KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > selectors > AbstractSelectorContainer


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
19 package org.apache.tools.ant.types.selectors;
20
21 import java.util.Enumeration JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.types.DataType;
26 import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
27
28 /**
29  * This is the a base class a container of selectors - it does
30  * not need do be a selector itself.
31  *
32  * @since 1.7
33  */

34 public abstract class AbstractSelectorContainer extends DataType
35         implements SelectorContainer {
36
37     private Vector JavaDoc selectorsList = new Vector JavaDoc();
38
39     /**
40      * Indicates whether there are any selectors here.
41      * @return true if there are selectors
42      */

43     public boolean hasSelectors() {
44         return !(selectorsList.isEmpty());
45     }
46
47     /**
48      * Gives the count of the number of selectors in this container
49      * @return the number of selectors
50      */

51     public int selectorCount() {
52         return selectorsList.size();
53     }
54
55     /**
56      * Returns the set of selectors as an array.
57      * @param p the current project
58      * @return an array of selectors
59      */

60     public FileSelector[] getSelectors(Project p) {
61         FileSelector[] result = new FileSelector[selectorsList.size()];
62         selectorsList.copyInto(result);
63         return result;
64     }
65
66     /**
67      * Returns an enumerator for accessing the set of selectors.
68      * @return an enumerator for the selectors
69      */

70     public Enumeration JavaDoc selectorElements() {
71         return selectorsList.elements();
72     }
73
74     /**
75      * Convert the Selectors within this container to a string. This will
76      * just be a helper class for the subclasses that put their own name
77      * around the contents listed here.
78      *
79      * @return comma separated list of Selectors contained in this one
80      */

81     public String JavaDoc toString() {
82         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
83         Enumeration JavaDoc e = selectorElements();
84         if (e.hasMoreElements()) {
85             while (e.hasMoreElements()) {
86                 buf.append(e.nextElement().toString());
87                 if (e.hasMoreElements()) {
88                     buf.append(", ");
89                 }
90             }
91         }
92
93         return buf.toString();
94     }
95
96     /**
97      * Add a new selector into this container.
98      *
99      * @param selector the new selector to add
100      */

101     public void appendSelector(FileSelector selector) {
102         selectorsList.addElement(selector);
103     }
104
105     /**
106      * <p>
107      * This validates each contained selector
108      * provided that the selector implements the validate interface.
109      * </p>
110      * <p>Ordinarily, this will validate all the elements of a selector
111      * container even if the isSelected() method of some elements is
112      * never called. This has two effects:</p>
113      * <ul>
114      * <li>Validation will often occur twice.
115      * <li>Since it is not required that selectors derive from
116      * BaseSelector, there could be selectors in the container whose
117      * error conditions are not detected if their isSelected() call
118      * is never made.
119      * </ul>
120      */

121     public void validate() {
122         Enumeration JavaDoc e = selectorElements();
123         while (e.hasMoreElements()) {
124             Object JavaDoc o = e.nextElement();
125             if (o instanceof BaseSelector) {
126                 ((BaseSelector) o).validate();
127             }
128         }
129     }
130
131
132     /* Methods below all add specific selectors */
133
134     /**
135      * add a "Select" selector entry on the selector list
136      * @param selector the selector to add
137      */

138     public void addSelector(SelectSelector selector) {
139         appendSelector(selector);
140     }
141
142     /**
143      * add an "And" selector entry on the selector list
144      * @param selector the selector to add
145      */

146     public void addAnd(AndSelector selector) {
147         appendSelector(selector);
148     }
149
150     /**
151      * add an "Or" selector entry on the selector list
152      * @param selector the selector to add
153      */

154     public void addOr(OrSelector selector) {
155         appendSelector(selector);
156     }
157
158     /**
159      * add a "Not" selector entry on the selector list
160      * @param selector the selector to add
161      */

162     public void addNot(NotSelector selector) {
163         appendSelector(selector);
164     }
165
166     /**
167      * add a "None" selector entry on the selector list
168      * @param selector the selector to add
169      */

170     public void addNone(NoneSelector selector) {
171         appendSelector(selector);
172     }
173
174     /**
175      * add a majority selector entry on the selector list
176      * @param selector the selector to add
177      */

178     public void addMajority(MajoritySelector selector) {
179         appendSelector(selector);
180     }
181
182     /**
183      * add a selector date entry on the selector list
184      * @param selector the selector to add
185      */

186     public void addDate(DateSelector selector) {
187         appendSelector(selector);
188     }
189
190     /**
191      * add a selector size entry on the selector list
192      * @param selector the selector to add
193      */

194     public void addSize(SizeSelector selector) {
195         appendSelector(selector);
196     }
197
198     /**
199      * add a selector filename entry on the selector list
200      * @param selector the selector to add
201      */

202     public void addFilename(FilenameSelector selector) {
203         appendSelector(selector);
204     }
205
206     /**
207      * add an extended selector entry on the selector list
208      * @param selector the selector to add
209      */

210     public void addCustom(ExtendSelector selector) {
211         appendSelector(selector);
212     }
213
214     /**
215      * add a contains selector entry on the selector list
216      * @param selector the selector to add
217      */

218     public void addContains(ContainsSelector selector) {
219         appendSelector(selector);
220     }
221
222     /**
223      * add a present selector entry on the selector list
224      * @param selector the selector to add
225      */

226     public void addPresent(PresentSelector selector) {
227         appendSelector(selector);
228     }
229
230     /**
231      * add a depth selector entry on the selector list
232      * @param selector the selector to add
233      */

234     public void addDepth(DepthSelector selector) {
235         appendSelector(selector);
236     }
237
238     /**
239      * add a depends selector entry on the selector list
240      * @param selector the selector to add
241      */

242     public void addDepend(DependSelector selector) {
243         appendSelector(selector);
244     }
245
246     /**
247      * adds a different selector to the selector list
248      * @param selector the selector to add
249      */

250     public void addDifferent(DifferentSelector selector) {
251         appendSelector(selector);
252     }
253
254     /**
255      * adds a type selector to the selector list
256      * @param selector the selector to add
257      */

258     public void addType(TypeSelector selector) {
259         appendSelector(selector);
260     }
261
262     /**
263      * add a regular expression selector entry on the selector list
264      * @param selector the selector to add
265      */

266     public void addContainsRegexp(ContainsRegexpSelector selector) {
267         appendSelector(selector);
268     }
269
270     /**
271      * add the modified selector
272      * @param selector the selector to add
273      * @since ant 1.6
274      */

275     public void addModified(ModifiedSelector selector) {
276         appendSelector(selector);
277     }
278
279     /**
280      * add an arbitary selector
281      * @param selector the selector to add
282      * @since Ant 1.6
283      */

284     public void add(FileSelector selector) {
285         appendSelector(selector);
286     }
287
288 }
289
Popular Tags