Package org.apache.tools.ant
Class ComponentHelper
java.lang.Object
org.apache.tools.ant.ComponentHelper
Component creation and configuration.
 The class is based around handing component
 definitions in an AntTypeTable.
 The old task/type methods have been kept
 for backward compatibly.
 Project will just delegate its calls to this class.
 A very simple hook mechanism is provided that allows users to plug
 in custom code. It is also possible to replace the default behavior
 (for example in an app embedding Ant)
- Since:
- Ant1.6
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Stringreference under which we register ourselves with a project -"ant.ComponentHelper"
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreates a new ComponentHelper instance.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddDataTypeDefinition(String typeName, Class<?> typeClass) Adds a new datatype definition.voidDescribeaddDataTypeDefinitionmethod here.voidaddTaskDefinition(String taskName, Class<?> taskClass) Adds a new task definition to the project.voidcheckTaskClass(Class<?> taskClass) Checks whether or not a class is suitable for serving as Ant task.createComponent(String componentName) Create an object for a component.createComponent(UnknownElement ue, String ns, String componentType) Factory method to create the components.createDataType(String typeName) Creates a new instance of a data type.createTask(String taskType) Creates a new instance of a task.diagnoseCreationFailure(String componentName, String type) Handler called to do decent diagnosis on instantiation failure.voidenterAntLib(String uri) Called at the start of processing an antlib.voidCalled at the end of processing an antlib.Returns the current datatype definition hashtable.Class<?>getComponentClass(String componentName) Return the class of the component name.static ComponentHelpergetComponentHelper(Project project) Find a project component for a specific project, creating it if it does not exist.Returns the current type definition hashtable.getDefinition(String componentName) Return the antTypeDefinition for a componentName.getElementName(Object element) Returns a description of the type of the given element.getElementName(Object o, boolean brief) Returns a description of the type of the given element.static StringgetElementName(Project p, Object o, boolean brief) Convenient way to get some element name even when you may not have a Project context.getNext()Get the next chained component helper.Get the project.getRestrictedDefinitions(String componentName) This returns a list of restricted definitions for a name.Returns the current task definition hashtable.voidThis method is initialization code implementing the original ant component loading from /org/apache/tools/ant/taskdefs/default.properties and /org/apache/tools/ant/types/default.properties.voidinitSubProject(ComponentHelper helper) Used with creating child projects.voidsetNext(ComponentHelper next) Set the next chained component helper.voidsetProject(Project project) Sets the project for this component helper.
- 
Field Details- 
COMPONENT_HELPER_REFERENCEreference under which we register ourselves with a project -"ant.ComponentHelper"- See Also:
 
 
- 
- 
Constructor Details- 
ComponentHelperprotected ComponentHelper()Creates a new ComponentHelper instance.
 
- 
- 
Method Details- 
getProjectGet the project.- Returns:
- the project owner of this helper.
 
- 
getComponentHelperFind a project component for a specific project, creating it if it does not exist.- Parameters:
- project- the project.
- Returns:
- the project component for a specific project.
 
- 
setNextSet the next chained component helper.- Parameters:
- next- the next chained component helper.
 
- 
getNextGet the next chained component helper.- Returns:
- the next chained component helper.
 
- 
setProjectSets the project for this component helper.- Parameters:
- project- the project for this helper.
 
- 
initSubProjectUsed with creating child projects. Each child project inherits the component definitions from its parent.- Parameters:
- helper- the component helper of the parent project.
 
- 
createComponentpublic Object createComponent(UnknownElement ue, String ns, String componentType) throws BuildException Factory method to create the components. This should be called by UnknownElement.- Parameters:
- ue- The Unknown Element creating this component.
- ns- Namespace URI. Also available as ue.getNamespace().
- componentType- The component type, Also available as ue.getComponentName().
- Returns:
- the created component.
- Throws:
- BuildException- if an error occurs.
 
- 
createComponentCreate an object for a component.- Parameters:
- componentName- the name of the component, if the component is in a namespace, the name is prefixed with the namespace uri and ":".
- Returns:
- the class if found or null if not.
 
- 
getComponentClassReturn the class of the component name.- Parameters:
- componentName- the name of the component, if the component is in a namespace, the name is prefixed with the namespace uri and ":".
- Returns:
- the class if found or null if not.
 
- 
getDefinitionReturn the antTypeDefinition for a componentName.- Parameters:
- componentName- the name of the component.
- Returns:
- the ant definition or null if not present.
 
