@Override public boolean add(Document o) { if (o == null) return false; Document doc = o; // make it accept only docs from its own datastore if (doc.getDataStore() != null && !this.dataStore.equals(doc.getDataStore())) { Err.prln("Error: Persistent corpus can only accept documents " + "from its own datastore!"); return false; } // if // add the document with its index in the docDataList // in this case, since it's going to be added to the end // the index will be the size of the docDataList before // the addition DocumentData docData = new DocumentData(doc.getName(), doc.getLRPersistenceId(), doc.getClass().getName()); boolean result = docDataList.add(docData); documents.add(doc); documentAdded(doc); fireDocumentAdded( new CorpusEvent( SerialCorpusImpl.this, doc, docDataList.size() - 1, doc.getLRPersistenceId(), CorpusEvent.DOCUMENT_ADDED)); return result; }
@Override public void resourceUnloaded(CreoleEvent e) { Resource res = e.getResource(); if (res instanceof Document) { Document doc = (Document) res; if (DEBUG) Out.prln("resource Unloaded called "); // remove from the corpus too, if a transient one if (doc.getDataStore() != this.getDataStore()) { this.remove(doc); } else { // unload all occurences int index = indexOf(res); if (index < 0) return; documents.set(index, null); if (DEBUG) Out.prln("corpus: document " + index + " unloaded and set to null"); } // if } }