Methods Summary |
---|
public void | checkClass(Project project)Checks if the attributes are correct.
if the class can be created.
if an adapter class can be created
if the type is assignable from adapto
if the type can be used with the adapter class
if (clazz == null) {
clazz = getTypeClass(project);
if (clazz == null) {
throw new BuildException(
"Unable to create class for " + getName());
}
}
// check adapter
if (adapterClass != null && (adaptToClass == null
|| !adaptToClass.isAssignableFrom(clazz))) {
TypeAdapter adapter = (TypeAdapter) createAndSet(
project, adapterClass);
if (adapter == null) {
throw new BuildException("Unable to create adapter object");
}
adapter.checkProxyClass(clazz);
}
|
public java.lang.Object | create(Project project)Create an instance of the definition.
The instance may be wrapped in a proxy class.
return icreate(project);
|
private java.lang.Object | createAndSet(Project project, java.lang.Class c)Get the constructor of the definition
and invoke it.
try {
Object o = innerCreateAndSet(c, project);
return o;
} catch (InvocationTargetException ex) {
Throwable t = ex.getTargetException();
throw new BuildException(
"Could not create type " + name + " due to " + t, t);
} catch (NoClassDefFoundError ncdfe) {
String msg = "Type " + name + ": A class needed by class "
+ c + " cannot be found: " + ncdfe.getMessage();
throw new BuildException(msg, ncdfe);
} catch (NoSuchMethodException nsme) {
throw new BuildException("Could not create type " + name
+ " as the class " + c + " has no compatible constructor");
} catch (InstantiationException nsme) {
throw new BuildException("Could not create type "
+ name + " as the class " + c + " is abstract");
} catch (IllegalAccessException e) {
throw new BuildException("Could not create type "
+ name + " as the constructor " + c + " is not accessible");
} catch (Throwable t) {
throw new BuildException(
"Could not create type " + name + " due to " + t, t);
}
|
private java.lang.String | extractClassname(java.lang.Class c)
return (c == null) ? "<null>" : c.getClass().getName();
|
public java.lang.ClassLoader | getClassLoader()Get the classloader for this definition.
return classLoader;
|
public java.lang.String | getClassName()Get the classname of the definition.
return className;
|
public java.lang.Class | getExposedClass(Project project)Get the exposed class for this
definition. This will be a proxy class
(adapted class) if there is an adapter
class and the definition class is not
assignable from the assignable class.
if (adaptToClass != null) {
Class z = getTypeClass(project);
if (z == null || adaptToClass.isAssignableFrom(z)) {
return z;
}
}
return (adapterClass == null) ? getTypeClass(project) : adapterClass;
|
public java.lang.String | getName()Return the definition's name.
return name;
|
public java.lang.Class | getTypeClass(Project project)Get the definition class.
try {
return innerGetTypeClass();
} catch (NoClassDefFoundError ncdfe) {
project.log("Could not load a dependent class ("
+ ncdfe.getMessage() + ") for type "
+ name, Project.MSG_DEBUG);
} catch (ClassNotFoundException cnfe) {
project.log("Could not load class (" + className
+ ") for type " + name, Project.MSG_DEBUG);
}
return null;
|
private java.lang.Object | icreate(Project project)Create a component object based on
its definition.
Class c = getTypeClass(project);
if (c == null) {
return null;
}
Object o = createAndSet(project, c);
if (o == null || adapterClass == null) {
return o;
}
if (adaptToClass != null) {
if (adaptToClass.isAssignableFrom(o.getClass())) {
return o;
}
}
TypeAdapter adapterObject = (TypeAdapter) createAndSet(
project, adapterClass);
if (adapterObject == null) {
return null;
}
adapterObject.setProxy(o);
return adapterObject;
|
public java.lang.Object | innerCreateAndSet(java.lang.Class newclass, Project project)Inner implementation of the {@link #createAndSet(Project, Class)} logic, with no
exception catching
Constructor ctor = null;
boolean noArg = false;
// DataType can have a "no arg" constructor or take a single
// Project argument.
try {
ctor = newclass.getConstructor(new Class[0]);
noArg = true;
} catch (NoSuchMethodException nse) {
//can throw the same exception, if there is no this(Project) ctor.
ctor = newclass.getConstructor(new Class[] {Project.class});
noArg = false;
}
//now we instantiate
Object o = ctor.newInstance(
((noArg) ? new Object[0] : new Object[] {project}));
//set up project references.
project.setProjectReference(o);
return o;
|
public java.lang.Class | innerGetTypeClass()Try and load a class, with no attempt to catch any fault.
if (clazz != null) {
return clazz;
}
if (classLoader == null) {
clazz = Class.forName(className);
} else {
clazz = classLoader.loadClass(className);
}
return clazz;
|
public boolean | sameDefinition(org.apache.tools.ant.AntTypeDefinition other, Project project)Equality method for this definition (assumes the names are the same).
return (other != null && other.getClass() == getClass()
&& other.getTypeClass(project).equals(getTypeClass(project))
&& other.getExposedClass(project).equals(getExposedClass(project))
&& other.adapterClass == adapterClass
&& other.adaptToClass == adaptToClass);
|
public void | setAdaptToClass(java.lang.Class adaptToClass)Set the assignable class for this definition.
this.adaptToClass = adaptToClass;
|
public void | setAdapterClass(java.lang.Class adapterClass)Set the adapter class for this definition.
This class is used to adapt the definitions class if
required.
this.adapterClass = adapterClass;
|
public void | setClass(java.lang.Class clazz)Set the class of the definition.
As a side-effect may set the classloader and classname.
this.clazz = clazz;
if (clazz == null) {
return;
}
this.classLoader = (classLoader == null)
? clazz.getClassLoader() : classLoader;
this.className = (className == null) ? clazz.getName() : className;
|
public void | setClassLoader(java.lang.ClassLoader classLoader)Set the classloader to use to create an instance
of the definition.
this.classLoader = classLoader;
|
public void | setClassName(java.lang.String className)Set the classname of the definition.
this.className = className;
|
public void | setName(java.lang.String name)Set the definition's name.
this.name = name;
|
public boolean | similarDefinition(org.apache.tools.ant.AntTypeDefinition other, Project project)Similar definition;
used to compare two definitions defined twice with the same
name and the same types.
The classloader may be different but have the same
path so #sameDefinition cannot
be used.
if (other == null
|| getClass() != other.getClass()
|| !getClassName().equals(other.getClassName())
|| !extractClassname(adapterClass).equals(
extractClassname(other.adapterClass))
|| !extractClassname(adaptToClass).equals(
extractClassname(other.adaptToClass))) {
return false;
}
// all the names are the same: check if the class path of the loader
// is the same
ClassLoader oldLoader = other.getClassLoader();
ClassLoader newLoader = getClassLoader();
return oldLoader == newLoader
|| (oldLoader instanceof AntClassLoader
&& newLoader instanceof AntClassLoader
&& ((AntClassLoader) oldLoader).getClasspath()
.equals(((AntClassLoader) newLoader).getClasspath()));
|