Top Description Inners Fields Constructors Methods
org.apache.tools.ant

public final Class IntrospectionHelper

extends Object
Class Inheritance
Imports
java.io.File, java.lang.reflect.Constructor, .InvocationTargetException, .Method, .ParameterizedType, .Type, java.util.ArrayList, .Collections, .Enumeration, .HashMap, .Hashtable, .List, .Locale, .Map, .Optional, .OptionalDouble, .OptionalInt, .OptionalLong, java.util.function.Supplier, org.apache.tools.ant.taskdefs.PreSetDef, org.apache.tools.ant.types.EnumeratedAttribute, .Resource, org.apache.tools.ant.types.resources.FileProvider, .FileResource, org.apache.tools.ant.util.StringUtils

Helper class that collects the methods a task or nested element holds to set attributes, create nested elements or hold PCDATA elements. It contains hashtables containing classes that use introspection to handle all the invocation of the project-component specific methods. This class is somewhat complex, as it implements the O/X mapping between Ant XML and Java class instances. This is not the best place for someone new to Ant to start contributing to the codebase, as a change here can break the entire system in interesting ways. Always run a full test of Ant before checking in/submitting changes to this file. The class is final and has a private constructor. To get an instance for a specific (class,project) combination, use 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
IntrospectionHelper.AddNestedCreator

Version to use for addXXX and addConfiguredXXX

private abstract static class
IntrospectionHelper.AttributeSetter

Internal interface used to setting element attributes.

private static class
public static class
IntrospectionHelper.Creator

creator - allows use of create/store external to IntrospectionHelper.

private static class
private abstract static class
IntrospectionHelper.NestedCreator

Internal interface used to create nested elements.

Field Summary

Modifier and TypeField and Description
private final Method
addText

The method to invoke to add PCDATA.

private final List<Method>
addTypeMethods

Vector of methods matching add[Configured](Class) pattern.

private final Map<String, IntrospectionHelper.AttributeSetter>
attributeSetters

Map from attribute names to attribute setter methods (String to AttributeSetter).

private final Map<String, Class<?>>
attributeTypes

Map from attribute names to attribute types (String to Class).

private final Class<?>
bean

The class introspected by this instance.

private static final String
private static final Map<String, IntrospectionHelper>
HELPERS

Helper instances we've already created (Class.getName() to IntrospectionHelper).

private static final int
private final Map<String, IntrospectionHelper.NestedCreator>
nestedCreators

Map from attribute names to methods to create nested types (String to NestedCreator).

private final Map<String, Class<?>>
nestedTypes

Map from attribute names to nested types (String to Class).

protected static final String
NOT_SUPPORTED_CHILD_POSTFIX

part of the error message created by throwNotSupported.

protected static final String
NOT_SUPPORTED_CHILD_PREFIX

part of the error message created by throwNotSupported.

private static final Map<Class<?>, Class<?>>
PRIMITIVE_TYPE_MAP

Map from primitive types to wrapper classes for use in createAttributeSetter (Class to Class).

Constructor Summary

AccessConstructor and Description
private
IntrospectionHelper(final Class<?>
The bean type to introspect. Must not be null.
bean
)

Sole constructor, which is private to ensure that all IntrospectionHelpers are created via getHelper.

Method Summary

Modifier and TypeMethod and Description
public void
addText(final Project
The project which the element is part of. Must not be null.
project
,
final Object
The element to add the text to. Must not be null.
element
,
String
The text to add. Must not be null.
text
)

Adds PCDATA to an element, using the element's void addText(String) method, if it has one.

public static void
clearCache()

Clears the static cache of on build finished.

private String
condenseText(final String text)

private IntrospectionHelper.NestedCreator

Returns:

a nested creator, or null if there is no component of the given name, or it has no matching add type methods
createAddTypeCreator
(final Project
owning project
project
,
final Object
Parent object used to create the instance.
parent
,
final String
name of the element
elementName
)

Create a NestedCreator for the given element.

private IntrospectionHelper.AttributeSetter

Returns:

an appropriate AttributeSetter instance, or null if no appropriate conversion is available.
createAttributeSetter
(final Method
The method to invoke on the bean when the setter is invoked. Must not be null.
m
,
final Class<?>
The type of the single argument of the bean's method. Must not be null.
arg
,
final String
the name of the attribute for which the setter is being created.
attrName
)

