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 )
addDataTypeDefinition
public void addDataTypeDefinition(String typeName,
Class typeClass)
Adds 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.
typeName
- The name of the datatype.
Must not be null
.typeClass
- The full name of the class implementing the datatype.
Must not be null
.
addDataTypeDefinition
public void addDataTypeDefinition(AntTypeDefinition def)
Describe addDataTypeDefinition
method here.
def
- an AntTypeDefinition
value.
addTaskDefinition
public void addTaskDefinition(String taskName,
Class taskClass)
Adds 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 and
invalidates any tasks which have already been created with the
old definition.
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
.
checkTaskClass(Class)
checkTaskClass
public void checkTaskClass(Class taskClass)
throws BuildException
Checks 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.
taskClass
- The class to be checked.
Must not be null
.
BuildException
- if the class is unsuitable for being an Ant
task. An error level message is logged before
this exception is thrown.
createComponent
public Object createComponent(String componentName)
Create an object for a component.
componentName
- the name of the component, if
the component is in a namespace, the
name is prefixed with the namespace uri and ":".
- the class if found or null if not.
createComponent
public Object createComponent(UnknownElement ue,
String ns,
String componentType)
throws BuildException
Factory method to create the components.
This should be called by UnknownElement.
ue
- The Unknown Element creating this component.ns
- Namespace URI. Also available as ue.getNamespace().componentType
- The component type,
Also available as ue.getComponentName().
- the created component.
BuildException
- if an error occurs.
createDataType
public Object createDataType(String typeName)
throws BuildException
Creates a new instance of a data type.
typeName
- The name of the data type to create an instance of.
Must not be null
.
- an instance of the specified data type, or
null
if
the data type name is not recognised.
BuildException
- if the data type name is recognised but
instance creation fails.
createTask
public Task createTask(String taskType)
throws BuildException
Creates a new instance of a task, adding it to a list of
created tasks for later invalidation. This causes all tasks
to be remembered until the containing project is removed
Called from Project.createTask(), which can be called by tasks.
The method should be deprecated, as it doesn't support ns and libs.
taskType
- The name of the task to create an instance of.
Must not be null
.
- an instance of the specified task, or
null
if
the task name is not recognised.
BuildException
- if the task name is recognised but task
creation fails.
enterAntLib
public void enterAntLib(String uri)
Called at the start of processing an antlib.
uri
- the uri that is associated with this antlib.
exitAntLib
public void exitAntLib()
Called at the end of processing an antlib.
getAntTypeTable
public Hashtable getAntTypeTable()
Returns the current datatype definition hashtable. The returned
hashtable is "live" and so should not be modified.
- a map of from datatype name to implementing class
(String to Class).
getComponentClass
public Class getComponentClass(String componentName)
Return the class of the component name.
componentName
- the name of the component, if
the component is in a namespace, the
name is prefixed with the namespace uri and ":".
- the class if found or null if not.
getComponentHelper
public static ComponentHelper getComponentHelper(Project project)
Find a project component for a specific project, creating
it if it does not exist.
project
- the project.
- the project component for a specific project.
getCurrentAntlibUri
public String getCurrentAntlibUri()
- the current antlib uri.
getDataTypeDefinitions
public Hashtable getDataTypeDefinitions()
Returns the current type definition hashtable. The returned hashtable is
"live" and so should not be modified.
- a map of from type name to implementing class
(String to Class).
getDefinition
public AntTypeDefinition getDefinition(String componentName)
Return the antTypeDefinition for a componentName.
componentName
- the name of the component.
- the ant definition or null if not present.
getElementName
public String getElementName(Object element)
Returns a description of the type of the given element.
This is useful for logging purposes.
element
- The element to describe.
Must not be null
.
- a description of the element type.
- Ant 1.6
getNext
public ComponentHelper getNext()
Get the next chained component helper.
- the next chained component helper.
getTaskDefinitions
public Hashtable getTaskDefinitions()
Returns the current task definition hashtable. The returned hashtable is
"live" and so should not be modified.
- a map of from task name to implementing class
(String to Class).
initDefaultDefinitions
public 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.
initSubProject
public void initSubProject(ComponentHelper helper)
Used with creating child projects. Each child
project inherits the component definitions
from its parent.
helper
- the component helper of the parent project.
setNext
public void setNext(ComponentHelper next)
Set the next chained component helper.
next
- the next chained component helper.
setProject
public void setProject(Project project)
Sets the project for this component helper.
project
- the project for this helper.