use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class GappModel method finish.
/**
* Finish up processing of the gapp file ready for writing.
*/
@SuppressWarnings("unchecked")
public void finish() {
// remove duplicate plugin entries
try {
// this XPath selects all URLHolders out of the URL list that have
// the same URL string as one of their preceding siblings, i.e. if
// there are N URLs in the list with the same value then this
// XPath
// will select all but the first one of them.
XPath duplicatePluginXPath = XPath.newInstance("/gate.util.persistence.GateApplication/urlList" + "/localList/gate.util.persistence.PersistenceManager-URLHolder" + "[urlString = preceding-sibling::gate.util.persistence.PersistenceManager-URLHolder/urlString]");
List<Element> duplicatePlugins = duplicatePluginXPath.selectNodes(gappDocument);
for (Element e : duplicatePlugins) {
e.getParentElement().removeContent(e);
}
} catch (JDOMException e) {
throw new GateRuntimeException("Error applying XPath expression to remove duplicate plugins", e);
}
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class SerialCorpusImpl method resourceDeleted.
/**
* Called by a datastore when a resource has been deleted
*/
@Override
public void resourceDeleted(DatastoreEvent evt) {
DataStore ds = (DataStore) evt.getSource();
// 1. check whether this datastore fired the event. If not, return.
if (!ds.equals(this.dataStore))
return;
Object docID = evt.getResourceID();
if (docID == null)
return;
if (DEBUG)
Out.prln("Resource deleted called for: " + docID);
// unloaded immediately
if (docID.equals(this.getLRPersistenceId())) {
Factory.deleteResource(this);
return;
}
// if
boolean isDirty = false;
// first
for (int i = 0; i < docDataList.size(); i++) {
DocumentData docData = docDataList.get(i);
// don't break the loop, because it might appear more than once
if (docID.equals(docData.getPersistentID())) {
if (evt.getResource() == null) {
// instead of calling remove() which tries to load the
// document
// remove it from the documents and docDataList
documentRemoved(docDataList.get(i).persistentID.toString());
docDataList.remove(i);
documents.remove(i);
isDirty = true;
i--;
continue;
}
remove(i);
isDirty = true;
}
// if
}
if (isDirty)
try {
this.dataStore.sync(this);
} catch (PersistenceException ex) {
throw new GateRuntimeException("SerialCorpusImpl: " + ex.getMessage());
} catch (SecurityException sex) {
throw new GateRuntimeException("SerialCorpusImpl: " + sex.getMessage());
}
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class SerialCorpusImpl method get.
@Override
public Document get(int index) {
if (index >= docDataList.size())
return null;
Document res = documents.get(index);
if (DEBUG)
Out.prln("SerialCorpusImpl: get(): index " + index + "result: " + res);
// if the document is null, then I must get it from the DS
if (res == null) {
FeatureMap parameters = Factory.newFeatureMap();
parameters.put(DataStore.DATASTORE_FEATURE_NAME, this.dataStore);
try {
parameters.put(DataStore.LR_ID_FEATURE_NAME, docDataList.get(index).getPersistentID());
Document lr = (Document) Factory.createResource(docDataList.get(index).getClassType(), parameters);
if (DEBUG)
Out.prln("Loaded document :" + lr.getName());
// change the result to the newly loaded doc
res = lr;
// finally replace the doc with the instantiated version
documents.set(index, lr);
} catch (ResourceInstantiationException ex) {
Err.prln("Error reading document inside a serialised corpus.");
throw new GateRuntimeException(ex);
}
}
return res;
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class CreoleRegisterImpl method getAnnotationVRs.
// getVRsForResource()
/**
* Returns a list of strings representing class names for annotation VRs that
* are able to display/edit all types of annotations. The default VR will be
* the first in the returned list.
*
* @return a list with all VRs that can display all annotation types
*/
@Override
public List<String> getAnnotationVRs() {
LinkedList<String> responseList = new LinkedList<String>();
String defaultVR = null;
Iterator<String> vrIterator = vrTypes.iterator();
while (vrIterator.hasNext()) {
String vrClassName = vrIterator.next();
ResourceData vrResourceData = this.get(vrClassName);
if (vrResourceData == null)
throw new GateRuntimeException("Couldn't get resource data for VR called " + vrClassName);
Class<?> vrResourceClass = null;
try {
vrResourceClass = vrResourceData.getResourceClass();
} catch (ClassNotFoundException ex) {
throw new GateRuntimeException("Couldn't create a class object for VR called " + vrClassName);
}
// Test if VR can display all types of annotations
if (vrResourceData.getGuiType() == ResourceData.NULL_GUI && vrResourceData.getAnnotationTypeDisplayed() == null && vrResourceData.getResourceDisplayed() == null && gate.creole.AnnotationVisualResource.class.isAssignableFrom(vrResourceClass)) {
responseList.add(vrClassName);
if (vrResourceData.isMainView())
defaultVR = vrClassName;
}
// End if
}
// End while
if (defaultVR != null) {
responseList.remove(defaultVR);
responseList.addFirst(defaultVR);
}
// End if
return Collections.unmodifiableList(responseList);
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class CreoleRegisterImpl method put.
// registerBuiltins()
/**
* Overide HashMap's put method to maintain a list of all the types of LR in
* the register, and a list of tool types. The key is the resource type, the
* value its data.
*/
@Override
public ResourceData put(String key, ResourceData rd) {
if (super.containsKey(key)) {
ResourceData rData = super.get(key);
rData.increaseReferenceCount();
if (DEBUG)
Out.println(key + " is already defined, new reference will be ignored.");
// TODO not sure what we should actually return here
return rData;
}
// get the resource implementation class
Class<? extends Resource> resClass = null;
try {
resClass = rd.getResourceClass();
} catch (ClassNotFoundException e) {
throw new GateRuntimeException("Couldn't get resource class from the resource data:" + e);
}
// add class names to the type lists
if (LanguageResource.class.isAssignableFrom(resClass)) {
if (DEBUG)
Out.prln("LR: " + resClass);
// for
if (lrTypes == null)
lrTypes = new HashSet<String>();
// deserialisation
lrTypes.add(rd.getClassName());
}
if (ProcessingResource.class.isAssignableFrom(resClass)) {
if (DEBUG) {
Out.prln("PR: " + resClass);
// Out.prln("prTypes: " + prTypes);
// Out.prln("rd.getClassName(): " + rd.getClassName());
}
// for
if (prTypes == null)
prTypes = new HashSet<String>();
// deserialisation
prTypes.add(rd.getClassName());
}
if (VisualResource.class.isAssignableFrom(resClass)) {
if (DEBUG)
Out.prln("VR: " + resClass);
// for
if (vrTypes == null)
vrTypes = new LinkedList<String>();
// we have to simulate Set behaviour as this is a list
if (!vrTypes.contains(rd.getClassName()))
vrTypes.add(rd.getClassName());
}
if (Controller.class.isAssignableFrom(resClass)) {
if (DEBUG)
Out.prln("Controller: " + resClass);
// for
if (controllerTypes == null)
controllerTypes = new HashSet<String>();
// deserialisation
controllerTypes.add(rd.getClassName());
}
if (PackagedController.class.isAssignableFrom(resClass)) {
if (DEBUG)
Out.prln("Application: " + resClass);
if (applicationTypes == null)
applicationTypes = new HashSet<String>();
applicationTypes.add(rd.getClassName());
}
// maintain tool types list
if (rd.isTool()) {
// for
if (toolTypes == null)
toolTypes = new HashSet<String>();
// deserialisation
toolTypes.add(rd.getClassName());
}
return super.put(key, rd);
}
Aggregations