Creates an implementation of AttributeSetter for the given attribute type.

private Object
createDynamicElement(final Object parent, final String ns, final String localName, final String qName)

Invokes the "correct" createDynamicElement method on parent in order to obtain a child element by name.

public Object

Returns:

an instance of the specified element type
createElement
(final Project
Project to which the parent object belongs. Must not be null. If the resulting object is an instance of ProjectComponent, its Project reference is set to this parameter value.
project
,
final Object
Parent object used to create the instance. Must not be null.
parent
,
final String
Name of the element to create an instance of. Must not be null.
elementName
)

Deprecated since 1.6.x. This is not a namespace aware method.
Creates a named nested element.
private IntrospectionHelper.MethodAndObject
createRestricted(final ComponentHelper helper, final String elementName, final List<Method> addTypeMethods)

private IntrospectionHelper.MethodAndObject
createTopLevel(final ComponentHelper helper, final String elementName, final List<Method> methods)

private static BuildException

Returns:

the nested exception
extractBuildException
(final InvocationTargetException
the exception
ite
)

Helper method to extract the inner fault from an InvocationTargetException, and turn it into a BuildException.

private Method

Returns:

a matching Method; null if none found.
findMatchingMethod
(final Class<?>
the Class type to search for.
paramClass
,
final List<Method>
the List of methods to search.
methods
)

Search the list of methods to find the first method that has a parameter that accepts the nested element object.

private AntTypeDefinition
findRestrictedDefinition(final ComponentHelper helper, final String componentName, final List<Method> methods)

public Method

Returns:

the method on this introspected class that adds nested text. Cannot be null.
getAddTextMethod
()

Returns the addText method when the introspected class supports nested text.

public Map<String, Class<?>>

Returns:

an attribute name to attribute Class unmodifiable map. Can be empty, but never null.
getAttributeMap
()

Returns a read-only map of attributes supported by the introspected class.

public Method

Returns:

the method on this introspected class that sets this attribute. This will never be null.
getAttributeMethod
(final String
The name of the attribute to find the setter method of. Must not be null.
attributeName
)

Returns the setter method of a named attribute.

public Enumeration<String>

Returns:

an enumeration of the names of the attributes supported by the introspected class.
getAttributes
()

Returns an enumeration of the names of the attributes supported by the introspected class.

public Class<?>

Returns:

the type of the attribute with the specified name. This will never be null.
getAttributeType
(final String
The name of the attribute to find the type of. Must not be null.
attributeName
)

Returns the type of a named attribute.

public IntrospectionHelper.Creator

Returns:

a creator object to create and store the element instance.
getElementCreator
(final Project
Project to which the parent object belongs.
project
,
final String
The namespace uri of the parent object.
parentUri
,
final Object
Parent object used to create the creator object to create and store and instance of a subelement.
parent
,
final String
Name of the element to create an instance of.
elementName
,
final UnknownElement
The unknown element associated with the element.
ue
)

returns an object that creates and stores an object for an element of a parent.

public Method

Returns:

the method on this introspected class that adds or creates this nested element. Can be null when the introspected class is a dynamic configurator!
getElementMethod
(final String
The name of the attribute to find the setter method of. Must not be null.
elementName
)

Returns the adder or creator method of a named nested element.

private String

Returns:

a description of the element type
getElementName
(final Project
The project the element is defined in. Must not be null.
project
,
final Object
The element to describe. Must not be null.
element
)

Returns a description of the type of the given element in relation to a given project.

public Class<?>

Returns:

the type of the nested element with the specified name. This will never be null.
getElementType
(final String
The name of the element to find the type of. Must not be null.
elementName
)

Returns the type of a named nested element.

private IntrospectionHelper.AttributeSetter
getEnumSetter(final Class<?> reflectedArg, final Method m, final Class<?> arg)

public List<Method>

Returns:

a list of void, single argument add() or addConfigured() Methods 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.
getExtensionPoints
()

Returns a read-only list of extension points supported by the introspected class.

public static IntrospectionHelper

Returns:

a helper for the specified class
getHelper
(final Class<?>
The class for which a helper is required. Must not be null.
c
)

Returns a helper for the given class, either from the cache or by creating a new instance.

public static IntrospectionHelper

Returns:

