use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class CreoleRegisterImpl method remove.
/**
* Overide HashMap's delete method to update the lists of types in the
* register.
*/
@Override
public ResourceData remove(Object key) {
ResourceData rd = get(key);
if (rd == null)
return null;
// TODO not sure what we should actually return here
if (rd.reduceReferenceCount() > 0) {
if (DEBUG)
Out.println(key + " is still defined by another plugin so won't be unloaded");
return rd;
}
if (DEBUG) {
Out.prln(key);
Out.prln(rd);
}
try {
if (LanguageResource.class.isAssignableFrom(rd.getResourceClass())) {
lrTypes.remove(rd.getClassName());
} else if (ProcessingResource.class.isAssignableFrom(rd.getResourceClass())) {
prTypes.remove(rd.getClassName());
} else if (VisualResource.class.isAssignableFrom(rd.getResourceClass())) {
vrTypes.remove(rd.getClassName());
} else if (Controller.class.isAssignableFrom(rd.getResourceClass())) {
controllerTypes.remove(rd.getClassName());
} else if (PackagedController.class.isAssignableFrom(rd.getResourceClass())) {
applicationTypes.remove(rd.getClassName());
}
} catch (ClassNotFoundException cnfe) {
throw new GateRuntimeException("Could not load class specified in CREOLE data.", cnfe);
}
// maintain tool types list
if (rd.isTool())
toolTypes.remove(rd.getClassName());
return super.remove(key);
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class CreoleRegisterImpl method getVRsForResource.
// getSmallVRsForResource
/**
* Returns a list of strings representing class names for guiType VRs valid
* for a given type of language/processing resource The default VR will be the
* first in the returned list.
*
* @param resourceClassName
* the name of the resource that has large viewers. If
* resourceClassName is <b>null</b> then an empty list will be
* returned.
* @param guiType
* can be ResourceData's LARGE_GUI or SMALL_GUI
* @return a list with Strings representing the large VRs for the
* resourceClassName
*/
private List<String> getVRsForResource(String resourceClassName, int guiType) {
// If resurceClassName is null return a simply list
if (resourceClassName == null)
return Collections.unmodifiableList(new ArrayList<String>());
// create a Class object for the resource
Class<?> resourceClass = null;
GateClassLoader classLoader = Gate.getClassLoader();
try {
resourceClass = classLoader.loadClass(resourceClassName);
} catch (ClassNotFoundException ex) {
throw new GateRuntimeException("Couldn't get resource class from the resource name:" + ex);
}
// End try
LinkedList<String> responseList = new LinkedList<String>();
String defaultVR = null;
// Take all VRs and for each large one, test if
// resourceClassName is asignable form VR's RESOURCE_DISPLAYED
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);
if (vrResourceData.getGuiType() == guiType) {
String resourceDisplayed = vrResourceData.getResourceDisplayed();
if (resourceDisplayed != null) {
Class<?> resourceDisplayedClass = null;
try {
resourceDisplayedClass = classLoader.loadClass(resourceDisplayed);
} catch (ClassNotFoundException ex) {
throw new GateRuntimeException("Couldn't get resource class from the resource name :" + resourceDisplayed + " " + ex);
}
// End try
if (resourceDisplayedClass.isAssignableFrom(resourceClass)) {
responseList.add(vrClassName);
if (vrResourceData.isMainView()) {
defaultVR = vrClassName;
}
// End if
}
// End if
}
// End if
}
// End if
}
// End while
if (defaultVR != null) {
responseList.remove(defaultVR);
responseList.addFirst(defaultVR);
}
// End if
return Collections.unmodifiableList(responseList);
}
Aggregations