| 66 | // always restore the doc, because it has its persistence ID. |
| 67 | |
| 68 | @CreoleResource(name = "GATE Serial Corpus", isPrivate = true, comment = "GATE persistent corpus (serialisation)", icon = "corpus", helpURL = "http://gate.ac.uk/userguide/sec:developer:datastores") |
| 69 | public class SerialCorpusImpl extends AbstractLanguageResource |
| 70 | implements Corpus, CreoleListener, DatastoreListener, IndexedCorpus, |
| 71 | CustomDuplication { |
| 72 | |
| 73 | /** Debug flag */ |
| 74 | private static final boolean DEBUG = false; |
| 75 | |
| 76 | static final long serialVersionUID = 3632609241787241616L; |
| 77 | |
| 78 | protected transient Vector<CorpusListener> corpusListeners; |
| 79 | |
| 80 | protected List<DocumentData> docDataList = null; |
| 81 | |
| 82 | // here I keep document index as key (same as the index in docDataList |
| 83 | // which defines the document order) and Documents as value |
| 84 | protected transient List<Document> documents = null; |
| 85 | |
| 86 | protected transient IndexManager indexManager = null; |
| 87 | |
| 88 | protected transient List<Document> addedDocs = null; |
| 89 | |
| 90 | protected transient List<String> removedDocIDs = null; |
| 91 | |
| 92 | protected transient List<Document> changedDocs = null; |
| 93 | |
| 94 | public SerialCorpusImpl() { |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Constructor to create a SerialCorpus from a transient one. This is |
| 99 | * called by adopt() to store the transient corpus and re-route the |
| 100 | * methods calls to it, until the corpus is sync-ed on disk. After |
| 101 | * that, the transientCorpus will always be null, so the new |
| 102 | * functionality will be used instead. |
| 103 | */ |
| 104 | protected SerialCorpusImpl(Corpus tCorpus) { |
| 105 | // copy the corpus name and features from the one in memory |
| 106 | this.setName(tCorpus.getName()); |
| 107 | this.setFeatures(tCorpus.getFeatures()); |
| 108 | |
| 109 | docDataList = new ArrayList<DocumentData>(); |
| 110 | // now cache the names of all docs for future use |
| 111 | List<String> docNames = tCorpus.getDocumentNames(); |
| 112 | for(int i = 0; i < docNames.size(); i++) { |
| 113 | Document doc = tCorpus.get(i); |
| 114 | docDataList.add(new DocumentData(docNames.get(i), null, doc |
| 115 | .getClass().getName())); |
| 116 | } |
| 117 | |
| 118 | // copy all the documents from the transient corpus |
| 119 | documents = new ArrayList<Document>(); |
| 120 | documents.addAll(tCorpus); |
| 121 | |
| 122 | // make sure we fire events when docs are added/removed/etc |
| 123 | Gate.getCreoleRegister().addCreoleListener(this); |
| 124 | } |
| 125 |
nothing calls this directly
no outgoing calls
no test coverage detected