Base class for those classes that can appear inside the build file
as stand alone data types.
This class handles the common description attribute and provides
a default implementation for reference handling and checking for
circular references that is appropriate for types that can not be
nested inside elements of the same type (i.e. <patternset>
but not <path>).
checkAttributesAllowed
protected void checkAttributesAllowed()
check that it is ok to set attributes, i.e that no reference is defined
checkChildrenAllowed
protected void checkChildrenAllowed()
check that it is ok to add children, i.e that no reference is defined
circularReference
protected BuildException circularReference()
Creates an exception that indicates the user has generated a
loop of data types referencing each other.
clone
public Object clone()
throws CloneNotSupportedException
- clone in interface ProjectComponent
- a shallow copy of this DataType.
dieOnCircularReference
protected void dieOnCircularReference()
Convenience method.
dieOnCircularReference
protected void dieOnCircularReference(Stack stack,
Project project)
throws BuildException
Check to see whether any DataType we hold references to is
included in the Stack (which holds all DataType instances that
directly or indirectly reference this instance, including this
instance itself).
If one is included, throw a BuildException created by
circularReference
.
This implementation is appropriate only for a DataType that
cannot hold other DataTypes as children.
The general contract of this method is that it shouldn't do
anything if
checked
is true and
set it to true on exit.
stack
- the stack of references to check.project
- the project to use to dereference the references.
dieOnCircularReference
protected void dieOnCircularReference(Project p)
Convenience method.
p
- the Ant Project instance against which to resolve references.
getCheckedRef
protected Object getCheckedRef()
Performs the check for circular references and returns the
referenced object.
getCheckedRef
protected Object getCheckedRef(Class requiredClass,
String dataTypeName)
Performs the check for circular references and returns the
referenced object.
requiredClass
- the class that this reference should be a subclass of.dataTypeName
- the name of the datatype that the reference should be
(error message use only).
getCheckedRef
protected Object getCheckedRef(Class requiredClass,
String dataTypeName,
Project project)
Performs the check for circular references and returns the
referenced object. This version allows the fallback Project instance to be specified.
requiredClass
- the class that this reference should be a subclass of.dataTypeName
- the name of the datatype that the reference should be
(error message use only).project
- the fallback Project instance for dereferencing.
getCheckedRef
protected Object getCheckedRef(Project p)
Performs the check for circular references and returns the
referenced object.
p
- the Ant Project instance against which to resolve references.
getDataTypeName
protected String getDataTypeName()
Gets as descriptive as possible a name used for this datatype instance.
getRefid
public Reference getRefid()
get the reference set on this object
invokeCircularReferenceCheck
public static void invokeCircularReferenceCheck(DataType dt,
Stack stk,
Project p)
Allow DataTypes outside org.apache.tools.ant.types to indirectly call
dieOnCircularReference on nested DataTypes.
dt
- the DataType to check.stk
- the stack of references to check.p
- the project to use to dereference the references.
isChecked
protected boolean isChecked()
The flag that is used to indicate that circular references have been checked.
- true if circular references have been checked
isReference
public boolean isReference()
Has the refid attribute of this element been set?
- true if the refid attribute has been set
noChildrenAllowed
protected BuildException noChildrenAllowed()
Creates an exception that indicates that this XML element must
not have child elements if the refid attribute is set.
setChecked
protected void setChecked(boolean checked)
Set the flag that is used to indicate that circular references have been checked.
checked
- if true, if circular references have been checked
setRefid
public void setRefid(Reference ref)
Set the value of the refid attribute.
Subclasses may need to check whether any other attributes
have been set as well or child elements have been created and
thus override this method. if they do the must call
super.setRefid
.
ref
- the reference to use
toString
public String toString()
Basic DataType toString().
- this DataType formatted as a String.
tooManyAttributes
protected BuildException tooManyAttributes()
Creates an exception that indicates that refid has to be the
only attribute if it is set.