Browse Source

use DataType's (new) convenience methods

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278333 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
37e97ef42d
6 changed files with 46 additions and 124 deletions
  1. +1
    -13
      src/main/org/apache/tools/ant/types/Mapper.java
  2. +1
    -13
      src/main/org/apache/tools/ant/types/PatternSet.java
  3. +40
    -57
      src/main/org/apache/tools/ant/types/RedirectorElement.java
  4. +1
    -15
      src/main/org/apache/tools/ant/types/RegularExpression.java
  5. +1
    -14
      src/main/org/apache/tools/ant/types/Substitution.java
  6. +2
    -12
      src/main/org/apache/tools/ant/types/XMLCatalog.java

+ 1
- 13
src/main/org/apache/tools/ant/types/Mapper.java View File

@@ -247,19 +247,7 @@ public class Mapper extends DataType implements Cloneable {
* @return the referenced Mapper * @return the referenced Mapper
*/ */
protected Mapper getRef() { protected Mapper getRef() {
if (!isChecked()) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, getProject());
}

Object o = getRefid().getReferencedObject(getProject());
if (!(o instanceof Mapper)) {
String msg = getRefid().getRefId() + " doesn\'t denote a mapper";
throw new BuildException(msg);
} else {
return (Mapper) o;
}
return (Mapper) getCheckedRef();
} }


/** /**


+ 1
- 13
src/main/org/apache/tools/ant/types/PatternSet.java View File

@@ -414,19 +414,7 @@ public class PatternSet extends DataType implements Cloneable {
* referenced PatternSet. * referenced PatternSet.
*/ */
private PatternSet getRef(Project p) { private PatternSet getRef(Project p) {
if (!isChecked()) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, p);
}

Object o = getRefid().getReferencedObject(p);
if (!(o instanceof PatternSet)) {
String msg = getRefid().getRefId() + " doesn\'t denote a patternset";
throw new BuildException(msg);
} else {
return (PatternSet) o;
}
return (PatternSet) getCheckedRef(p);
} }


