Search in sources :

Example 36 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class GappModel method finish.

/**
 * Finish up processing of the gapp file ready for writing.
 */
@SuppressWarnings("unchecked")
public void finish() {
    // remove duplicate plugin entries
    try {
        // this XPath selects all URLHolders out of the URL list that have
        // the same URL string as one of their preceding siblings, i.e. if
        // there are N URLs in the list with the same value then this
        // XPath
        // will select all but the first one of them.
        XPath duplicatePluginXPath = XPath.newInstance("/gate.util.persistence.GateApplication/urlList" + "/localList/gate.util.persistence.PersistenceManager-URLHolder" + "[urlString = preceding-sibling::gate.util.persistence.PersistenceManager-URLHolder/urlString]");
        List<Element> duplicatePlugins = duplicatePluginXPath.selectNodes(gappDocument);
        for (Element e : duplicatePlugins) {
            e.getParentElement().removeContent(e);
        }
    } catch (JDOMException e) {
        throw new GateRuntimeException("Error applying XPath expression to remove duplicate plugins", e);
    }
}
Also used : XPath(org.jdom.xpath.XPath) Element(org.jdom.Element) GateRuntimeException(gate.util.GateRuntimeException) JDOMException(org.jdom.JDOMException)

Example 37 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class SerialCorpusImpl method resourceDeleted.

/**
 * Called by a datastore when a resource has been deleted
 */
@Override
public void resourceDeleted(DatastoreEvent evt) {
    DataStore ds = (DataStore) evt.getSource();
    // 1. check whether this datastore fired the event. If not, return.
    if (!ds.equals(this.dataStore))
        return;
    Object docID = evt.getResourceID();
    if (docID == null)
        return;
    if (DEBUG)
        Out.prln("Resource deleted called for: " + docID);
    // unloaded immediately
    if (docID.equals(this.getLRPersistenceId())) {
        Factory.deleteResource(this);
        return;
    }
    // if
    boolean isDirty = false;
    // first
    for (int i = 0; i < docDataList.size(); i++) {
        DocumentData docData = docDataList.get(i);
        // don't break the loop, because it might appear more than once
        if (docID.equals(docData.getPersistentID())) {
            if (evt.getResource() == null) {
                // instead of calling remove() which tries to load the
                // document
                // remove it from the documents and docDataList
                documentRemoved(docDataList.get(i).persistentID.toString());
                docDataList.remove(i);
                documents.remove(i);
                isDirty = true;
                i--;
                continue;
            }
            remove(i);
            isDirty = true;
        }
    // if
    }
    if (isDirty)
        try {
            this.dataStore.sync(this);
        } catch (PersistenceException ex) {
            throw new GateRuntimeException("SerialCorpusImpl: " + ex.getMessage());
        } catch (SecurityException sex) {
            throw new GateRuntimeException("SerialCorpusImpl: " + sex.getMessage());
        }
}
Also used : DataStore(gate.DataStore) GateRuntimeException(gate.util.GateRuntimeException) PersistenceException(gate.persist.PersistenceException)

Example 38 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class SerialCorpusImpl method get.

@Override
public Document get(int index) {
    if (index >= docDataList.size())
        return null;
    Document res = documents.get(index);
    if (DEBUG)
        Out.prln("SerialCorpusImpl: get(): index " + index + "result: " + res);
    // if the document is null, then I must get it from the DS
    if (res == null) {
        FeatureMap parameters = Factory.newFeatureMap();
        parameters.put(DataStore.DATASTORE_FEATURE_NAME, this.dataStore);
        try {
            parameters.put(DataStore.LR_ID_FEATURE_NAME, docDataList.get(index).getPersistentID());
            Document lr = (Document) Factory.createResource(docDataList.get(index).getClassType(), parameters);
            if (DEBUG)
                Out.prln("Loaded document :" + lr.getName());
            // change the result to the newly loaded doc
            res = lr;
            // finally replace the doc with the instantiated version
            documents.set(index, lr);
        } catch (ResourceInstantiationException ex) {
            Err.prln("Error reading document inside a serialised corpus.");
            throw new GateRuntimeException(ex);
        }
    }
    return res;
}
Also used : FeatureMap(gate.FeatureMap) GateRuntimeException(gate.util.GateRuntimeException) Document(gate.Document) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 39 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class CreoleRegisterImpl method getAnnotationVRs.

