it.haefelinger.flaka
Class CompH

java.lang.Object
  extended by org.apache.tools.ant.ComponentHelper
      extended by it.haefelinger.flaka.CompH

public class CompH
extends ComponentHelper

This whole class just exists to get rid of some anoying warnings * issued by Ant. Here's an example situation: * * Executing this command would issue a warning like * * Overriding previous definition of type javac Unfortunatly there is no easy way to remove such warnings. Looking * how this is implemented, it appears that method * * ComponentHelper.updateDataTypeDefinition() is the guilty part. It is rather easy to exchange this faulty * ComponentHelper instance by a customized on. All that needs to be * done is to save a reference to a customized instance via property * name "ant.ComponentHelper". Unfortunatly our faulty method is made * private. So how can we change the behaviour? This is how it's done: * * 1. Make a new class using ComponentHelper as base class. * 2. The new class contains a pointer to the original instance (dlgt) * 3. Delegate all public methods to dlgt except those public methods * (indirectly) call our faulty method. * 4. Implement our faulty method again without issuing a warning. * 5. Implement non-delegation public methods in such a way that they * are using my improved method. * * Steps 4. and 5. are problematic of course and are using Java's * reflection API to access private methods and fields. While this * works with Ant 1.6.3 - 1.6.5 it may not work with newer versions * of Ant. * * There are other approaches to solve the problem: * a.) override the setProject() method and wrap the project's instance * with a wrapper overriding Project.log(). Since there's no * factory methods for Projects a delegation technique similar to * the one used in this class needs to be applied. * b.) what was the other approach again?? * * *

Since:
1.0
Author:
merzedes

Field Summary
protected static boolean applicable
           
protected  ComponentHelper dlgt
           
protected static Method invalidateCreatedTasks
           
protected static Field project
           
protected static Field rebuildTaskClassDefinitions
           
protected static Field rebuildTypeClassDefinitions
           
protected static Method sameDefinition
           
 
Fields inherited from class org.apache.tools.ant.ComponentHelper
COMPONENT_HELPER_REFERENCE
 
Constructor Summary
CompH()
           
 
Method Summary
 void addDataTypeDefinition(AntTypeDefinition def)
          Describe addDataTypeDefinition method here.
 void addDataTypeDefinition(String typeName, Class typeClass)
          Adds a new datatype definition.
 void addTaskDefinition(String taskName, Class taskClass)
          Adds a new task definition to the project.
 void checkTaskClass(Class taskClass)
          Checks whether or not a class is suitable for serving as Ant task.
 Object createComponent(String componentName)
          Create an object for a component.
 Object createComponent(UnknownElement ue, String ns, String componentType)
          Factory method to create the components.
 Object createDataType(String typeName)
          Creates a new instance of a data type.
 Task createTask(String taskType)
          Creates a new instance of a task, adding it to a list of created tasks for later invalidation.
 void enterAntLib(String uri)
          Called at the start of processing an antlib.
 void exitAntLib()
          Called at the end of processing an antlib.
 Hashtable getAntTypeTable()
          Returns the current datatype definition hashtable.
protected  Object getattr(Field field)
           
 Class getComponentClass(String componentName)
          Return the class of the component name.
 String getCurrentAntlibUri()
           
 Hashtable getDataTypeDefinitions()
          Returns the current type definition hashtable.
 AntTypeDefinition getDefinition(String componentName)
          Return the antTypeDefinition for a componentName.
 String getElementName(Object element)
          Returns a description of the type of the given element.
 ComponentHelper getNext()
          Get the next chained component helper.
 Hashtable getTaskDefinitions()
          Returns the current task definition hashtable.
 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.
 void initSubProject(ComponentHelper helper)
          Used with creating child projects.
static boolean install(Project P)
          Installs this ComponentHandler in project given.
protected  Object invoke(Method method, Object[] args)
           
static boolean isapplicable()
          Checks whether it is possible to use this Class as replacement * for class ComponentHelper.
protected  boolean sameDefinition(AntTypeDefinition def, AntTypeDefinition old)
           
protected  void setattr(Field field, Object val)
           
 void setNext(ComponentHelper next)
          Set the next chained component helper.
 void setProject(Project project)
          Sets the project for this component helper.
static boolean uninstall(Project P)
          Checks whether current component handler is instance of this * particular class (or a subclass).
 
Methods inherited from class org.apache.tools.ant.ComponentHelper
diagnoseCreationFailure, getComponentHelper, getElementName, getElementName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

project

protected static Field project

rebuildTaskClassDefinitions

protected static Field rebuildTaskClassDefinitions

rebuildTypeClassDefinitions

protected static Field rebuildTypeClassDefinitions

invalidateCreatedTasks

protected static Method invalidateCreatedTasks

sameDefinition

protected static Method sameDefinition

applicable

protected static boolean applicable

dlgt

protected ComponentHelper dlgt
Constructor Detail

CompH

public CompH()
Method Detail

setNext

public void setNext(ComponentHelper next)
Set the next chained component helper.

Overrides:
setNext in class ComponentHelper
Parameters:
next - the next chained component helper.

