Search in sources :

Example 41 with GateRuntimeException

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);
}
Also used : GateRuntimeException(gate.util.GateRuntimeException) ProcessingResource(gate.ProcessingResource) Controller(gate.Controller)

Example 42 with GateRuntimeException

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);
}
Also used : GateRuntimeException(gate.util.GateRuntimeException) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GateClassLoader(gate.util.GateClassLoader) LinkedList(java.util.LinkedList)

Aggregations

GateRuntimeException (gate.util.GateRuntimeException)42 ArrayList (java.util.ArrayList)12 URL (java.net.URL)6 FeatureMap (gate.FeatureMap)5 PersistenceException (gate.persist.PersistenceException)5 GateException (gate.util.GateException)5 Point (java.awt.Point)5 LinkedList (java.util.LinkedList)5 DataStore (gate.DataStore)4 ResourceInstantiationException (gate.creole.ResourceInstantiationException)4 InvalidOffsetException (gate.util.InvalidOffsetException)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 MalformedURLException (java.net.MalformedURLException)4 List (java.util.List)4 JButton (javax.swing.JButton)4 JPanel (javax.swing.JPanel)4 Annotation (gate.Annotation)3 AnnotationSet (gate.AnnotationSet)3 Corpus (gate.Corpus)3