// getVRsForResource()
/**
 * Returns a list of strings representing class names for annotation VRs that
 * are able to display/edit all types of annotations. The default VR will be
 * the first in the returned list.
 *
 * @return a list with all VRs that can display all annotation types
 */
@Override
public List<String> getAnnotationVRs() {
    LinkedList<String> responseList = new LinkedList<String>();
    String defaultVR = null;
    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);
        Class<?> vrResourceClass = null;
        try {
            vrResourceClass = vrResourceData.getResourceClass();
        } catch (ClassNotFoundException ex) {
            throw new GateRuntimeException("Couldn't create a class object for VR called " + vrClassName);
        }
        // Test if VR can display all types of annotations
        if (vrResourceData.getGuiType() == ResourceData.NULL_GUI && vrResourceData.getAnnotationTypeDisplayed() == null && vrResourceData.getResourceDisplayed() == null && gate.creole.AnnotationVisualResource.class.isAssignableFrom(vrResourceClass)) {
            responseList.add(vrClassName);
            if (vrResourceData.isMainView())
                defaultVR = vrClassName;
        }
    // 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) LinkedList(java.util.LinkedList)

Example 40 with GateRuntimeException

use of gate.util.GateRuntimeException in project gate-core by GateNLP.

the class CreoleRegisterImpl method put.

// registerBuiltins()
/**
 * Overide HashMap's put method to maintain a list of all the types of LR in
 * the register, and a list of tool types. The key is the resource type, the
 * value its data.
 */
@Override
public ResourceData put(String key, ResourceData rd) {
    if (super.containsKey(key)) {
        ResourceData rData = super.get(key);
        rData.increaseReferenceCount();
        if (DEBUG)
            Out.println(key + " is already defined, new reference will be ignored.");
        // TODO not sure what we should actually return here
        return rData;
    }
    // get the resource implementation class
    Class<? extends Resource> resClass = null;
    try {
        resClass = rd.getResourceClass();
    } catch (ClassNotFoundException e) {
        throw new GateRuntimeException("Couldn't get resource class from the resource data:" + e);
    }
    // add class names to the type lists
    if (LanguageResource.class.isAssignableFrom(resClass)) {
        if (DEBUG)
            Out.prln("LR: " + resClass);
        // for
        if (lrTypes == null)
            lrTypes = new HashSet<String>();
        // deserialisation
        lrTypes.add(rd.getClassName());
    }
    if (ProcessingResource.class.isAssignableFrom(resClass)) {
        if (DEBUG) {
            Out.prln("PR: " + resClass);
        // Out.prln("prTypes: " + prTypes);
        // Out.prln("rd.getClassName(): " + rd.getClassName());
        }
        // for
        if (prTypes == null)
            prTypes = new HashSet<String>();
        // deserialisation
        prTypes.add(rd.getClassName());
    }
    if (VisualResource.class.isAssignableFrom(resClass)) {
        if (DEBUG)
            Out.prln("VR: " + resClass);
        // for
        if (vrTypes == null)
            vrTypes = new LinkedList<String>();
        // we have to simulate Set behaviour as this is a list
        if (!vrTypes.contains(rd.getClassName()))
            vrTypes.add(rd.getClassName());
    }
    if (Controller.class.isAssignableFrom(resClass)) {
        if (DEBUG)
            Out.prln("Controller: " + resClass);
        // for
        if (controllerTypes == null)
            controllerTypes = new HashSet<String>();
        // deserialisation
        controllerTypes.add(rd.getClassName());
    }
    if (PackagedController.class.isAssignableFrom(resClass)) {
        if (DEBUG)
            Out.prln("Application: " + resClass);
        if (applicationTypes == null)
            applicationTypes = new HashSet<String>();
        applicationTypes.add(rd.getClassName());
    }
    // maintain tool types list
    if (rd.isTool()) {
        // for
        if (toolTypes == null)
            toolTypes = new HashSet<String>();
        // deserialisation
        toolTypes.add(rd.getClassName());
    }
    return super.put(key, rd);
}
Also used : GateRuntimeException(gate.util.GateRuntimeException) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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