gate.util.GateException Java Examples

The following examples show how to use gate.util.GateException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestConfig.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Helper method that processes a config file.
 */
private void readConfig(URL configUrl) throws Exception {
  ConfigDataProcessor configProcessor = new ConfigDataProcessor();

  // open a stream to the builtin config data file (tests version)
  InputStream configStream = null;
  try {
    configStream = configUrl.openStream();
  } catch(IOException e) {
    throw new GateException(
      "Couldn't open config data test file: " + configUrl + " " + e
    );
  }
  if (DEBUG)
    Out.prln(
      "Parsing config file ... " + configStream + "from URL" + configUrl
    );
  configProcessor.parseConfigFile(configStream, configUrl);
}
 
Example #2
Source File: CreoleAnnotationHandler.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Process the given RESOURCE element, adding extra elements to it based on
 * the annotations on the resource class.
 * 
 * @param element
 *          the RESOURCE element to process.
 */
private void processAnnotationsForResource(Element element)
    throws GateException {
  String className = element.getChildTextTrim("CLASS");
  if(className == null) { throw new GateException(
      "\"CLASS\" element not found for resource in " + plugin); }
  Class<?> resourceClass = null;
  try {
    resourceClass = Gate.getClassLoader().loadClass(className);
  } catch(ClassNotFoundException e) {
    log.debug("Couldn't load class " + className + " for resource in "
        + plugin, e);
    throw new GateException("Couldn't load class " + className
        + " for resource in " + plugin);
  }

  processCreoleResourceAnnotations(element, resourceClass);
}
 
Example #3
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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() + " "
        + plugin.getVersion());

  } catch(Exception e) {
    if(DEBUG) log.debug("unable to register built in creole",e);
    throw (new GateException(e));
  }
}
 
Example #4
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void processFullCreoleXmlTree(Plugin plugin,
    Document jdomDoc, CreoleAnnotationHandler annotationHandler)
    throws GateException, IOException, JDOMException {
  // now we can process any annotations on the new classes
  // and augment the XML definition
  annotationHandler.processAnnotations(jdomDoc);

  // debugging
  if(DEBUG) {
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.output(jdomDoc, System.out);
  }

  // finally, parse the augmented definition with the normal parser
  DefaultHandler handler =
      new CreoleXmlHandler(this, plugin);
  SAXOutputter outputter =
      new SAXOutputter(handler, handler, handler, handler);
  outputter.output(jdomDoc);
  if(DEBUG) {
    Out.prln("done parsing " + plugin);
  }
}
 
Example #5
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Default constructor. Sets up directory files parser. <B>NOTE:</B> only
 * Factory should call this method.
 */
public CreoleRegisterImpl() throws GateException {

  // initialise the various maps

  lrTypes = new HashSet<String>();
  prTypes = new HashSet<String>();
  vrTypes = new LinkedList<String>();
  toolTypes = new HashSet<String>();
  applicationTypes = new HashSet<String>();

  plugins = new LinkedHashSet<Plugin>();

  // construct a SAX parser for parsing the CREOLE directory files
  jdomBuilder = new SAXBuilder(false);
  jdomBuilder.setXMLFilter(new CreoleXmlUpperCaseFilter());

  // read plugin name mappings file
  readPluginNamesMappings();

}
 
Example #6
Source File: BootStrap.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
  System.out.println(System.getProperty("path.separator"));
  System.out.println("intre");
  System.out.println(System.getProperty("java.class.path"));
  BootStrap bootStrap = new BootStrap();
  Set<String> interfaces = new HashSet<String>();
  interfaces.add("gate.Document");
  interfaces.add("gate.ProcessingResource");
  try{

  bootStrap.createResource("morph","creole.sheffield.ac.lisa","LanguageResource",
    "Documente", interfaces, "z:/test");
  } catch (GateException ge) {
    ge.printStackTrace(Err.getPrintWriter());
  } catch (ClassNotFoundException cnfe) {
    cnfe.printStackTrace(Err.getPrintWriter());
  } catch (IOException ioe) {
    ioe.printStackTrace(Err.getPrintWriter());
  } catch (InterruptedException ie){
    ie.printStackTrace(Err.getPrintWriter());
  }
}
 
Example #7
Source File: BootStrap.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** verify if the class name contains only letters and digits
 *  the path of the new project is a directory
 */
public void verifyInput(String className, String pathNewProject)
                        throws GateException {
  // verify the input
  // class name contains only letters and digits
  char[] classNameChars = className.toCharArray();
  for (int i=0;i<classNameChars.length;i++){
    if (!Character.isLetterOrDigit(classNameChars[i]))
      throw new GateException("Only letters and digits in	 the class name");
  }

  // verify if it exits a directory of given path
  File dir = new File(pathNewProject);
  if (!dir.isDirectory())
    throw new GateException("The folder is not a directory");
}
 
