KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > AntFilterReader


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types;
19
20 import java.util.Vector JavaDoc;
21 import org.apache.tools.ant.BuildException;
22
23 /**
24  * An AntFilterReader is a wrapper class that encloses the classname
25  * and configuration of a Configurable FilterReader.
26  */

27 public final class AntFilterReader
28     extends DataType implements Cloneable JavaDoc {
29
30     private String JavaDoc className;
31
32     private final Vector JavaDoc parameters = new Vector JavaDoc();
33
34     private Path classpath;
35
36     /**
37      * Set the className attribute.
38      *
39      * @param className a <code>String</code> value
40      */

41     public void setClassName(final String JavaDoc className) {
42         this.className = className;
43     }
44
45     /**
46      * Get the className attribute.
47      *
48      * @return a <code>String</code> value
49      */

50     public String JavaDoc getClassName() {
51         return className;
52     }
53
54     /**
55      * Add a Parameter.
56      *
57      * @param param a <code>Parameter</code> value
58      */

59     public void addParam(final Parameter param) {
60         parameters.addElement(param);
61     }
62
63     /**
64      * Set the classpath to load the FilterReader through (attribute).
65      * @param classpath a classpath
66      */

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     /**
79      * Set the classpath to load the FilterReader through (nested element).
80      * @return a classpath to be configured
81      */

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     /**
93      * Get the classpath.
94      * @return the classpath
95      */

96     public Path getClasspath() {
97         return classpath;
98     }
99
100     /**
101      * Set the classpath to load the FilterReader through via
102      * reference (attribute).
103      * @param r a reference to a classpath
104      */

105     public void setClasspathRef(Reference r) {
106         if (isReference()) {
107             throw tooManyAttributes();
108         }
109         createClasspath().setRefid(r);
110     }
111
112     /**
113      * The parameters for this filter.
114      *
115      * @return a <code>Parameter[]</code> value
116      */

117     public Parameter[] getParams() {
118         Parameter[] params = new Parameter[parameters.size()];
119         parameters.copyInto(params);
120         return params;
121     }
122
123     /**
124      * Makes this instance in effect a reference to another AntFilterReader
125      * instance.
126      *
127      * <p>You must not set another attribute or nest elements inside
128      * this element if you make it a reference.</p>
129      *
130      * @param r the reference to which this instance is associated
131      * @exception BuildException if this instance already has been configured.
132      */

133     public void setRefid(Reference r) throws BuildException {
134         if (!parameters.isEmpty() || className != null
135                 || classpath != null) {
136             throw tooManyAttributes();
137         }
138         // change this to get the objects from the other reference
139
Object JavaDoc 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 JavaDoc 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