source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/AntFilterReader.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.0 KB
Line 
1/*
2 * Copyright 2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.types;
18
19import java.util.Vector;
20import org.apache.tools.ant.BuildException;
21
22/**
23 * An AntFileReader is a wrapper class that encloses the classname
24 * and configuration of a Configurable FilterReader.
25 *
26 */
27public final class AntFilterReader
28 extends DataType
29 implements Cloneable {
30
31 private String className;
32
33 private final Vector parameters = new Vector();
34
35 private Path classpath;
36
37 public final void setClassName(final String className) {
38 this.className = className;
39 }
40
41 public final String getClassName() {
42 return className;
43 }
44
45 public final void addParam(final Parameter param) {
46 parameters.addElement(param);
47 }
48
49 /**
50 * Set the classpath to load the FilterReader through (attribute).
51 */
52 public final void setClasspath(Path classpath) {
53 if (isReference()) {
54 throw tooManyAttributes();
55 }
56 if (this.classpath == null) {
57 this.classpath = classpath;
58 } else {
59 this.classpath.append(classpath);
60 }
61 }
62
63 /**
64 * Set the classpath to load the FilterReader through (nested element).
65 */
66 public final Path createClasspath() {
67 if (isReference()) {
68 throw noChildrenAllowed();
69 }
70 if (this.classpath == null) {
71 this.classpath = new Path(getProject());
72 }
73 return this.classpath.createPath();
74 }
75
76 /**
77 * Get the classpath
78 */
79 public final Path getClasspath() {
80 return classpath;
81 }
82
83 /**
84 * Set the classpath to load the FilterReader through via
85 * reference (attribute).
86 */
87 public void setClasspathRef(Reference r) {
88 if (isReference()) {
89 throw tooManyAttributes();
90 }
91 createClasspath().setRefid(r);
92 }
93
94 public final Parameter[] getParams() {
95 Parameter[] params = new Parameter[parameters.size()];
96 parameters.copyInto(params);
97 return params;
98 }
99
100 /**
101 * Makes this instance in effect a reference to another AntFilterReader
102 * instance.
103 *
104 * <p>You must not set another attribute or nest elements inside
105 * this element if you make it a reference.</p>
106 *
107 * @param r the reference to which this instance is associated
108 * @exception BuildException if this instance already has been configured.
109 */
110 public void setRefid(Reference r) throws BuildException {
111 if (!parameters.isEmpty() || className != null
112 || classpath != null) {
113 throw tooManyAttributes();
114 }
115 // change this to get the objects from the other reference
116 Object o = r.getReferencedObject(getProject());
117 if (o instanceof AntFilterReader) {
118 AntFilterReader afr = (AntFilterReader) o;
119 setClassName(afr.getClassName());
120 setClasspath(afr.getClasspath());
121 Parameter[] p = afr.getParams();
122 if (p != null) {
123 for (int i = 0; i < p.length; i++) {
124 addParam(p[i]);
125 }
126 }
127 } else {
128 String msg = r.getRefId() + " doesn\'t refer to a FilterReader";
129 throw new BuildException(msg);
130 }
131
132 super.setRefid(r);
133 }
134}
Note: See TracBrowser for help on using the repository browser.