getNext

public ComponentHelper getNext()
Get the next chained component helper.

Overrides:
getNext in class ComponentHelper
Returns:
the next chained component helper.

setProject

public void setProject(Project project)
Sets the project for this component helper.

Overrides:
setProject in class ComponentHelper
Parameters:
project - the project for this helper.

initSubProject

public void initSubProject(ComponentHelper helper)
Used with creating child projects. Each child project inherits the component definitions from its parent.

Overrides:
initSubProject in class ComponentHelper
Parameters:
helper - the component helper of the parent project.

createComponent

public Object createComponent(UnknownElement ue,
                              String ns,
                              String componentType)
                       throws BuildException
Factory method to create the components. This should be called by UnknownElement.

Overrides:
createComponent in class ComponentHelper
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.

createComponent

public Object createComponent(String componentName)
Create an object for a component.

Overrides:
createComponent in class ComponentHelper
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.

getComponentClass

public Class getComponentClass(String componentName)
Return the class of the component name.

Overrides:
getComponentClass in class ComponentHelper
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.

getDefinition

public AntTypeDefinition getDefinition(String componentName)
Return the antTypeDefinition for a componentName.

Overrides:
getDefinition in class ComponentHelper
Parameters:
componentName - the name of the component.
Returns:
the ant definition or null if not present.

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.

Overrides:
initDefaultDefinitions in class ComponentHelper

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.

Overrides:
checkTaskClass in class ComponentHelper
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.

getTaskDefinitions

public Hashtable getTaskDefinitions()
Returns the current task definition hashtable. The returned hashtable is "live" and so should not be modified.

Overrides:
getTaskDefinitions in class ComponentHelper
Returns:
a map of from task name to implementing class (String to Class).

getDataTypeDefinitions

public Hashtable getDataTypeDefinitions()
Returns the current type definition hashtable. The returned hashtable is "live" and so should not be modified.

Overrides:
getDataTypeDefinitions in class ComponentHelper
Returns:
a map of from type name to implementing class (String to Class).

getAntTypeTable

public Hashtable getAntTypeTable()
Returns the current datatype definition hashtable. The returned hashtable is "live" and so should not be modified.

Overrides:
getAntTypeTable in class ComponentHelper
Returns:
a map of from datatype name to implementing class (String to Class).

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.

Overrides:
createTask in class ComponentHelper
Parameters:
taskType - The name of the task to create an instance of. Must not be null.
Returns:
an instance of the specified task, or null if the task name is not recognised.
Throws:
BuildException - if the task name is recognised but task creation fails.

createDataType

public Object createDataType(String typeName)
                      throws BuildException
Creates a new instance of a data type.

Overrides:
createDataType in class ComponentHelper
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 null if the data type name is not recognised.
Throws:
BuildException - if the data type name is recognised but instance creation fails.

getElementName

public String getElementName(Object element)
Returns a description of the type of the given element.

This is useful for logging purposes.

Overrides:
getElementName in class ComponentHelper
Parameters:
element - The element to describe. Must not be null.
Returns:
a description of the element type.
Since:
Ant 1.6

enterAntLib

public void enterAntLib(String uri)
Called at the start of processing an antlib.

Overrides:
enterAntLib in class ComponentHelper
Parameters:
uri - the uri that is associated with this antlib.

getCurrentAntlibUri

public String getCurrentAntlibUri()
Overrides:
getCurrentAntlibUri in class ComponentHelper
Returns:
the current antlib uri.

exitAntLib

public void exitAntLib()
Called at the end of processing an antlib.

Overrides:
exitAntLib in class ComponentHelper

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.

Overrides:
addDataTypeDefinition in class ComponentHelper
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.

addDataTypeDefinition

public void addDataTypeDefinition(AntTypeDefinition def)
Describe addDataTypeDefinition method here.

Overrides:
addDataTypeDefinition in class ComponentHelper
Parameters:
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.

Overrides:
addTaskDefinition in class ComponentHelper
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:
checkTaskClass(Class)

sameDefinition

protected boolean sameDefinition(AntTypeDefinition def,
                                 AntTypeDefinition old)

invoke

protected Object invoke(Method method,
                        Object[] args)

getattr

protected Object getattr(Field field)

setattr

protected void setattr(Field field,
                       Object val)

isapplicable

public static boolean isapplicable()
Checks whether it is possible to use this Class as replacement * for class ComponentHelper. Using this class may not be possible * if at least one of the private methods and attributes are not * any longer available. * *

Returns:
true if it's safe to use this class as replacement for * class ComponentHelper.

install

public static boolean install(Project P)
Installs this ComponentHandler in project given. * *

Parameters:
P - not null * *
Returns:
true if this ComponentHandler could be installed in * given project.

uninstall

public static boolean uninstall(Project P)
Checks whether current component handler is instance of this * particular class (or a subclass). If so, the current component * handler is replaced by it's successor (retrieved via method * getNext()). If current component handler is not a instance of * this class then method returns false and true otherwise. * *

Parameters:
P - not null * *
Returns:
true if this ComponentHandler could be uninstalled in * given project.