source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.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: 8.1 KB
Line 
1/*
2 * Copyright 2002-2005 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 */
17
18package org.apache.tools.ant.types.selectors;
19
20import java.util.Enumeration;
21import java.util.Vector;
22
23import org.apache.tools.ant.Project;
24import org.apache.tools.ant.types.DataType;
25import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
26
27/**
28 * This is the a base class a container of selectors - it does
29 * not need do be a selector itself.
30 *
31 * @since 1.7
32 */
33public abstract class AbstractSelectorContainer extends DataType
34 implements SelectorContainer {
35
36 private Vector selectorsList = new Vector();
37
38 /**
39 * Indicates whether there are any selectors here.
40 * @return true if there are selectors
41 */
42 public boolean hasSelectors() {
43 return !(selectorsList.isEmpty());
44 }
45
46 /**
47 * Gives the count of the number of selectors in this container
48 * @return the number of selectors
49 */
50 public int selectorCount() {
51 return selectorsList.size();
52 }
53
54 /**
55 * Returns the set of selectors as an array.
56 * @param p the current project
57 * @return an array of selectors
58 */
59 public FileSelector[] getSelectors(Project p) {
60 FileSelector[] result = new FileSelector[selectorsList.size()];
61 selectorsList.copyInto(result);
62 return result;
63 }
64
65 /**
66 * Returns an enumerator for accessing the set of selectors.
67 * @return an enumerator for the selectors
68 */
69 public Enumeration selectorElements() {
70 return selectorsList.elements();
71 }
72
73 /**
74 * Convert the Selectors within this container to a string. This will
75 * just be a helper class for the subclasses that put their own name
76 * around the contents listed here.
77 *
78 * @return comma separated list of Selectors contained in this one
79 */
80 public String toString() {
81 StringBuffer buf = new StringBuffer();
82 Enumeration e = selectorElements();
83 if (e.hasMoreElements()) {
84 while (e.hasMoreElements()) {
85 buf.append(e.nextElement().toString());
86 if (e.hasMoreElements()) {
87 buf.append(", ");
88 }
89 }
90 }
91
92 return buf.toString();
93 }
94
95 /**
96 * Add a new selector into this container.
97 *
98 * @param selector the new selector to add
99 */
100 public void appendSelector(FileSelector selector) {
101 selectorsList.addElement(selector);
102 }
103
104 /**
105 * <p>
106 * This validates each contained selector
107 * provided that the selector implements the validate interface.
108 * </p>
109 * <p>Ordinarily, this will validate all the elements of a selector
110 * container even if the isSelected() method of some elements is
111 * never called. This has two effects:</p>
112 * <ul>
113 * <li>Validation will often occur twice.
114 * <li>Since it is not required that selectors derive from
115 * BaseSelector, there could be selectors in the container whose
116 * error conditions are not detected if their isSelected() call
117 * is never made.
118 * </ul>
119 */
120 public void validate() {
121 Enumeration e = selectorElements();
122 while (e.hasMoreElements()) {
123 Object o = e.nextElement();
124 if (o instanceof BaseSelector) {
125 ((BaseSelector) o).validate();
126 }
127 }
128 }
129
130
131 /* Methods below all add specific selectors */
132
133 /**
134 * add a "Select" selector entry on the selector list
135 * @param selector the selector to add
136 */
137 public void addSelector(SelectSelector selector) {
138 appendSelector(selector);
139 }
140
141 /**
142 * add an "And" selector entry on the selector list
143 * @param selector the selector to add
144 */
145 public void addAnd(AndSelector selector) {
146 appendSelector(selector);
147 }
148
149 /**
150 * add an "Or" selector entry on the selector list
151 * @param selector the selector to add
152 */
153 public void addOr(OrSelector selector) {
154 appendSelector(selector);
155 }
156
157 /**
158 * add a "Not" selector entry on the selector list
159 * @param selector the selector to add
160 */
161 public void addNot(NotSelector selector) {
162 appendSelector(selector);
163 }
164
165 /**
166 * add a "None" selector entry on the selector list
167 * @param selector the selector to add
168 */
169 public void addNone(NoneSelector selector) {
170 appendSelector(selector);
171 }
172
173 /**
174 * add a majority selector entry on the selector list
175 * @param selector the selector to add
176 */
177 public void addMajority(MajoritySelector selector) {
178 appendSelector(selector);
179 }
180
181 /**
182 * add a selector date entry on the selector list
183 * @param selector the selector to add
184 */
185 public void addDate(DateSelector selector) {
186 appendSelector(selector);
187 }
188
189 /**
190 * add a selector size entry on the selector list
191 * @param selector the selector to add
192 */
193 public void addSize(SizeSelector selector) {
194 appendSelector(selector);
195 }
196
197 /**
198 * add a selector filename entry on the selector list
199 * @param selector the selector to add
200 */
201 public void addFilename(FilenameSelector selector) {
202 appendSelector(selector);
203 }
204
205 /**
206 * add an extended selector entry on the selector list
207 * @param selector the selector to add
208 */
209 public void addCustom(ExtendSelector selector) {
210 appendSelector(selector);
211 }
212
213 /**
214 * add a contains selector entry on the selector list
215 * @param selector the selector to add
216 */
217 public void addContains(ContainsSelector selector) {
218 appendSelector(selector);
219 }
220
221 /**
222 * add a present selector entry on the selector list
223 * @param selector the selector to add
224 */
225 public void addPresent(PresentSelector selector) {
226 appendSelector(selector);
227 }
228
229 /**
230 * add a depth selector entry on the selector list
231 * @param selector the selector to add
232 */
233 public void addDepth(DepthSelector selector) {
234 appendSelector(selector);
235 }
236
237 /**
238 * add a depends selector entry on the selector list
239 * @param selector the selector to add
240 */
241 public void addDepend(DependSelector selector) {
242 appendSelector(selector);
243 }
244
245 /**
246 * adds a different selector to the selector list
247 * @param selector the selector to add
248 */
249 public void addDifferent(DifferentSelector selector) {
250 appendSelector(selector);
251 }
252
253 /**
254 * adds a type selector to the selector list
255 * @param selector the selector to add
256 */
257 public void addType(TypeSelector selector) {
258 appendSelector(selector);
259 }
260
261 /**
262 * add a regular expression selector entry on the selector list
263 * @param selector the selector to add
264 */
265 public void addContainsRegexp(ContainsRegexpSelector selector) {
266 appendSelector(selector);
267 }
268
269 /**
270 * add the modified selector
271 * @param selector the selector to add
272 * @since ant 1.6
273 */
274 public void addModified(ModifiedSelector selector) {
275 appendSelector(selector);
276 }
277
278 /**
279 * add an arbitary selector
280 * @param selector the selector to add
281 * @since Ant 1.6
282 */
283 public void add(FileSelector selector) {
284 appendSelector(selector);
285 }
286
287}
Note: See TracBrowser for help on using the repository browser.