use of gate.util.GateClassLoader in project gate-core by GateNLP.
the class Gate method init.
/**
* Initialisation - must be called by all clients before using any other parts
* of the library. Also initialises the CREOLE register and reads config data (<TT>gate.xml</TT>
* files).
*
* @see #initCreoleRegister
*/
public static void init() throws GateException {
// init local paths
if (!sandboxed)
initLocalPaths();
// check if benchmarking should be enabled or disabled
if (System.getProperty(ENABLE_BENCHMARKING_FEATURE_NAME) != null && System.getProperty(ENABLE_BENCHMARKING_FEATURE_NAME).equalsIgnoreCase("true")) {
Benchmark.setBenchmarkingEnabled(true);
}
// builtin creole dir
if (builtinCreoleDir == null) {
String builtinCreoleDirPropertyValue = System.getProperty(BUILTIN_CREOLE_DIR_PROPERTY_NAME);
if (builtinCreoleDirPropertyValue == null) {
// default to /gate/resources/creole in gate.jar
builtinCreoleDir = Files.getGateResource("/creole/");
} else {
String builtinCreoleDirPath = builtinCreoleDirPropertyValue;
// a creole directory URL should always end with a forward slash
if (!builtinCreoleDirPath.endsWith("/")) {
builtinCreoleDirPath += "/";
}
try {
builtinCreoleDir = new URL(builtinCreoleDirPath);
} catch (MalformedURLException mue) {
// couldn't parse as a File either, so throw an exception
throw new GateRuntimeException(BUILTIN_CREOLE_DIR_PROPERTY_NAME + " value \"" + builtinCreoleDirPropertyValue + "\" could" + " not be parsed as either a URL or a file path.");
}
log.info("Using " + builtinCreoleDir + " as built-in CREOLE" + " directory URL");
}
}
// initialise the symbols generator
lastSym = 0;
// create class loader and creole register if they're null
if (classLoader == null)
classLoader = new GateClassLoader("Top-Level GATE ClassLoader", Gate.class.getClassLoader());
if (creoleRegister == null)
creoleRegister = new CreoleRegisterImpl();
if (knownPlugins == null)
knownPlugins = new HashSet<Plugin>();
if (autoloadPlugins == null)
autoloadPlugins = new ArrayList<Plugin>();
// if(pluginData == null) pluginData = new HashSet<Plugin>();
// init the creole register
initCreoleRegister();
// init the data store register
initDataStoreRegister();
// initialisation in order for the CREOLE-DIR elements to have and effect
if (!sandboxed)
initConfigData();
if (!sandboxed)
initCreoleRepositories();
// the creoleRegister acts as a proxy for datastore related events
dataStoreRegister.addCreoleListener(creoleRegister);
// some of the events are actually fired by the {@link gate.Factory}
Factory.addCreoleListener(creoleRegister);
// check we have a useable JDK
if (System.getProperty("java.version").compareTo(MIN_JDK_VERSION) < 0) {
throw new GateException("GATE requires JDK " + MIN_JDK_VERSION + " or newer");
}
initFinished = true;
}
use of gate.util.GateClassLoader in project gate-core by GateNLP.
the class MainFrame method pluginUnloaded.
@Override
public void pluginUnloaded(URL url) {
try {
String classloaderID = (new URL(url, "creole.xml")).toExternalForm();
Iterator<String> it = iconByName.keySet().iterator();
while (it.hasNext()) {
String name = it.next();
Icon icon = iconByName.get(name);
ClassLoader cl = icon.getClass().getClassLoader();
if (cl instanceof GateClassLoader) {
if (((GateClassLoader) cl).getID().equals(classloaderID)) {
it.remove();
}
}
}
} catch (MalformedURLException e) {
// this should be impossible!
e.printStackTrace();
}
}
use of gate.util.GateClassLoader 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);
}
use of gate.util.GateClassLoader in project gate-core by GateNLP.
the class CreoleRegisterImpl method parseDirectory.
/**
* Parse a directory file (represented as an open stream), adding resource
* data objects to the CREOLE register as they occur. If the resource is from
* a URL then that location is passed (otherwise null).
*/
protected void parseDirectory(Plugin plugin, Document jdomDoc, URL directoryUrl, URL creoleFileUrl) throws GateException {
// this will create ResourceData entries in the register
try {
CreoleAnnotationHandler annotationHandler = new CreoleAnnotationHandler(plugin);
GateClassLoader gcl = Gate.getClassLoader().getDisposableClassLoader(creoleFileUrl.toExternalForm());
// Add any JARs from the creole.xml to the GATE ClassLoader
annotationHandler.addJarsToClassLoader(gcl, jdomDoc);
// Make sure there is a RESOURCE element for every resource type the
// directory defines
annotationHandler.createResourceElementsForDirInfo(jdomDoc);
processFullCreoleXmlTree(plugin, jdomDoc, annotationHandler);
} catch (IOException e) {
throw (new GateException(e));
} catch (JDOMException je) {
if (DEBUG)
je.printStackTrace(Err.getPrintWriter());
throw (new GateException(je));
}
}
Aggregations