a helper for the specified class
getHelper
(final Project
the project instance. Can be null, in which case the helper is not cached.
p
,
final Class<?>
The class for which a helper is required. Must not be null.
c
)

Returns a helper for the given class, either from the cache or by creating a new instance.

private IntrospectionHelper.NestedCreator

Returns:

a nested creator that can handle the child elements.
getNestedCreator
(final Project
ant project
project
,
String
URI of the parent.
parentUri
,
final Object
the parent class
parent
,
final String
element to work with. This can contain a URI,localname tuple of of the form uri:localname
elementName
,
final UnknownElement
the bit of XML to work with
child
)

Get the specific NestedCreator for a given project/parent/element combination

public Map<String, Class<?>>

Returns:

a nested-element name to nested-element Class unmodifiable map. Can be empty, but never null.
getNestedElementMap
()

Returns a read-only map of nested elements supported by the introspected class.

public Enumeration<String>

Returns:

an enumeration of the names of the nested elements supported by the introspected class.
getNestedElements
()

Returns an enumeration of the names of the nested elements supported by the introspected class.

private static String

Returns:

the lower-cased method name with the prefix removed.
getPropertyName
(final String
The name of the method in question. Must not be null.
methodName
,
final String
The prefix to remove. Must not be null.
prefix
)

Extracts the name of a property from a method name by subtracting a given prefix and converting into lower case.

private void
insertAddTypeMethod(final Method
the Method to insert.
method
)

Inserts an add or addConfigured method into the addTypeMethods array.

public boolean

Returns:

true if the introspected class is a container; false otherwise.
isContainer
()

Indicates whether the introspected class is a task container, supporting arbitrary nested tasks/types.

public boolean

Returns:

true if the introspected class is dynamic; false otherwise.
isDynamic
()

Indicates whether the introspected class is a dynamic one, supporting arbitrary nested elements and/or attributes.

private boolean

Returns:

true if the given set method is to be hidden.
isHiddenSetMethod
(final String
the name of the set method
name
,
final Class<?>
the type of the set method's parameter
type
)

Certain set methods are part of the Ant core interface to tasks and therefore not to be considered for introspection

public void
setAttribute(final Project
The project containing the element. This is used when files need to be resolved. Must not be null.
p
,
final Object
The element to set the attribute in. Must not be null.
element
,
final String
The name of the attribute to set. Must not be null.
attributeName
,
final Object
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.
value
)

Sets the named attribute in the given element, which is part of the given project.

public void
setAttribute(final Project
The project containing the element. This is used when files need to be resolved. Must not be null.
p
,
final Object
The element to set the attribute in. Must not be null.
element
,
final String
The name of the attribute to set. Must not be null.
attributeName
,
final String
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.
value
)

Sets the named attribute in the given element, which is part of the given project.

public void
storeElement(final Project
Ignored in this implementation. May be null.
project
,
final Object
Parent instance to store the child in. Must not be null.
parent
,
final Object
Child instance to store in the parent. Should not be null.
child
,
final String
Name of the child element to store. May be null, in which case this method returns immediately.
elementName
)

Stores a named nested element using a storage method determined by the initial introspection.

public boolean

Returns:

whether or not the introspected class supports PCDATA.
supportsCharacters
()

Returns whether or not the introspected class supports PCDATA.

public boolean

Returns:

true if the given nested element is supported
supportsNestedElement
(final String
the name of the nested element being checked
elementName
)

Indicates if this element supports a nested element of the given name.

public boolean

Returns:

true if the given nested element is supported
supportsNestedElement
(final String
the uri of the parent
parentUri
,
final String
the name of the nested element being checked
elementName
)

Indicate if this element supports a nested element of the given name.

public boolean

Returns:

true if the given nested element is supported
supportsNestedElement
(final String
the uri of the parent
parentUri
,
final String
the name of the nested element being checked
elementName
,
final Project
currently executing project instance
project
,
final Object
the parent element
parent
)

Indicate if this element supports a nested element of the given name.

public boolean

Returns:

true if the given nested element is supported
supportsReflectElement
(String
the uri of the parent
parentUri
,
final String
the name of the nested element being checked
elementName
)

Check if this element supports a nested element from reflection.

public void
throwNotSupported(final Project
the Project instance.
project
,
final Object
the object which doesn't support a requested element
parent
,
final String
the name of the Element which is trying to be created.
elementName
)

Utility method to throw a NotSupported exception

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait