1 18 package org.apache.tools.ant.types; 19 20 import java.util.Vector ; 21 import org.apache.tools.ant.BuildException; 22 23 27 public final class AntFilterReader 28 extends DataType implements Cloneable { 29 30 private String className; 31 32 private final Vector parameters = new Vector (); 33 34 private Path classpath; 35 36 41 public void setClassName(final String className) { 42 this.className = className; 43 } 44 45 50 public String getClassName() { 51 return className; 52 } 53 54 59 public void addParam(final Parameter param) { 60 parameters.addElement(param); 61 } 62 63 67 public void setClasspath(Path classpath) { 68 if (isReference()) { 69 throw tooManyAttributes(); 70 } 71 if (this.classpath == null) { 72 this.classpath = classpath; 73 } else { 74 this.classpath.append(classpath); 75 } 76 } 77 78 82 public Path createClasspath() { 83 if (isReference()) { 84 throw noChildrenAllowed(); 85 } 86 if (this.classpath == null) { 87 this.classpath = new Path(getProject()); 88 } 89 return this.classpath.createPath(); 90 } 91 92 96 public Path getClasspath() { 97 return classpath; 98 } 99 100 105 public void setClasspathRef(Reference r) { 106 if (isReference()) { 107 throw tooManyAttributes(); 108 } 109 createClasspath().setRefid(r); 110 } 111 112 117 public Parameter[] getParams() { 118 Parameter[] params = new Parameter[parameters.size()]; 119 parameters.copyInto(params); 120 return params; 121 } 122 123 133 public void setRefid(Reference r) throws BuildException { 134 if (!parameters.isEmpty() || className != null 135 || classpath != null) { 136 throw tooManyAttributes(); 137 } 138 Object o = r.getReferencedObject(getProject()); 140 if (o instanceof AntFilterReader) { 141 AntFilterReader afr = (AntFilterReader) o; 142 setClassName(afr.getClassName()); 143 setClasspath(afr.getClasspath()); 144 Parameter[] p = afr.getParams(); 145 if (p != null) { 146 for (int i = 0; i < p.length; i++) { 147 addParam(p[i]); 148 } 149 } 150 } else { 151 String msg = r.getRefId() + " doesn\'t refer to a FilterReader"; 152 throw new BuildException(msg); 153 } 154 155 super.setRefid(r); 156 } 157 } 158 | Popular Tags |