public final class IntrospectionHelper extends Object
getHelper(Project,Class)
.
This may return an existing version, or a new one
...do not make any assumptions about its uniqueness, or its validity after the Project
instance has finished its build.Modifier and Type | Class and Description |
---|---|
static class |
IntrospectionHelper.Creator
creator - allows use of create/store external
to IntrospectionHelper.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
NOT_SUPPORTED_CHILD_POSTFIX
part of the error message created by
throwNotSupported . |
protected static String |
NOT_SUPPORTED_CHILD_PREFIX
part of the error message created by
throwNotSupported . |
Modifier and Type | Method and Description |
---|---|
void |
addText(Project project,
Object element,
String text)
Adds PCDATA to an element, using the element's
void addText(String) method, if it has one. |
static void |
clearCache()
Clears the static cache of on build finished.
|
java.lang.reflect.Method |
getAddTextMethod()
Returns the addText method when the introspected
class supports nested text.
|
Map<String,Class<?>> |
getAttributeMap()
Returns a read-only map of attributes supported by the introspected class.
|
java.lang.reflect.Method |
getAttributeMethod(String attributeName)
Returns the setter method of a named attribute.
|
Enumeration<String> |
getAttributes()
Returns an enumeration of the names of the attributes supported by the introspected class.
|
Class<?> |
getAttributeType(String attributeName)
Returns the type of a named attribute.
|
IntrospectionHelper.Creator |
getElementCreator(Project project,
String parentUri,
Object parent,
String elementName,
UnknownElement ue)
returns an object that creates and stores an object
for an element of a parent.
|
java.lang.reflect.Method |
getElementMethod(String elementName)
Returns the adder or creator method of a named nested element.
|
Class<?> |
getElementType(String elementName)
Returns the type of a named nested element.
|
List<java.lang.reflect.Method> |
getExtensionPoints()
Returns a read-only list of extension points supported
by the introspected class.
|
static IntrospectionHelper |
getHelper(Class<?> c)
Returns a helper for the given class, either from the cache
or by creating a new instance.
|
static IntrospectionHelper |
getHelper(Project p,
Class<?> c)
Returns a helper for the given class, either from the cache
or by creating a new instance.
|
Map<String,Class<?>> |
getNestedElementMap()
Returns a read-only map of nested elements supported
by the introspected class.
|
Enumeration<String> |
getNestedElements()
Returns an enumeration of the names of the nested elements supported
by the introspected class.
|
boolean |
isContainer()
Indicates whether the introspected class is a task container,
supporting arbitrary nested tasks/types.
|
boolean |
isDynamic()
Indicates whether the introspected class is a dynamic one,
supporting arbitrary nested elements and/or attributes.
|
void |
setAttribute(Project p,
Object element,
String attributeName,
Object value)
Sets the named attribute in the given element, which is part of the
given project.
|
void |
setAttribute(Project p,
Object element,
String attributeName,
String value)
Sets the named attribute in the given element, which is part of the
given project.
|
void |
storeElement(Project project,
Object parent,
Object child,
String elementName)
Stores a named nested element using a storage method determined
by the initial introspection.
|
boolean |
supportsCharacters()
Returns whether or not the introspected class supports PCDATA.
|
boolean |
supportsNestedElement(String elementName)
Indicates if this element supports a nested element of the
given name.
|
boolean |
supportsNestedElement(String parentUri,
String elementName)
Indicate if this element supports a nested element of the
given name.
|
boolean |
supportsNestedElement(String parentUri,
String elementName,
Project project,
Object parent)
Indicate if this element supports a nested element of the
given name.
|
boolean |
supportsReflectElement(String parentUri,
String elementName)
Check if this element supports a nested element from reflection.
|
void |
throwNotSupported(Project project,
Object parent,
String elementName)
Utility method to throw a NotSupported exception
|
protected static final String NOT_SUPPORTED_CHILD_POSTFIX
throwNotSupported
.protected static final String NOT_SUPPORTED_CHILD_PREFIX
throwNotSupported
.public void addText(Project project, Object element, String text) throws BuildException
void addText(String)
method, if it has one. If no
such method is present, a BuildException is thrown if the
given text contains non-whitespace.project
- The project which the element is part of.
Must not be null
.element
- The element to add the text to.
Must not be null
.text
- The text to add.
Must not be null
.BuildException
- if non-whitespace text is provided and no
method is available to handle it, or if
the handling method fails.public static void clearCache()
public java.lang.reflect.Method getAddTextMethod() throws BuildException
null
.BuildException
- if the introspected class does not
support the nested text.public Map<String,Class<?>> getAttributeMap()
Class
unmodifiable map. Can be empty, but never null
.public java.lang.reflect.Method getAttributeMethod(String attributeName) throws BuildException
attributeName
- The name of the attribute to find the setter
method of. Must not be null
.null
.BuildException
- if the introspected class does not
support the named attribute.public Enumeration<String> getAttributes()
getAttributeMap()
public Class<?> getAttributeType(String attributeName) throws BuildException
attributeName
- The name of the attribute to find the type of.
Must not be null
.null
.BuildException
- if the introspected class does not
support the named attribute.public IntrospectionHelper.Creator getElementCreator(Project project, String parentUri, Object parent, String elementName, UnknownElement ue)
project
- Project to which the parent object belongs.parentUri
- The namespace uri of the parent object.parent
- Parent object used to create the creator object to
create and store and instance of a subelement.elementName
- Name of the element to create an instance of.ue
- The unknown element associated with the element.public java.lang.reflect.Method getElementMethod(String elementName) throws BuildException
elementName
- The name of the attribute to find the setter
method of. Must not be null
.null
when the introspected
class is a dynamic configurator!BuildException
- if the introspected class does not
support the named nested element.public Class<?> getElementType(String elementName) throws BuildException
elementName
- The name of the element to find the type of.
Must not be null
.null
.BuildException
- if the introspected class does not
support the named nested element.public List<java.lang.reflect.Method> getExtensionPoints()
A task/type or nested element with void methods named add()
or addConfigured()
, taking a single class or interface
argument, supports extensions point. This method returns the list of
all these void add[Configured](type) methods.
Method
s of all supported extension points.
These methods are sorted such that if the argument type of a
method derives from another type also an argument of a method
of this list, the method with the most derived argument will
always appear first. Can be empty, but never null
.public static IntrospectionHelper getHelper(Class<?> c)
c
- The class for which a helper is required.
Must not be null
.public static IntrospectionHelper getHelper(Project p, Class<?> c)
p
- the project instance. Can be null, in which case the helper is not cached.c
- The class for which a helper is required.
Must not be null
.public Map<String,Class<?>> getNestedElementMap()
Class
unmodifiable map. Can be empty, but never null
.public Enumeration<String> getNestedElements()
getNestedElementMap()
public boolean isContainer()
true
if the introspected class is a container;
false
otherwise.TaskContainer
public boolean isDynamic()
true
if the introspected class is dynamic;
false
otherwise.DynamicElement
,
DynamicElementNS
public void setAttribute(Project p, Object element, String attributeName, Object value) throws BuildException
p
- The project containing the element. This is used when files
need to be resolved. Must not be null
.element
- The element to set the attribute in. Must not be
null
.attributeName
- The name of the attribute to set. Must not be
null
.value
- The value to set the attribute to. This may be interpreted
or converted to the necessary type if the setter method
doesn't accept an object of the supplied type.BuildException
- if the introspected class doesn't support
the given attribute, or if the setting
method fails.public void setAttribute(Project p, Object element, String attributeName, String value) throws BuildException
p
- The project containing the element. This is used when files
need to be resolved. Must not be null
.element
- The element to set the attribute in. Must not be
null
.attributeName
- The name of the attribute to set. Must not be
null
.value
- The value to set the attribute to. This may be interpreted
or converted to the necessary type if the setter method
doesn't just take a string. Must not be null
.BuildException
- if the introspected class doesn't support
the given attribute, or if the setting
method fails.public void storeElement(Project project, Object parent, Object child, String elementName) throws BuildException
project
- Ignored in this implementation.
May be null
.parent
- Parent instance to store the child in.
Must not be null
.child
- Child instance to store in the parent.
Should not be null
.elementName
- Name of the child element to store.
May be null
, in which case
this method returns immediately.BuildException
- if the storage method fails.public boolean supportsCharacters()
public boolean supportsNestedElement(String elementName)
elementName
- the name of the nested element being checkedpublic boolean supportsNestedElement(String parentUri, String elementName)
Note that this method will always return true if the
introspected class is dynamic
or contains a
method named "add" with void return type and a single argument.
To ge a more thorough answer, use the four-arg version of this
method instead.
parentUri
- the uri of the parentelementName
- the name of the nested element being checkedpublic boolean supportsNestedElement(String parentUri, String elementName, Project project, Object parent)
Note that this method will always return true if the
introspected class is dynamic
, so be
prepared to catch an exception about unsupported children when
calling getElementCreator
.
parentUri
- the uri of the parentelementName
- the name of the nested element being checkedproject
- currently executing project instanceparent
- the parent elementpublic boolean supportsReflectElement(String parentUri, String elementName)
parentUri
- the uri of the parentelementName
- the name of the nested element being checkedpublic void throwNotSupported(Project project, Object parent, String elementName)
project
- the Project instance.parent
- the object which doesn't support a requested elementelementName
- the name of the Element which is trying to be created.