git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273167 13f79535-47bb-0310-9956-ffa450edef68master
@@ -378,15 +378,15 @@ public abstract class AbstractFileSet extends DataType implements Cloneable, | |||
* referenced FileSet. | |||
*/ | |||
protected AbstractFileSet getRef(Project p) { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, p); | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = getRefid().getReferencedObject(p); | |||
if (!getClass().isAssignableFrom(o.getClass())) { | |||
String msg = ref.getRefId() + " doesn\'t denote a " | |||
String msg = getRefid().getRefId() + " doesn\'t denote a " | |||
+ getDataTypeName(); | |||
throw new BuildException(msg); | |||
} else { | |||
@@ -75,19 +75,32 @@ import org.apache.tools.ant.ProjectComponent; | |||
public abstract class DataType extends ProjectComponent { | |||
/** | |||
* The descriptin the user has set. | |||
* | |||
* @deprecated The user should not be directly referencing | |||
* variable. Please use {@link #setDescription} or | |||
* {@link #getDescription} instead. | |||
*/ | |||
protected String description; | |||
/** | |||
* Value to the refid attribute. | |||
* | |||
* @deprecated The user should not be directly referencing | |||
* variable. Please use {@link #getRefid} instead. | |||
*/ | |||
protected Reference ref; | |||
/** | |||
* Are we sure we don't hold circular references? | |||
* | |||
* <p>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).</p> | |||
* DataType).</p> | |||
* | |||
* @deprecated The user should not be directly referencing | |||
* variable. Please use {@link #setChecked} or | |||
* {@link #isChecked} instead. | |||
*/ | |||
protected boolean checked = true; | |||
@@ -95,7 +108,7 @@ public abstract class DataType extends ProjectComponent { | |||
* Sets a description of the current data type. It will be useful | |||
* in commenting what we are doing. | |||
*/ | |||
public void setDescription(String desc) { | |||
public void setDescription( final String desc ) { | |||
description = desc; | |||
} | |||
@@ -121,7 +134,7 @@ public abstract class DataType extends ProjectComponent { | |||
* thus override this method. if they do the must call | |||
* <code>super.setRefid</code>.</p> | |||
*/ | |||
public void setRefid(Reference ref) { | |||
public void setRefid( final Reference ref ) { | |||
this.ref = ref; | |||
checked = false; | |||
} | |||
@@ -142,21 +155,22 @@ public abstract class DataType extends ProjectComponent { | |||
* anything if {@link #checked <code>checked</code>} is true and | |||
* set it to true on exit.</p> | |||
*/ | |||
protected void dieOnCircularReference(Stack stk, Project p) | |||
protected void dieOnCircularReference( final Stack stack, | |||
final Project project ) | |||
throws BuildException { | |||
if (checked || !isReference()) { | |||
return; | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = ref.getReferencedObject(project); | |||
if (o instanceof DataType) { | |||
if (stk.contains(o)) { | |||
if (stack.contains(o)) { | |||
throw circularReference(); | |||
} else { | |||
stk.push(o); | |||
((DataType) o).dieOnCircularReference(stk, p); | |||
stk.pop(); | |||
stack.push(o); | |||
((DataType) o).dieOnCircularReference(stack, project); | |||
stack.pop(); | |||
} | |||
} | |||
checked = true; | |||
@@ -166,7 +180,8 @@ public abstract class DataType extends ProjectComponent { | |||
* Performs the check for circular references and returns the | |||
* referenced object. | |||
*/ | |||
protected Object getCheckedRef(Class requiredClass, String dataTypeName) { | |||
protected Object getCheckedRef( final Class requiredClass, | |||
final String dataTypeName ) { | |||
if (!checked) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
@@ -208,4 +223,17 @@ public abstract class DataType extends ProjectComponent { | |||
return new BuildException("This data type contains a circular " | |||
+ "reference."); | |||
} | |||
protected boolean isChecked() { | |||
return checked; | |||
} | |||
protected void setChecked( final boolean checked ) { | |||
this.checked = checked; | |||
} | |||
protected Reference getRefid() | |||
{ | |||
return ref; | |||
} | |||
} |
@@ -155,15 +155,15 @@ public class FileList extends DataType { | |||
* referenced FileList. | |||
*/ | |||
protected FileList getRef(Project p) { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, p); | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = getRefid().getReferencedObject(p); | |||
if (!(o instanceof FileList)) { | |||
String msg = ref.getRefId() + " doesn\'t denote a filelist"; | |||
String msg = getRefid().getRefId() + " doesn\'t denote a filelist"; | |||
throw new BuildException(msg); | |||
} else { | |||
return (FileList) o; | |||
@@ -225,15 +225,15 @@ public class Mapper extends DataType implements Cloneable { | |||
* referenced Mapper. | |||
*/ | |||
protected Mapper getRef() { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, getProject()); | |||
} | |||
Object o = ref.getReferencedObject(getProject()); | |||
Object o = getRefid().getReferencedObject(getProject()); | |||
if (!(o instanceof Mapper)) { | |||
String msg = ref.getRefId() + " doesn\'t denote a mapper"; | |||
String msg = getRefid().getRefId() + " doesn\'t denote a mapper"; | |||
throw new BuildException(msg); | |||
} else { | |||
return (Mapper) o; | |||
@@ -197,7 +197,7 @@ public class Path extends DataType implements Cloneable { | |||
throw noChildrenAllowed(); | |||
} | |||
elements.addElement(fs); | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -208,7 +208,7 @@ public class Path extends DataType implements Cloneable { | |||
throw noChildrenAllowed(); | |||
} | |||
elements.addElement(fl); | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -219,7 +219,7 @@ public class Path extends DataType implements Cloneable { | |||
throw noChildrenAllowed(); | |||
} | |||
elements.addElement(dset); | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -231,7 +231,7 @@ public class Path extends DataType implements Cloneable { | |||
} | |||
Path p = new Path(getProject()); | |||
elements.addElement(p); | |||
checked = false; | |||
setChecked( false ); | |||
return p; | |||
} | |||
@@ -280,7 +280,7 @@ public class Path extends DataType implements Cloneable { | |||
* @return list of path elements. | |||
*/ | |||
public String[] list() { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
// make sure we don't have a circular reference here | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
@@ -453,7 +453,7 @@ public class Path extends DataType implements Cloneable { | |||
protected void dieOnCircularReference(Stack stk, Project p) | |||
throws BuildException { | |||
if (checked) { | |||
if (isChecked()) { | |||
return; | |||
} | |||
@@ -474,7 +474,7 @@ public class Path extends DataType implements Cloneable { | |||
} | |||
} | |||
} | |||
checked = true; | |||
setChecked( true ); | |||
} | |||
/** | |||
@@ -396,15 +396,15 @@ public class PatternSet extends DataType { | |||
* referenced PatternSet. | |||
*/ | |||
private PatternSet getRef(Project p) { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, p); | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = getRefid().getReferencedObject(p); | |||
if (!(o instanceof PatternSet)) { | |||
String msg = ref.getRefId() + " doesn\'t denote a patternset"; | |||
String msg = getRefid().getRefId() + " doesn\'t denote a patternset"; | |||
throw new BuildException(msg); | |||
} else { | |||
return (PatternSet) o; | |||
@@ -137,16 +137,16 @@ public class RegularExpression extends DataType { | |||
* the given project. Check for circular references too | |||
*/ | |||
public RegularExpression getRef(Project p) { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, p); | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = getRefid().getReferencedObject(p); | |||
if (!(o instanceof RegularExpression)) { | |||
String msg = ref.getRefId() + " doesn\'t denote a " | |||
String msg = getRefid().getRefId() + " doesn\'t denote a " | |||
+ DATA_TYPE_NAME; | |||
throw new BuildException(msg); | |||
} else { | |||
@@ -101,16 +101,16 @@ public class Substitution extends DataType { | |||
* the given project. Check for circular references too | |||
*/ | |||
public Substitution getRef(Project p) { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, p); | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = getRefid().getReferencedObject(p); | |||
if (!(o instanceof Substitution)) { | |||
String msg = ref.getRefId() + " doesn\'t denote a substitution"; | |||
String msg = getRefid().getRefId() + " doesn\'t denote a substitution"; | |||
throw new BuildException(msg); | |||
} else { | |||
return (Substitution) o; | |||
@@ -157,7 +157,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
//-- Methods --------------------------------------------------------------- | |||
public XMLCatalog() { | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -203,7 +203,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
if (this.classpath == null) { | |||
this.classpath = new Path(getProject()); | |||
} | |||
checked = false; | |||
setChecked( false ); | |||
return this.classpath.createPath(); | |||
} | |||
@@ -222,7 +222,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
} else { | |||
this.classpath.append(classpath); | |||
} | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -236,7 +236,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
throw tooManyAttributes(); | |||
} | |||
createClasspath().setRefid(r); | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -256,7 +256,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
} | |||
getElements().addElement(dtd); | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -298,7 +298,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
// Append the classpath of the nested catalog | |||
Path nestedClasspath = catalog.getClasspath(); | |||
createClasspath().append(nestedClasspath); | |||
checked = false; | |||
setChecked( false ); | |||
} | |||
/** | |||
@@ -339,7 +339,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
public InputSource resolveEntity(String publicId, String systemId) | |||
throws SAXException, IOException { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
// make sure we don't have a circular reference here | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
@@ -367,7 +367,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver, U | |||
public Source resolve(String href, String base) | |||
throws TransformerException { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
// make sure we don't have a circular reference here | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
@@ -188,15 +188,15 @@ public class ZipFileSet extends FileSet { | |||
* standard directory scanner. | |||
*/ | |||
protected AbstractFileSet getRef(Project p) { | |||
if (!checked) { | |||
if (!isChecked()) { | |||
Stack stk = new Stack(); | |||
stk.push(this); | |||
dieOnCircularReference(stk, p); | |||
} | |||
Object o = ref.getReferencedObject(p); | |||
Object o = getRefid().getReferencedObject(p); | |||
if (!(o instanceof FileSet)) { | |||
String msg = ref.getRefId() + " doesn\'t denote a fileset"; | |||
String msg = getRefid().getRefId() + " doesn\'t denote a fileset"; | |||
throw new BuildException(msg); | |||
} else { | |||
return (AbstractFileSet) o; | |||