Example #8
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 {
  // TODO we need to add support for the loadDependencies option to
  // registerPlugin
  try {
    Plugin plugin = new Plugin.Directory(directoryUrl);

    registerPlugin(plugin);
  } catch(Exception e) {
    throw new GateException("Failed to load plugin", e);
  }
}
 
Example #9
Source File: CreoleAnnotationHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Process annotations for the given element. If the element is a RESOURCE it
 * is processed, otherwise the method calls itself recursively for all the
 * children of the given element.
 * 
 * @param element
 *          the element to process.
 */
@SuppressWarnings("unchecked")
private void processAnnotations(Element element) throws GateException {
  if("RESOURCE".equals(element.getName())) {
    processAnnotationsForResource(element);
  } else {
    for(Element child : (List<Element>)element.getChildren()) {
      processAnnotations(child);
    }
  }
}
 
Example #10
Source File: GateService.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() throws GateException, IOException {

    File gateHome = new File(gateHomePath);
    //in case called by other contexts
    if(!Gate.isInitialised()) {
        Gate.setGateHome(gateHome);
        Gate.runInSandbox(true);
        Gate.init();
    }

    loadresources();
}
 
Example #11
Source File: AbstractResource.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Removes listeners from a resource.
 * @param listeners The listeners to be removed from the resource. A
 * {@link java.util.Map} that maps from fully qualified class name
 * (as a string) to listener (of the type declared by the key).
 * @param resource the resource that listeners will be removed from.
 */
public static void removeResourceListeners(Resource resource, Map<String, ? extends Object> listeners)
                   throws IntrospectionException, InvocationTargetException,
                          IllegalAccessException, GateException{

  // get the beaninfo for the resource bean, excluding data about Object
  BeanInfo resBeanInfo = getBeanInfo(resource.getClass());

  // get all the events the bean can fire
  EventSetDescriptor[] events = resBeanInfo.getEventSetDescriptors();

  //remove the listeners
  if(events != null) {
    EventSetDescriptor event;
    for(int i = 0; i < events.length; i++) {
      event = events[i];

      // did we get such a listener?
      Object listener =
        listeners.get(event.getListenerType().getName());
      if(listener != null) {
        Method removeListener = event.getRemoveListenerMethod();

        // call the set method with the parameter value
        Object[] args = new Object[1];
        args[0] = listener;
        removeListener.invoke(resource, args);
      }
    } // for each event
  }   // if events != null
}
 
Example #12
Source File: AbstractResource.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds listeners to a resource.
 * @param listeners The listeners to be registered with the resource. A
 * {@link java.util.Map} that maps from fully qualified class name (as a
 * string) to listener (of the type declared by the key).
 * @param resource the resource that listeners will be registered to.
 */
public static void setResourceListeners(Resource resource, Map<String, ? extends Object> listeners)
throws
  IntrospectionException, InvocationTargetException,
  IllegalAccessException, GateException
{
  // get the beaninfo for the resource bean, excluding data about Object
  BeanInfo resBeanInfo = getBeanInfo(resource.getClass());

  // get all the events the bean can fire
  EventSetDescriptor[] events = resBeanInfo.getEventSetDescriptors();

  // add the listeners
  if (events != null) {
    EventSetDescriptor event;
    for(int i = 0; i < events.length; i++) {
      event = events[i];

      // did we get such a listener?
      Object listener =
        listeners.get(event.getListenerType().getName());
      if(listener != null) {
        Method addListener = event.getAddListenerMethod();

        // call the set method with the parameter value
        Object[] args = new Object[1];
        args[0] = listener;
        addListener.invoke(resource, args);
      }
    } // for each event
  }   // if events != null
}
 
Example #13
Source File: CreoleAnnotationHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #14
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 {
  // create a handler for the directory file and parse it;
  // this will create ResourceData entries in the register
  try {

    CreoleAnnotationHandler annotationHandler =
        new CreoleAnnotationHandler(plugin);

    GateClassLoader gcl = Gate.getClassLoader()
        .getDisposableClassLoader(plugin.getBaseURI().toString());

    // 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(URISyntaxException | IOException e) {
    throw (new GateException(e));
  } catch(JDOMException je) {
    if(DEBUG) je.printStackTrace(Err.getPrintWriter());
    throw (new GateException(je));
  }

}
 
Example #15
Source File: GateService.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
public String deIdentifyString(String text, String primaryKeyFieldValue) throws DeIdentificationFailedException {
    Document doc;
    try {
        doc = Factory.newDocument(text);

        doc.getFeatures().put("primaryKeyFieldValue", primaryKeyFieldValue);
        CorpusController controller;

        controller = deIdQueue.take();

        controller.getCorpus().add(doc);
        controller.execute();
        controller.getCorpus().clear();

        deIdQueue.put(controller);

        text = doc.getContent().toString();
        Factory.deleteResource(doc);
    }catch (Exception ex) {
        LOG.error("GATE app execution error", ex);
        try {
            loadresources();
        } catch (GateException|IOException e) {
            LOG.error("could not reload resources", ex);
        }
        throw new DeIdentificationFailedException("GATE app execution error");
    }
    return text;
}
 