/** /**


+ 40
- 57
src/main/org/apache/tools/ant/types/RedirectorElement.java View File

@@ -27,22 +27,23 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Redirector; import org.apache.tools.ant.taskdefs.Redirector;


/** /**
* Element representation of a <CODE>Redirector</CODE>.
* Element representation of a <code>Redirector</code>.
* @since Ant 1.6.2
*/ */
public class RedirectorElement extends DataType { public class RedirectorElement extends DataType {


/** /**
* Whether the input mapper was set via <CODE>setOutput</CODE>.
* Whether the input mapper was set via <code>setOutput</code>.
*/ */
private boolean usingInput = false; private boolean usingInput = false;


/** /**
* Whether the output mapper was set via <CODE>setOutput</CODE>.
* Whether the output mapper was set via <code>setOutput</code>.
*/ */
private boolean usingOutput = false; private boolean usingOutput = false;


/** /**
* Whether the error mapper was set via <CODE>setError</CODE>.
* Whether the error mapper was set via <code>setError</code>.
*/ */
private boolean usingError = false; private boolean usingError = false;


@@ -103,7 +104,7 @@ public class RedirectorElement extends DataType {


/** /**
* Add the input file mapper. * Add the input file mapper.
* @param inputMapper <CODE>Mapper</CODE>.
* @param inputMapper <code>Mapper</code>.
*/ */
public void addConfiguredInputMapper(Mapper inputMapper) { public void addConfiguredInputMapper(Mapper inputMapper) {
if (isReference()) { if (isReference()) {
@@ -122,7 +123,7 @@ public class RedirectorElement extends DataType {


/** /**
* Add the output file mapper. * Add the output file mapper.
* @param outputMapper <CODE>Mapper</CODE>.
* @param outputMapper <code>Mapper</code>.
*/ */
public void addConfiguredOutputMapper(Mapper outputMapper) { public void addConfiguredOutputMapper(Mapper outputMapper) {
if (isReference()) { if (isReference()) {
@@ -141,7 +142,7 @@ public class RedirectorElement extends DataType {


/** /**
* Add the error file mapper. * Add the error file mapper.
* @param errorMapper <CODE>Mapper</CODE>.
* @param errorMapper <code>Mapper</code>.
*/ */
public void addConfiguredErrorMapper(Mapper errorMapper) { public void addConfiguredErrorMapper(Mapper errorMapper) {
if (isReference()) { if (isReference()) {
@@ -159,12 +160,12 @@ public class RedirectorElement extends DataType {
} }


/** /**
* Makes this instance in effect a reference to another instance.
* Make this instance in effect a reference to another instance.
* *
* <p>You must not set another attribute or nest elements inside * <p>You must not set another attribute or nest elements inside
* this element if you make it a reference.</p> * this element if you make it a reference.</p>
* @param r the reference to use
* @throws BuildException on error
* @param r the reference to use.
* @throws BuildException on error.
*/ */
public void setRefid(Reference r) throws BuildException { public void setRefid(Reference r) throws BuildException {
if (usingInput if (usingInput
@@ -178,14 +179,15 @@ public class RedirectorElement extends DataType {
|| outputEncoding != null || outputEncoding != null
|| errorEncoding != null || errorEncoding != null
|| outputProperty != null || outputProperty != null
|| errorProperty != null) {
|| errorProperty != null
|| logInputString != null) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
super.setRefid(r); super.setRefid(r);
} }


/** /**
* Set the input to use for the task
* Set the input to use for the task.
* @param input the file from which input is read. * @param input the file from which input is read.
*/ */
public void setInput(File input) { public void setInput(File input) {
@@ -230,9 +232,9 @@ public class RedirectorElement extends DataType {


/** /**
* File the output of the process is redirected to. If error is not * File the output of the process is redirected to. If error is not
* redirected, it too will appear in the output
* redirected, it too will appear in the output.
* *
* @param out the file to which output stream is written
* @param out the file to which output stream is written.
*/ */
public void setOutput(File out) { public void setOutput(File out) {
if (isReference()) { if (isReference()) {
@@ -247,7 +249,7 @@ public class RedirectorElement extends DataType {


/** /**
* Set the output encoding. * Set the output encoding.
* @param outputEncoding <CODE>String</CODE>.
* @param outputEncoding <code>String</code>.
*/ */
public void setOutputEncoding(String outputEncoding) { public void setOutputEncoding(String outputEncoding) {
if (isReference()) { if (isReference()) {
@@ -259,7 +261,7 @@ public class RedirectorElement extends DataType {
/** /**
* Set the error encoding. * Set the error encoding.
* *
* @param errorEncoding <CODE>String</CODE>.
* @param errorEncoding <code>String</code>.
*/ */
public void setErrorEncoding(String errorEncoding) { public void setErrorEncoding(String errorEncoding) {
if (isReference()) { if (isReference()) {
@@ -270,7 +272,7 @@ public class RedirectorElement extends DataType {


/** /**
* Set the input encoding. * Set the input encoding.
* @param inputEncoding <CODE>String</CODE>.
* @param inputEncoding <code>String</code>.
*/ */
public void setInputEncoding(String inputEncoding) { public void setInputEncoding(String inputEncoding) {
if (isReference()) { if (isReference()) {
@@ -282,7 +284,7 @@ public class RedirectorElement extends DataType {
/** /**
* Controls whether error output of exec is logged. This is only useful * Controls whether error output of exec is logged. This is only useful
* when output is being redirected and error output is desired in the * when output is being redirected and error output is desired in the
* Ant log
* Ant log.
* @param logError if true the standard error is sent to the Ant log system * @param logError if true the standard error is sent to the Ant log system
* and not sent to output. * and not sent to output.
*/ */
@@ -295,7 +297,7 @@ public class RedirectorElement extends DataType {


/** /**
* Set the file to which standard error is to be redirected. * Set the file to which standard error is to be redirected.
* @param error the file to which error is to be written
* @param error the file to which error is to be written.
*/ */
public void setError(File error) { public void setError(File error) {
if (isReference()) { if (isReference()) {
@@ -351,7 +353,7 @@ public class RedirectorElement extends DataType {
/** /**
* Whether output and error files should be created even when empty. * Whether output and error files should be created even when empty.
* Defaults to true. * Defaults to true.
* @param createEmptyFiles <CODE>boolean</CODE>.
* @param createEmptyFiles <code>boolean</code>.
*/ */
public void setCreateEmptyFiles(boolean createEmptyFiles) { public void setCreateEmptyFiles(boolean createEmptyFiles) {
if (isReference()) { if (isReference()) {
@@ -375,8 +377,8 @@ public class RedirectorElement extends DataType {
} }


/** /**
* Create a nested input <CODE>FilterChain</CODE>.
* @return <CODE>FilterChain</CODE>.
* Create a nested input <code>FilterChain</code>.
* @return <code>FilterChain</code>.
*/ */
public FilterChain createInputFilterChain() { public FilterChain createInputFilterChain() {
if (isReference()) { if (isReference()) {
@@ -389,8 +391,8 @@ public class RedirectorElement extends DataType {
} }


/** /**
* Create a nested output <CODE>FilterChain</CODE>.
* @return <CODE>FilterChain</CODE>.
* Create a nested output <code>FilterChain</code>.
* @return <code>FilterChain</code>.
*/ */
public FilterChain createOutputFilterChain() { public FilterChain createOutputFilterChain() {
if (isReference()) { if (isReference()) {
@@ -403,8 +405,8 @@ public class RedirectorElement extends DataType {
} }


/** /**
* Create a nested error <CODE>FilterChain</CODE>.
* @return <CODE>FilterChain</CODE>.
* Create a nested error <code>FilterChain</code>.
* @return <code>FilterChain</code>.
*/ */
public FilterChain createErrorFilterChain() { public FilterChain createErrorFilterChain() {
if (isReference()) { if (isReference()) {
@@ -417,18 +419,18 @@ public class RedirectorElement extends DataType {
} }


/** /**
* Configure the specified <CODE>Redirector</CODE>.
* @param redirector <CODE>Redirector</CODE>.
* Configure the specified <code>Redirector</code>.
* @param redirector <code>Redirector</code>.
*/ */
public void configure(Redirector redirector) { public void configure(Redirector redirector) {
configure(redirector, null); configure(redirector, null);
} }


/** /**
* Configure the specified <CODE>Redirector</CODE>
* Configure the specified <code>Redirector</code>
* for the specified sourcefile. * for the specified sourcefile.
* @param redirector <CODE>Redirector</CODE>.
* @param sourcefile <CODE>String</CODE>.
* @param redirector <code>Redirector</code>.
* @param sourcefile <code>String</code>.
*/ */
public void configure(Redirector redirector, String sourcefile) { public void configure(Redirector redirector, String sourcefile) {
if (isReference()) { if (isReference()) {
@@ -523,8 +525,8 @@ public class RedirectorElement extends DataType {


/** /**
* Create a merge mapper pointing to the specified destination file. * Create a merge mapper pointing to the specified destination file.
* @param destfile <CODE>File</CODE>
* @return <CODE>Mapper</CODE>.
* @param destfile <code>File</code>
* @return <code>Mapper</code>.
*/ */
protected Mapper createMergeMapper(File destfile) { protected Mapper createMergeMapper(File destfile) {
Mapper result = new Mapper(getProject()); Mapper result = new Mapper(getProject());
@@ -535,9 +537,9 @@ public class RedirectorElement extends DataType {
} }


/** /**
* Return a <CODE>File[]</CODE> from the specified set of filenames.
* @param name <CODE>String[]</CODE>
* @return <CODE>File[]</CODE>.
* Return a <code>File[]</code> from the specified set of filenames.
* @param name <code>String[]</code>
* @return <code>File[]</code>.
*/ */
protected File[] toFileArray(String[] name) { protected File[] toFileArray(String[] name) {
if (name == null) { if (name == null) {
@@ -553,19 +555,6 @@ public class RedirectorElement extends DataType {
return (File[]) (list.toArray(new File[list.size()])); return (File[]) (list.toArray(new File[list.size()]));
} }


/**
* Convenience method.
* @throws BuildException on error.
*/
protected void dieOnCircularReference() throws BuildException {
if (isChecked()) {
return;
}
Stack s = new Stack();
s.push(this);
dieOnCircularReference(s, getProject());
}

/** /**
* Overrides the version of DataType to recurse on all DataType * Overrides the version of DataType to recurse on all DataType
* child elements that may have been added. * child elements that may have been added.
@@ -607,17 +596,11 @@ public class RedirectorElement extends DataType {


/** /**
* Perform the check for circular references, returning the * Perform the check for circular references, returning the
* referenced RedirectorElement
* referenced RedirectorElement.
* @return the referenced RedirectorElement. * @return the referenced RedirectorElement.
*/ */
private RedirectorElement getRef() { private RedirectorElement getRef() {
dieOnCircularReference();
Object o = getRefid().getReferencedObject(getProject());
if (!(o instanceof RedirectorElement)) {
throw new BuildException(getRefid().getRefId()
+ " doesn\'t denote a RedirectorElement");
}
return (RedirectorElement) o;
return (RedirectorElement) getCheckedRef();
} }


} }

+ 1
- 15
src/main/org/apache/tools/ant/types/RegularExpression.java View File

@@ -138,20 +138,6 @@ public class RegularExpression extends DataType {
* @return resolved RegularExpression instance * @return resolved RegularExpression instance
*/ */
public RegularExpression getRef(Project p) { public RegularExpression getRef(Project p) {
if (!isChecked()) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, p);
}


Object o = getRefid().getReferencedObject(p);
if (!(o instanceof RegularExpression)) {
String msg = getRefid().getRefId() + " doesn\'t denote a "
+ DATA_TYPE_NAME;
throw new BuildException(msg);
} else {
return (RegularExpression) o;
}
return (RegularExpression) getCheckedRef(p);
} }
} }

+ 1
- 14
src/main/org/apache/tools/ant/types/Substitution.java View File

@@ -73,19 +73,6 @@ public class Substitution extends DataType {
* @return the resolved reference * @return the resolved reference
*/ */
public Substitution getRef(Project p) { public Substitution getRef(Project p) {
if (!isChecked()) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, p);
}


Object o = getRefid().getReferencedObject(p);
if (!(o instanceof Substitution)) {
String msg = getRefid().getRefId() + " doesn\'t denote a substitution";
throw new BuildException(msg);
} else {
return (Substitution) o;
}
return (Substitution) getCheckedRef(p);
} }
} }

+ 2
- 12
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -394,12 +394,7 @@ public class XMLCatalog extends DataType
return getRef().resolveEntity(publicId, systemId); return getRef().resolveEntity(publicId, systemId);
} }


if (!isChecked()) {
// make sure we don't have a circular reference here
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, getProject());
}
dieOnCircularReference();


log("resolveEntity: '" + publicId + "': '" + systemId + "'", log("resolveEntity: '" + publicId + "': '" + systemId + "'",
Project.MSG_DEBUG); Project.MSG_DEBUG);
@@ -427,12 +422,7 @@ public class XMLCatalog extends DataType
return getRef().resolve(href, base); return getRef().resolve(href, base);
} }


if (!isChecked()) {
// make sure we don't have a circular reference here
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, getProject());
}
dieOnCircularReference();


SAXSource source = null; SAXSource source = null;




Loading…
Cancel
Save