use of gate.util.GateException in project gate-core by GateNLP.
the class CreoleRegisterImpl method registerDirectories.
/**
* Register a single CREOLE directory. The <CODE>creole.xml</CODE> file at the
* URL is parsed, and <CODE>CreoleData</CODE> objects added to the register.
* If the directory URL has not yet been added it is now added. If any other
* plugins that need to be loaded for this plugin to load (specified by
* <CODE>REQUIRES</Code> elements in <code>creole.xml</code>) will only be
* loaded if the <code>loadDependencies</code> param is true. It is useful to
* be able to ignore dependencies when loading an xgapp where we know they
* have already been resolved.
*/
@Override
public void registerDirectories(URL directoryUrl, boolean loadDependencies) throws GateException {
// registerPlugin
try {
Plugin plugin = new Plugin.Directory(directoryUrl);
registerPlugin(plugin);
} catch (Exception e) {
throw new GateException("Failed to load plugin", e);
}
}
use of gate.util.GateException in project gate-core by GateNLP.
the class CreoleRegisterImpl method registerBuiltins.
/**
* Register resources that are built in to the GATE distribution. These
* resources are described by the <TT>creole.xml</TT> file in
* <TT>resources/creole</TT>.
*/
@Override
public void registerBuiltins() throws GateException {
try {
URL creoleDirURL = Gate.getBuiltinCreoleDir();
// URL creoleFileURL = new URL(creoleDirURL, "creole.xml");
// URL creoleFileURL = Files.getGateResource("/creole/creole.xml");
// parseDirectory(creoleFileURL.openStream(), creoleDirURL,
// creoleFileURL,true);*/
Plugin plugin = new Plugin.Directory(creoleDirURL);
parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(), new URL(plugin.getBaseURL(), "creole.xml"));
log.info("CREOLE plugin loaded: " + plugin.getName());
} catch (Exception e) {
if (DEBUG)
log.debug(e);
throw (new GateException(e));
}
}
use of gate.util.GateException in project gate-core by GateNLP.
the class CreoleRegisterImpl method getAllInstances.
public List<Resource> getAllInstances(String type, boolean includeHidden) throws GateException {
List<Resource> res = new ArrayList<Resource>();
Class<? extends Resource> targetClass;
try {
targetClass = Gate.getClassLoader().loadClass(type).asSubclass(Resource.class);
} catch (ClassNotFoundException cnfe) {
throw new GateException("Invalid type " + type);
}
for (Map.Entry<String, ResourceData> entry : entrySet()) {
String aType = entry.getKey();
Class<?> aClass;
try {
aClass = entry.getValue().getResourceClass();
if (targetClass.isAssignableFrom(aClass)) {
// filter out hidden instances
Iterator<? extends Resource> newInstancesIter = get(aType).getInstantiations().iterator();
while (newInstancesIter.hasNext()) {
Resource instance = newInstancesIter.next();
if (includeHidden || !Gate.getHiddenAttribute(instance.getFeatures())) {
res.add(instance);
}
}
}
} catch (ClassNotFoundException cnfe) {
throw new GateRuntimeException("A type registered in the creole register does not exist in the VM!");
}
}
return res;
}
use of gate.util.GateException in project gate-core by GateNLP.
the class CreoleAnnotationHandler method loadRequiredPlugins.
/**
* Extracts all the the REQUIRES elements from the given JDOM document,
* expands the URLs and then attempts to load the specified plugin
*
* @param jdomDoc JDOM document representing a parsed creole.xml file.
*/
@Deprecated
public void loadRequiredPlugins(Document jdomDoc) throws IOException {
try {
XPath jarXPath = XPath.newInstance("//*[translate(local-name(), 'requires', 'REQUIRES') = 'REQUIRES']");
@SuppressWarnings("unchecked") List<Element> requires = jarXPath.selectNodes(jdomDoc);
String relativePathMarker = "$relpath$";
String gatehomePathMarker = "$gatehome$";
String gatepluginsPathMarker = "$gateplugins$";
for (Element required : requires) {
URL url = null;
String urlString = required.getTextTrim();
if (urlString.startsWith(relativePathMarker)) {
url = new URL(plugin.getBaseURL(), urlString.substring(relativePathMarker.length()));
} else if (urlString.startsWith(gatehomePathMarker)) {
URL gatehome = Gate.getGateHome().toURI().toURL();
url = new URL(gatehome, urlString.substring(gatehomePathMarker.length()));
} else if (urlString.startsWith(gatepluginsPathMarker)) {
URL gateplugins = Gate.getPluginsHome().toURI().toURL();
url = new URL(gateplugins, urlString.substring(gatepluginsPathMarker.length()));
} else {
url = new URL(plugin.getBaseURL(), urlString);
}
Gate.getCreoleRegister().registerPlugin(new Plugin.Directory(url));
}
} catch (GateException | JDOMException e) {
throw new IOException("Unable to load required plugin", e);
}
}
use of gate.util.GateException in project gate-core by GateNLP.
the class CreoleAnnotationHandler method processParameters.
/**
* Process any {@link CreoleParameter} and {@link HiddenCreoleParameter}
* annotations on set methods of the given class and set up the corresponding
* PARAMETER elements.
*
* @param resourceClass
* the resource class to process
* @param resourceElement
* the RESOURCE element to which the PARAMETERs are to be added
* @param parameterMap
* a map from parameter names to the PARAMETER elements that define
* them. This is used as we combine information from the original
* creole.xml, the parameter annotation on the target method and the
* annotations on the same method of its superclasses and interfaces.
* Parameter names that have been hidden by a
* {@link HiddenCreoleParameter} annotation are explicitly mapped to
* <code>null</code> in this map.
* @param disjunctionMap
* a map from disjunction IDs to the OR elements that define them.
* Disjunctive parameters are handled by specifying a disjunction ID
* on the {@link CreoleParameter} annotations - parameters with the
* same disjunction ID are grouped under the same OR element.
*/
private void processParameters(Class<?> resourceClass, Element resourceElement, Map<String, Element> parameterMap, Map<String, Element> disjunctionMap) throws GateException {
BeanInfo bi;
try {
bi = Introspector.getBeanInfo(resourceClass);
} catch (IntrospectionException e) {
throw new GateException("Failed to introspect " + resourceClass, e);
}
for (Method method : resourceClass.getDeclaredMethods()) {
processElement(method, bi, resourceElement, parameterMap, disjunctionMap);
}
for (Field field : resourceClass.getDeclaredFields()) {
processElement(field, bi, resourceElement, parameterMap, disjunctionMap);
}
// go up the tree
Class<?> superclass = resourceClass.getSuperclass();
if (superclass != null) {
processParameters(superclass, resourceElement, parameterMap, disjunctionMap);
}
for (Class<?> intf : resourceClass.getInterfaces()) {
processParameters(intf, resourceElement, parameterMap, disjunctionMap);
}
}
Aggregations