From de93400d04ba220ab724125f4e869e3daa37f1d4 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Thu, 25 Jul 2002 14:59:02 +0000 Subject: [PATCH] Encapsulate some fields of DataType. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273167 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/types/AbstractFileSet.java | 6 +-- .../org/apache/tools/ant/types/DataType.java | 48 +++++++++++++++---- .../org/apache/tools/ant/types/FileList.java | 6 +-- .../org/apache/tools/ant/types/Mapper.java | 6 +-- src/main/org/apache/tools/ant/types/Path.java | 14 +++--- .../apache/tools/ant/types/PatternSet.java | 6 +-- .../tools/ant/types/RegularExpression.java | 6 +-- .../apache/tools/ant/types/Substitution.java | 6 +-- .../apache/tools/ant/types/XMLCatalog.java | 16 +++---- .../apache/tools/ant/types/ZipFileSet.java | 6 +-- 10 files changed, 74 insertions(+), 46 deletions(-) diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java index c3917c2de..b42de15f8 100644 --- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java +++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java @@ -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 { diff --git a/src/main/org/apache/tools/ant/types/DataType.java b/src/main/org/apache/tools/ant/types/DataType.java index b9804f758..9a0316def 100644 --- a/src/main/org/apache/tools/ant/types/DataType.java +++ b/src/main/org/apache/tools/ant/types/DataType.java @@ -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? * *

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).

+ * DataType).

+ * + * @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 * super.setRefid.

*/ - 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 checked} is true and * set it to true on exit.

*/ - 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; + } } diff --git a/src/main/org/apache/tools/ant/types/FileList.java b/src/main/org/apache/tools/ant/types/FileList.java index e9cd27a57..a79508a88 100644 --- a/src/main/org/apache/tools/ant/types/FileList.java +++ b/src/main/org/apache/tools/ant/types/FileList.java @@ -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; diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java index 70afa1dd8..de1c9e91a 100644 --- a/src/main/org/apache/tools/ant/types/Mapper.java +++ b/src/main/org/apache/tools/ant/types/Mapper.java @@ -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; diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index 3d528d263..b552d4ccd 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -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 ); } /** diff --git a/src/main/org/apache/tools/ant/types/PatternSet.java b/src/main/org/apache/tools/ant/types/PatternSet.java index e223aeef9..80c3a938d 100644 --- a/src/main/org/apache/tools/ant/types/PatternSet.java +++ b/src/main/org/apache/tools/ant/types/PatternSet.java @@ -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; diff --git a/src/main/org/apache/tools/ant/types/RegularExpression.java b/src/main/org/apache/tools/ant/types/RegularExpression.java index 377ab4525..b07b79488 100644 --- a/src/main/org/apache/tools/ant/types/RegularExpression.java +++ b/src/main/org/apache/tools/ant/types/RegularExpression.java @@ -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 { diff --git a/src/main/org/apache/tools/ant/types/Substitution.java b/src/main/org/apache/tools/ant/types/Substitution.java index b1f64ba3d..9d7f53ee3 100644 --- a/src/main/org/apache/tools/ant/types/Substitution.java +++ b/src/main/org/apache/tools/ant/types/Substitution.java @@ -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; diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java index 60ebace5e..37e6fe83f 100644 --- a/src/main/org/apache/tools/ant/types/XMLCatalog.java +++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java @@ -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); diff --git a/src/main/org/apache/tools/ant/types/ZipFileSet.java b/src/main/org/apache/tools/ant/types/ZipFileSet.java index dfb4ad290..1079a999f 100644 --- a/src/main/org/apache/tools/ant/types/ZipFileSet.java +++ b/src/main/org/apache/tools/ant/types/ZipFileSet.java @@ -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;