|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgate.creole.CreoleAnnotationHandler
public class CreoleAnnotationHandler
Class to take a creole.xml file (as a JDOM tree) and add elements corresponding to the CREOLE annotations on the RESOURCE classes it declares.
| Field Summary | |
|---|---|
private URL |
creoleFileUrl
|
| Constructor Summary | |
|---|---|
CreoleAnnotationHandler(URL creoleFileUrl)
Create an annotation handler for the given creole.xml file. |
|
| Method Summary | |
|---|---|
private void |
addAttribute(org.jdom.Element paramElt,
Object value,
Object defaultValue,
String attrName)
Add an attribute with the given value to the given element, but only if the element does not already have the attribute, and the value is not equal to the given default value. |
private void |
addElement(org.jdom.Element parent,
String value,
String elementName)
Adds an element with the given name and text value to the parent element, but only if no such child element already exists and the value is not the empty string. |
void |
addJarsToClassLoader(org.jdom.Document jdomDoc)
Extract all JAR elements from the given JDOM document and add the jars they reference to the GateClassLoader. |
private void |
addJarsToClassLoader(org.jdom.Element jdomElt)
Recursively search the given element for JAR entries and add these jars to the GateClassLoader |
void |
createResourceElementsForDirInfo(org.jdom.Document jdomDoc)
Fetches the directory information for this handler's creole plugin and adds additional RESOURCE elements to the given JDOM document so that it contains a RESOURCE for every resource type defined in the plugin's directory info. |
private void |
determineCollectionElementType(Method method,
org.jdom.Element paramElt)
Given a single-argument method whose parameter is a Collection, use the method's generic type information to
determine the collection element type and store it as the
ITEM_CLASS_NAME attribute of the given Element. |
private Class<?> |
findCollectionElementType(Type type)
Find the collection element type for the given type. |
private Class<?> |
findCollectionElementType(Type type,
Map<TypeVariable<?>,Class<?>> tvMap)
Recursive method to find the collection element type for the given type. |
private void |
findResourceElements(Map<String,org.jdom.Element> map,
org.jdom.Element elt)
|
void |
processAnnotations(org.jdom.Document jdomDoc)
Processes annotations for resource classes named in the given creole.xml document, adding the relevant XML elements to the document as appropriate. |
private void |
processAnnotations(org.jdom.Element element)
Process annotations for the given element. |
private void |
processAnnotationsForResource(org.jdom.Element element)
Process the given RESOURCE element, adding extra elements to it based on the annotations on the resource class. |
private void |
processAutoInstances(CreoleResource cr,
org.jdom.Element element)
Process the AutoInstance annotations contained in the given
CreoleResource and add the corresponding
AUTOINSTANCE/HIDDEN-AUTOINSTANCE elements to the given parent. |
void |
processCreoleResourceAnnotations(org.jdom.Element element,
Class<?> resourceClass)
|
private void |
processInheritableResourceData(Class<?> clazz,
org.jdom.Element element)
Recursive method to process the CreoleResource elements
that can be inherited from superclasses and interfaces (everything
except the PRIVATE and MAIN_VIEWER flags, the NAME and the
AUTOINSTANCEs). |
private void |
processParameters(Class<?> resourceClass,
org.jdom.Element resourceElement,
Map<String,org.jdom.Element> parameterMap,
Map<String,org.jdom.Element> disjunctionMap)
Process any CreoleParameter and
HiddenCreoleParameter annotations on set methods of the
given class and set up the corresponding PARAMETER elements. |
private void |
processResourceData(Class<?> resourceClass,
org.jdom.Element element)
Process the CreoleResource data for this class. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private URL creoleFileUrl
| Constructor Detail |
|---|
public CreoleAnnotationHandler(URL creoleFileUrl)
creoleFileUrl - location of the creole.xml file.| Method Detail |
|---|
public void addJarsToClassLoader(org.jdom.Document jdomDoc)
throws MalformedURLException
jdomDoc - JDOM document representing a parsed creole.xml file.
MalformedURLException
private void addJarsToClassLoader(org.jdom.Element jdomElt)
throws MalformedURLException
jdomElt - JDOM element representing a creole.xml file
MalformedURLException
public void createResourceElementsForDirInfo(org.jdom.Document jdomDoc)
throws MalformedURLException
jdomDoc - JDOM document which should be the parsed creole.xml
that this handler was configured for.
MalformedURLException
private void findResourceElements(Map<String,org.jdom.Element> map,
org.jdom.Element elt)
public void processAnnotations(org.jdom.Document jdomDoc)
throws GateException
jdomDoc - the parsed creole.xml file
GateException
private void processAnnotations(org.jdom.Element element)
throws GateException
element - the element to process.
GateException
private void processAnnotationsForResource(org.jdom.Element element)
throws GateException
element - the RESOURCE element to process.
GateException
public void processCreoleResourceAnnotations(org.jdom.Element element,
Class<?> resourceClass)
throws GateException
GateException
private void processResourceData(Class<?> resourceClass,
org.jdom.Element element)
CreoleResource data for this class. This method
first extracts the non-inheritable data (PRIVATE, MAIN_VIEWER,
NAME and TOOL), then calls processInheritableResourceData(java.lang.Class>, org.jdom.Element)
to process the inheritable data, then deals with any specified
AutoInstances.
resourceClass - the resource class to process, which must be
annotated with CreoleResource.element - the RESOURCE element to which data should be added.
private void processInheritableResourceData(Class<?> clazz,
org.jdom.Element element)
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).
clazz - the class to processelement - the RESOURCE element to which data should be added.
private void addElement(org.jdom.Element parent,
String value,
String elementName)
parent - the parent elementvalue - the text value for the new childelementName - the name of the new child element
private void processAutoInstances(CreoleResource cr,
org.jdom.Element element)
AutoInstance annotations contained in the given
CreoleResource and add the corresponding
AUTOINSTANCE/HIDDEN-AUTOINSTANCE elements to the given parent.
cr - the CreoleResource annotationelement - the parent element
private void processParameters(Class<?> resourceClass,
org.jdom.Element resourceElement,
Map<String,org.jdom.Element> parameterMap,
Map<String,org.jdom.Element> disjunctionMap)
throws GateException
CreoleParameter and
HiddenCreoleParameter annotations on set methods of the
given class and set up the corresponding PARAMETER elements.
resourceClass - the resource class to processresourceElement - the RESOURCE element to which the PARAMETERs
are to be addedparameterMap - 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
HiddenCreoleParameter annotation are explicitly
mapped to null in this map.disjunctionMap - a map from disjunction IDs to the OR elements
that define them. Disjunctive parameters are handled by
specifying a disjunction ID on the CreoleParameter
annotations - parameters with the same disjunction ID are
grouped under the same OR element.
GateException
private void determineCollectionElementType(Method method,
org.jdom.Element paramElt)
Collection, use the method's generic type information to
determine the collection element type and store it as the
ITEM_CLASS_NAME attribute of the given Element.
method - the setter methodparamElt - the PARAMETER elementprivate Class<?> findCollectionElementType(Type type)
type - the type to use. To be able to find the element type,
this must be a Class that is assignable from Collection or
a ParameterizedType whose raw type is assignable from
Collection.
null if this cannot be determined
private Class<?> findCollectionElementType(Type type,
Map<TypeVariable<?>,Class<?>> tvMap)
type - the type to usetvMap - map from type variables to the classes they are
ultimately bound to. The reflection APIs can tell us that
List<String> is an instantiation of List<X>
and List<X> implements Collection<X>, but we
have to keep track of the fact that X maps to String
ourselves.
null if it
cannot be determined.
private void addAttribute(org.jdom.Element paramElt,
Object value,
Object defaultValue,
String attrName)
paramElt - the elementvalue - the attribute value (which will be converted to a
string)defaultValue - if value.equals(defaultValue) we do not add the
attribute.attrName - the name of the attribute to add.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||