Example #16
Source File: Main.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Main routine for GATE.
  * Command-line arguments:
  * <UL>
  * <LI>
  * <B>-h</B> display a short help message
  * <LI>
  * <B>-d URL</B> define URL to be a location for CREOLE resoures
  * <LI>
  * <B>-i file</B> additional initialisation file (probably called
  *   <TT>gate.xml</TT>). Used for site-wide initialisation by the
  *   start-up scripts
  * </UL>
  */
public static void main(String[] args) throws GateException {
  
  // check we have a useable JDK
  if(
    System.getProperty("java.version").compareTo(Gate.getMinJdkVersion())
    < 0
  ) {
    throw new GateException(
      "GATE requires JDK " + Gate.getMinJdkVersion() + " or newer"
    );
  }
  
  ThreadWarningSystem tws = new ThreadWarningSystem();
  tws.addListener(new ThreadWarningSystem.Listener() {
    
    final PrintStream out = System.out;
    
    @Override
    public void deadlockDetected(ThreadInfo inf) {
      out.println("Deadlocked Thread:");
      out.println("------------------");
      out.println(inf);
      for (StackTraceElement ste : inf.getStackTrace()) {
        out.println("\t" + ste);
      }
    }
    @Override
    public void thresholdExceeded(ThreadInfo[] threads) { }
  });

  // process command-line options
  processArgs(args);
  
  runGui();
}
 
Example #17
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void registerComponent(Class<? extends Resource> resourceClass)
    throws GateException {
  try {
    registerPlugin(new Plugin.Component(resourceClass));
  } catch(MalformedURLException mue) {
    throw new GateException("Unable to register component", mue);
  }
}
 
Example #18
Source File: CreoleRegisterImpl.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void registerPlugin(Plugin plugin, boolean loadDependencies)
    throws GateException {

  if(!plugins.contains(plugin)) {

    Gate.addKnownPlugin(plugin);

    try {

      if(loadDependencies) {
        for(Plugin required : plugin.getRequiredPlugins()) {
          registerPlugin(required, true);
        }
      }

      Document creoleXML = plugin.getCreoleXML();
      
      if (plugin.isValid()) {
        parseDirectory(plugin, creoleXML, plugin.getBaseURL(),
            new URL(plugin.getBaseURL(), "creole.xml"));
        log.info("CREOLE plugin loaded: " + plugin.getName() + " "
            + plugin.getVersion());
      }
      else {
        throw new GateException("plugin is invalid");
      }
    } catch(Throwable e) {
      // it failed:
      throw (new GateException("couldn't open creole.xml for plugin: "+plugin, e));
    }

    plugins.add(plugin);

    firePluginLoaded(plugin);
  }
}
 
Example #19
Source File: AnnotatedCorpusReader.java    From OpenLex with GNU General Public License v3.0 5 votes vote down vote up
private void setupAndStartGate() {
	if (Gate.getGateHome() == null) {
		Gate.setGateHome(new File(paths.getPathToGATE()));
	}
	if (Gate.getPluginsHome() == null) {
		Gate.setPluginsHome(new File(paths.getPathToGATEPlugins()));
	}

	try {
		Gate.init();
	} catch (GateException ge) {
		handleAnyException(ge);
	}
}
 
Example #20
Source File: AnnotationDiffGUI.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void populateGUI(){
  try{
    documents = Gate.getCreoleRegister().getAllInstances("gate.Document");
  }catch(GateException ge){
    throw new GateRuntimeException(ge);
  }
  List<String> documentNames = new ArrayList<String>(documents.size());
  for(Resource document : documents) {
    documentNames.add(document.getName());
  }
  Object keyDocSelectedItem = keyDocCombo.getSelectedItem();
  Object resDocSelectedItem = resDocCombo.getSelectedItem();
  keyDocCombo.setModel(new DefaultComboBoxModel<String>(documentNames.toArray(new String[documentNames.size()])));
  resDocCombo.setModel(new DefaultComboBoxModel<String>(documentNames.toArray(new String[documentNames.size()])));
  if(!documents.isEmpty()){
    keyDocCombo.setSelectedItem(keyDocSelectedItem);
    if (keyDocCombo.getSelectedIndex() == -1) {
      keyDocCombo.setSelectedIndex(0);
    }
    resDocCombo.setSelectedItem(resDocSelectedItem);
    if (resDocCombo.getSelectedIndex() == -1) {
      resDocCombo.setSelectedIndex(0);
    }
    statusLabel.setText(documents.size() + " documents loaded");
    if (annTypeCombo.getSelectedItem() == null) {
      statusLabel.setText(statusLabel.getText() +
        ". Choose two annotation sets to compare.");
    }
    statusLabel.setForeground(Color.BLACK);
  } else {
    statusLabel.setText("You must load at least one document.");
    statusLabel.setForeground(Color.RED);
  }
}
 
