org.apache.tools.ant.types
abstract public class: DataType [javadoc |
source]
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.types.DataType
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Reverse, BZip2Resource, Size, Scale, ModifiedSelector, Text, PresentSelector, Name, CompressedResource, PropertyResource, ArchiveResource, LibFileSet, TarResource, FilterSet, BCFileSet, OrSelector, Or, PatternSet, None, SignedSelector, Resource, Description, RedirectorElement, FileSet, DependSelector, FilterChain, ZipResource, Date, FileResource, BaseSelectorContainer, ArchiveFileSet, Sort, ExtensionSet, ResourceComparator, SyncTarget, Exists, Mapper, AndSelector, DepthSelector, BaseResourceCollectionWrapper, Compare, FileSystem, ScriptSelector, NoneSelector, JavaResource, ExtendSelector, GZipResource, MyPath, ExtensionAdapter, ZipFileSet, XMLCatalog, AbstractSelectorContainer, BaseSelector, ConcatResource, SizeLimitCollection, Tokens, Rectangle, IsFileSelected, ImageOperation, ContainsRegexpSelector, NonExistent, Last, ContainsSelector, InvertedPatternSet, AntFilterReader, DirSet, SizeSelector, Arc, TypeSelector, NotSelector, Path, StringResource, Draw, URLResource, And, Union, Intersect, RegularExpression, Files, DelegatedResourceComparator, BaseResourceCollectionContainer, TarFileSet, BaseExtendSelector, FilenameSelector, MappingSelector, TarFileSet, Resources, Rotate, PropertySet, FilterMapper, First, ResourceSelectorContainer, Ellipse, AbstractFileSet, Majority, Restrict, MyFileSet, DifferentSelector, Type, Content, Difference, DateSelector, TagArgument, Assertions, MajoritySelector, TransformOperation, FileUnion, BasicShape, IsSigned, FileList, ClassfileSet, Substitution, SelectSelector
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>).
| Field Summary |
|---|
| protected Reference | ref | Value to the refid attribute. |
| protected boolean | checked | Are we sure we don't hold circular references?
Subclasses are responsible for setting this value to false
if we'd need to investigate this condition (usually because a
child element has been added that is a subclass of
DataType). |
| Method from org.apache.tools.ant.types.DataType Summary: |
|---|
|
checkAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, setChecked, setRefid, toString, tooManyAttributes |
| Method from org.apache.tools.ant.types.DataType Detail: |
protected void checkAttributesAllowed() {
if (isReference()) {
throw tooManyAttributes();
}
}
check that it is ok to set attributes, i.e that no reference is defined |
protected void checkChildrenAllowed() {
if (isReference()) {
throw noChildrenAllowed();
}
}
check that it is ok to add children, i.e that no reference is defined |
protected BuildException circularReference() {
return new BuildException("This data type contains a circular "
+ "reference.");
}
Creates an exception that indicates the user has generated a
loop of data types referencing each other. |
public Object clone() throws CloneNotSupportedException {
DataType dt = (DataType) super.clone();
dt.setDescription(getDescription());
if (getRefid() != null) {
dt.setRefid(getRefid());
}
dt.setChecked(isChecked());
return dt;
}
|
protected void dieOnCircularReference() {
dieOnCircularReference(getProject());
}
|
protected void dieOnCircularReference(Project p) {
if (checked || !isReference()) {
return;
}
dieOnCircularReference(new IdentityStack(this), p);
}
|
protected void dieOnCircularReference(Stack stack,
Project project) throws BuildException {
if (checked || !isReference()) {
return;
}
Object o = ref.getReferencedObject(project);
if (o instanceof DataType) {
IdentityStack id = IdentityStack.getInstance(stack);
if (id.contains(o)) {
throw circularReference();
} else {
id.push(o);
((DataType) o).dieOnCircularReference(id, project);
id.pop();
}
}
checked = true;
}
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. |
protected Object getCheckedRef() {
return getCheckedRef(getProject());
}
Performs the check for circular references and returns the
referenced object. |
protected Object getCheckedRef(Project p) {
return getCheckedRef(getClass(), getDataTypeName(), p);
}
Performs the check for circular references and returns the
referenced object. |
protected Object getCheckedRef(Class requiredClass,
String dataTypeName) {
return getCheckedRef(requiredClass, dataTypeName, getProject());
}
Performs the check for circular references and returns the
referenced object. |
protected Object getCheckedRef(Class requiredClass,
String dataTypeName,
Project project) {
if (project == null) {
throw new BuildException("No Project specified");
}
dieOnCircularReference(project);
Object o = ref.getReferencedObject(project);
if (!(requiredClass.isAssignableFrom(o.getClass()))) {
log("Class " + o.getClass() + " is not a subclass of " + requiredClass,
Project.MSG_VERBOSE);
String msg = ref.getRefId() + " doesn\'t denote a " + dataTypeName;
throw new BuildException(msg);
}
return o;
}
Performs the check for circular references and returns the
referenced object. This version allows the fallback Project instance to be specified. |
protected String getDataTypeName() {
return ComponentHelper.getElementName(getProject(), this, true);
}
Gets as descriptive as possible a name used for this datatype instance. |
public Reference getRefid() {
return ref;
}
get the reference set on this object |
public static void invokeCircularReferenceCheck(DataType dt,
Stack stk,
Project p) {
dt.dieOnCircularReference(stk, p);
}
Allow DataTypes outside org.apache.tools.ant.types to indirectly call
dieOnCircularReference on nested DataTypes. |
protected boolean isChecked() {
return checked;
}
The flag that is used to indicate that circular references have been checked. |
public boolean isReference() {
// CheckStyle:VisibilityModifier ON
return ref != null;
}
Has the refid attribute of this element been set? |
protected BuildException noChildrenAllowed() {
return new BuildException("You must not specify nested elements "
+ "when using refid");
}
Creates an exception that indicates that this XML element must
not have child elements if the refid attribute is set. |
protected void setChecked(boolean checked) {
this.checked = checked;
}
Set the flag that is used to indicate that circular references have been checked. |
public void setRefid(Reference ref) {
this.ref = ref;
checked = false;
}
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. |
public String toString() {
String d = getDescription();
return d == null ? getDataTypeName() : getDataTypeName() + " " + d;
}
Basic DataType toString(). |
protected BuildException tooManyAttributes() {
return new BuildException("You must not specify more than one "
+ "attribute when using refid");
}
Creates an exception that indicates that refid has to be the
only attribute if it is set. |