1   package org.kuali.ole.batch.marc;
2   
3   import org.marc4j.ErrorHandler.Error;
4   import org.marc4j.RecordStack;
5   import org.marc4j.marc.Record;
6   import org.xml.sax.InputSource;
7   import org.marc4j.ErrorHandler;
8   
9   
10  import java.io.InputStream;
11  import java.util.List;
12  import java.util.concurrent.ExecutionException;
13  import java.util.concurrent.ExecutorService;
14  import java.util.concurrent.Executors;
15  import java.util.concurrent.Future;
16  
17  
18  
19  
20  
21  
22  
23  
24  public class OLEMarcXmlReader implements OLEMarcReader {
25  
26      private RecordStack queue;
27      private ErrorHandler errors;
28      private int errCount;
29  
30      public OLEMarcXmlReader(InputSource input) throws ExecutionException, InterruptedException {
31          this.queue = new RecordStack();
32          this.errors = new OLEMarcErrorHandler();
33          
34  
35  
36  
37  
38  
39  
40          OLEMarcXmlParserThread producer = new OLEMarcXmlParserThread(queue, input, errors);
41          producer.start();
42      }
43  
44      public OLEMarcXmlReader(InputStream input) throws ExecutionException, InterruptedException {
45          this(new InputSource(input));
46      }
47  
48      
49  
50  
51  
52  
53      public boolean hasNext() {
54          return queue.hasNext();
55      }
56  
57      
58  
59  
60  
61  
62      public Record next() {
63          return queue.pop();
64      }
65  
66      @Override
67      public boolean hasErrors() {
68          return errors.hasErrors();
69      }
70  
71      @SuppressWarnings("unchecked")
72      @Override
73      public List<Error> getErrors() {
74          return errors.getErrors();
75      }
76  
77      @Override
78      public Error getError() {
79          return (Error) errors.getErrors().get(0);
80      }
81  
82      public void clearErrors(){
83         errors.getErrors().clear();
84         OLEMarcErrorHandler errorHandler = (OLEMarcErrorHandler)errors;
85          errorHandler.getErrorMap().clear();
86      }
87  
88  }