Search in sources :

Example 1 with CreoleResource

use of gate.creole.metadata.CreoleResource in project gate-core by GateNLP.

the class CreoleAnnotationHandler method processCreoleResourceAnnotations.

@SuppressWarnings("unchecked")
public void processCreoleResourceAnnotations(Element element, Class<?> resourceClass) throws GateException {
    CreoleResource creoleResourceAnnot = resourceClass.getAnnotation(CreoleResource.class);
    if (creoleResourceAnnot != null) {
        // first process the top-level data and autoinstances
        processResourceData(resourceClass, element);
        // now deal with parameters
        // build a map holding the element corresponding to each parameter
        Map<String, Element> parameterMap = new HashMap<String, Element>();
        Map<String, Element> disjunctionMap = new HashMap<String, Element>();
        for (Element paramElt : (List<Element>) element.getChildren("PARAMETER")) {
            parameterMap.put(paramElt.getAttributeValue("NAME"), paramElt);
        }
        for (Element disjunctionElt : (List<Element>) element.getChildren("OR")) {
            String disjunctionId = disjunctionElt.getAttributeValue("ID");
            if (disjunctionId != null) {
                disjunctionMap.put(disjunctionId, disjunctionElt);
            }
            for (Element paramElt : (List<Element>) disjunctionElt.getChildren("PARAMETER")) {
                parameterMap.put(paramElt.getAttributeValue("NAME"), paramElt);
            }
        }
        processParameters(resourceClass, element, parameterMap, disjunctionMap);
    }
}
Also used : HashMap(java.util.HashMap) CreoleResource(gate.creole.metadata.CreoleResource) Element(org.jdom.Element) AnnotatedElement(java.lang.reflect.AnnotatedElement) List(java.util.List)

Example 2 with CreoleResource

use of gate.creole.metadata.CreoleResource in project gate-core by GateNLP.

the class CreoleAnnotationHandler method processInheritableResourceData.

/**
 * Recursive method to process the {@link CreoleResource} elements that can be
 * inherited from superclasses and interfaces (everything except the PRIVATE
 * and MAIN_VIEWER flags, the NAME and the AUTOINSTANCEs). Once data has been
 * extracted from the current class the method calls itself recursively for
 * the superclass and any implemented interfaces. For any given attribute, the
 * first value specified wins (i.e. the one on the most specific class).
 *
 * @param clazz
 *          the class to process
 * @param element
 *          the RESOURCE element to which data should be added.
 */
private void processInheritableResourceData(Class<?> clazz, Element element) {
    CreoleResource cr = clazz.getAnnotation(CreoleResource.class);
    if (cr != null) {
        addElement(element, cr.comment(), "COMMENT");
        addElement(element, cr.helpURL(), "HELPURL");
        addElement(element, cr.interfaceName(), "INTERFACE");
        addElement(element, cr.icon(), "ICON");
        if (cr.guiType() != GuiType.NONE && element.getChild("GUI") == null) {
            Element guiElement = new Element("GUI").setAttribute("TYPE", cr.guiType().toString());
            element.addContent(guiElement);
            addElement(guiElement, cr.resourceDisplayed(), "RESOURCE_DISPLAYED");
        }
        addElement(element, cr.annotationTypeDisplayed(), "ANNOTATION_TYPE_DISPLAYED");
    }
    Class<?> superclass = clazz.getSuperclass();
    if (superclass != null) {
        processInheritableResourceData(superclass, element);
    }
    for (Class<?> intf : clazz.getInterfaces()) {
        processInheritableResourceData(intf, element);
    }
}
Also used : CreoleResource(gate.creole.metadata.CreoleResource) Element(org.jdom.Element) AnnotatedElement(java.lang.reflect.AnnotatedElement)

Example 3 with CreoleResource

use of gate.creole.metadata.CreoleResource in project gate-core by GateNLP.

the class CreoleAnnotationHandler method processResourceData.

/**
 * Process the {@link CreoleResource} data for this class. This method first
 * extracts the non-inheritable data (PRIVATE, MAIN_VIEWER, NAME and TOOL),
 * then calls {@link #processInheritableResourceData} to process the
 * inheritable data, then deals with any specified {@link AutoInstance}s.
 *
 * @param resourceClass
 *          the resource class to process, which must be annotated with
 *          {@link CreoleResource}.
 * @param element
 *          the RESOURCE element to which data should be added.
 */
private void processResourceData(Class<?> resourceClass, Element element) {
    CreoleResource cr = resourceClass.getAnnotation(CreoleResource.class);
    if (cr.isPrivate() && element.getChild("PRIVATE") == null) {
        element.addContent(new Element("PRIVATE"));
    }
    if (cr.mainViewer() && element.getChild("MAIN_VIEWER") == null) {
        element.addContent(new Element("MAIN_VIEWER"));
    }
    if (cr.tool() && element.getChild("TOOL") == null) {
        element.addContent(new Element("TOOL"));
    }
    // NAME is the name given in the annotation, or the simple name of
    // the class if omitted
    addElement(element, ("".equals(cr.name())) ? resourceClass.getSimpleName() : cr.name(), "NAME");
    processInheritableResourceData(resourceClass, element);
    processAutoInstances(cr, element);
}
Also used : CreoleResource(gate.creole.metadata.CreoleResource) Element(org.jdom.Element) AnnotatedElement(java.lang.reflect.AnnotatedElement)

Aggregations

CreoleResource (gate.creole.metadata.CreoleResource)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 Element (org.jdom.Element)3 HashMap (java.util.HashMap)1 List (java.util.List)1