1 | package org.greenstone.gsdl3.gs3build.extractor;
|
---|
2 |
|
---|
3 | import java.util.Iterator;
|
---|
4 |
|
---|
5 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentID;
|
---|
6 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
|
---|
7 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentList;
|
---|
8 |
|
---|
9 | public class ExtractorManager
|
---|
10 | {
|
---|
11 | public static final String ACCUMULATE_MODE = "accumulate";
|
---|
12 |
|
---|
13 | DocumentList documents;
|
---|
14 | ExtractorInterface [] list;
|
---|
15 | int size;
|
---|
16 | int used;
|
---|
17 |
|
---|
18 | public ExtractorManager(DocumentList documentList)
|
---|
19 | { this.list = new ExtractorInterface[10];
|
---|
20 | this.size = 10;
|
---|
21 | this.used = 0;
|
---|
22 | this.documents = documentList;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void addExtractor(ExtractorInterface extractor)
|
---|
26 | { this.ensureSize(this.used + 1);
|
---|
27 | this.list[this.used] = extractor;
|
---|
28 | this.used ++;
|
---|
29 |
|
---|
30 | extractor.configure(this.documents);
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void extractDocument(DocumentID docId, DocumentInterface document)
|
---|
34 | { for (int i = 0; i < this.used; i ++)
|
---|
35 | { this.list[i].extractDocument(docId, document);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void extractDocuments()
|
---|
40 | { for (int i = 0; i < this.used; i ++)
|
---|
41 | { for (int p = 0; p < this.list[i].getNumberOfPasses(); p ++)
|
---|
42 | { this.list[i].startPass(p);
|
---|
43 |
|
---|
44 | Iterator iterator = documents.iterator();
|
---|
45 | while (iterator.hasNext()) {
|
---|
46 | DocumentInterface document = (DocumentInterface) iterator.next();
|
---|
47 | this.list[i].extractDocument(document.getID(), document);
|
---|
48 | }
|
---|
49 | this.list[i].endPass(p);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void ensureSize(int size)
|
---|
55 | { while (size >= this.size)
|
---|
56 | { ExtractorInterface newList [] = new ExtractorInterface[this.size*2];
|
---|
57 | this.size *= 2;
|
---|
58 | System.arraycopy(this.list, 0, newList, 0, this.size);
|
---|
59 | this.list = newList;
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|