- 
initDefaultDefinitionspublic void initDefaultDefinitions()This method is initialization code implementing the original ant component loading from /org/apache/tools/ant/taskdefs/default.properties and /org/apache/tools/ant/types/default.properties.
- 
addTaskDefinitionAdds a new task definition to the project. Attempting to override an existing definition with an equivalent one (i.e. with the same classname) results in a verbose log message. Attempting to override an existing definition with a different one results in a warning log message.- Parameters:
- taskName- The name of the task to add. Must not be- null.
- taskClass- The full name of the class implementing the task. Must not be- null.
- Throws:
- BuildException- if the class is unsuitable for being an Ant task. An error level message is logged before this exception is thrown.
- See Also:
 
- 
checkTaskClassChecks whether or not a class is suitable for serving as Ant task. Ant task implementation classes must be public, concrete, and have a no-arg constructor.- Parameters:
- taskClass- The class to be checked. Must not be- null.
- Throws:
- BuildException- if the class is unsuitable for being an Ant task. An error level message is logged before this exception is thrown.
 
- 
getTaskDefinitionsReturns the current task definition hashtable. The returned hashtable is "live" and so should not be modified. Also, the returned table may be modified asynchronously.- Returns:
- a map of from task name to implementing class (String to Class).
 
- 
getDataTypeDefinitionsReturns the current type definition hashtable. The returned hashtable is "live" and so should not be modified.- Returns:
- a map of from type name to implementing class (String to Class).
 
- 
getRestrictedDefinitionsThis returns a list of restricted definitions for a name. The returned List is "live" and so should not be modified. Also, the returned list may be modified asynchronously. Any access must be guarded with a lock on the list itself.- Parameters:
- componentName- the name to use.
- Returns:
- the list of restricted definitions for a particular name.
 
- 
addDataTypeDefinitionAdds a new datatype definition. Attempting to override an existing definition with an equivalent one (i.e. with the same classname) results in a verbose log message. Attempting to override an existing definition with a different one results in a warning log message, but the definition is changed.- Parameters:
- typeName- The name of the datatype. Must not be- null.
- typeClass- The full name of the class implementing the datatype. Must not be- null.
 
- 
addDataTypeDefinitionDescribeaddDataTypeDefinitionmethod here.- Parameters:
- def- an- AntTypeDefinitionvalue.
 
- 
getAntTypeTableReturns the current datatype definition hashtable. The returned hashtable is "live" and so should not be modified.- Returns:
- a map of from datatype name to datatype definition
         (String to AntTypeDefinition).
 
- 
createTaskCreates a new instance of a task. Called from Project.createTask(), which can be called by tasks.- Parameters:
- taskType- The name of the task to create an instance of. Must not be- null.
- Returns:
- an instance of the specified task, or nullif the task name is not recognised.
- Throws:
- BuildException- if the task name is recognised but task creation fails.
 
- 
createDataTypeCreates a new instance of a data type.- Parameters:
- typeName- The name of the data type to create an instance of. Must not be- null.
- Returns:
- an instance of the specified data type, or nullif the data type name is not recognised.
- Throws:
- BuildException- if the data type name is recognised but instance creation fails.
 
- 
getElementNameReturns a description of the type of the given element.This is useful for logging purposes. - Parameters:
- element- The element to describe. Must not be- null.
- Returns:
- a description of the element type.
- Since:
- Ant 1.6
 
- 
getElementNameReturns a description of the type of the given element.This is useful for logging purposes. - Parameters:
- o- The element to describe. Must not be- null.
- brief- whether to use a brief description.
- Returns:
- a description of the element type.
- Since:
- Ant 1.7
 
- 
getElementNameConvenient way to get some element name even when you may not have a Project context.- Parameters:
- p- The optional Project instance.
- o- The element to describe. Must not be- null.
- brief- whether to use a brief description.
- Returns:
- a description of the element type.
- Since:
- Ant 1.7
 
- 
enterAntLibCalled at the start of processing an antlib.- Parameters:
- uri- the uri that is associated with this antlib.
 
- 
getCurrentAntlibUri- Returns:
- the current antlib uri.
 
- 
exitAntLibpublic void exitAntLib()Called at the end of processing an antlib.
- 
diagnoseCreationFailureHandler called to do decent diagnosis on instantiation failure.- Parameters:
- componentName- component name.
- type- component type, used in error messages
- Returns:
- a string containing as much diagnostics info as possible.
 
 
-