Example #21
Source File: SerialControllerEditor.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object getElementAt(int index){
  if(index == 0) return "<none>";
  else{
    //get all corpora regardless of their actual type
    List<Resource> loadedCorpora = null;
    try{
      loadedCorpora = Gate.getCreoleRegister().
                             getAllInstances("gate.Corpus");
    }catch(GateException ge){
      ge.printStackTrace(Err.getPrintWriter());
    }
    return loadedCorpora == null? "" : loadedCorpora.get(index - 1);
  }
}
 
Example #22
Source File: SerialControllerEditor.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int getSize(){
  //get all corpora regardless of their actual type
  List<Resource> loadedCorpora = null;
  try{
    loadedCorpora = Gate.getCreoleRegister().
                           getAllInstances("gate.Corpus");
  }catch(GateException ge){
    ge.printStackTrace(Err.getPrintWriter());
  }

  return loadedCorpora == null ? 1 : loadedCorpora.size() + 1;
}
 
Example #23
Source File: CorpusEditor.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void initLocalData(){
  docTableModel = new DocumentTableModel();
  try {
    documentsLoadedCount = Gate.getCreoleRegister()
      .getAllInstances("gate.Document").size();
  } catch (GateException exception) {
    exception.printStackTrace();
  }
}
 
Example #24
Source File: Main.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Register any CREOLE URLs that we got on the command line */
protected static void registerCreoleUrls() {
  CreoleRegister reg = Gate.getCreoleRegister();
  Iterator<URL> iter = pendingCreoleUrls.iterator();
  while(iter.hasNext()) {
    URL u = iter.next();
    try {
      reg.registerPlugin(new Plugin.Directory(u));
    } catch(GateException e) {
      Err.prln("Couldn't register CREOLE directory: " + u);
      Err.prln(e);
      System.exit(STATUS_ERROR);
    }
  }
}
 
Example #25
Source File: TestPersist.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** Construction */
public TestPersist(String name) throws GateException {
  super(name);
}
 
Example #26
Source File: TestTikaFormats.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws GateException {
  Gate.init();
}
 
Example #27
Source File: TestCreoleAnnotationHandler.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** Construction */
public TestCreoleAnnotationHandler(String name) throws GateException {
  super(name);
}
 
Example #28
Source File: AnnotationEditor.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Does nothing, as this editor does not support cancelling and rollbacks.
 */
@Override
public void cancelAction() throws GateException {
}
 
Example #29
Source File: TestCreole.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** Construction */
public TestCreole(String name) throws GateException { super(name); }
 
Example #30
Source File: OntologyUtilities.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Checks the availability of an existing instance of the Ontology
 * with the given URL in the GATE's CreoleRegister. If found, returns
 * the first available one (doesn't guranttee in which order). If not
 * found, attempts to create one using OWLIM implementation with
 * RDF/XML as ontology type and if successful returns the newly
 * created instance of the ontology.
 * @throws ResourceInstantiationException
 * @deprecated - this method should be avoided
 */
@Deprecated
public static Ontology getOntology(URL url)
        throws ResourceInstantiationException {
  java.util.List<Resource> loadedOntologies = null;
  Ontology ontology = null;
  try {
    loadedOntologies = Gate.getCreoleRegister().getAllInstances(
            Ontology.class.getName());
  }
  catch(GateException ge) {
    throw new ResourceInstantiationException("Cannot list loaded ontologies",
            ge);
  }

  Iterator<Resource> ontIter = loadedOntologies.iterator();
  while(ontology == null && ontIter.hasNext()) {
    Ontology anOntology = (Ontology)ontIter.next();
    if(anOntology.getURL().equals(url)) {
      ontology = anOntology;
      break;
    }
  }

  try {
    // if not found, load it
    if(ontology == null) {
      // hardcoded to use OWL as the ontology type
      FeatureMap params = Factory.newFeatureMap();
      params.put("persistLocation", File.createTempFile("abc", "abc")
              .getParentFile().toURI().toURL());
      params.put("rdfXmlURL", url);
      ontology = (Ontology)Factory.createResource(
              "gate.creole.ontology.owlim.OWLIMOntologyLR", params);
    }
  }
  catch(Exception e) {
    throw new ResourceInstantiationException(
            "Cannot create a new instance of ontology", e);
  }
  return ontology;
}