KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > condition > ConditionBase


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.taskdefs.condition;
20
21 import java.util.Enumeration JavaDoc;
22 import java.util.Vector JavaDoc;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.DynamicElement;
25 import org.apache.tools.ant.ComponentHelper;
26 import org.apache.tools.ant.ProjectComponent;
27 import org.apache.tools.ant.taskdefs.Available;
28 import org.apache.tools.ant.taskdefs.Checksum;
29 import org.apache.tools.ant.taskdefs.UpToDate;
30
31 /**
32  * Baseclass for the <condition> task as well as several
33  * conditions - ensures that the types of conditions inside the task
34  * and the "container" conditions are in sync.
35  *
36  * @since Ant 1.4
37  */

38 public abstract class ConditionBase extends ProjectComponent
39     implements DynamicElement {
40
41     private static final String JavaDoc CONDITION_ANTLIB
42         = "antlib:org.apache.tools.ant.types.conditions:";
43
44     /**
45      * name of the component
46      */

47     private String JavaDoc taskName = "condition";
48
49     /**
50      *
51      */

52     private Vector JavaDoc conditions = new Vector JavaDoc();
53
54     /**
55      * Simple constructor.
56      */

57     protected ConditionBase() {
58         taskName = "component";
59     }
60
61     /**
62      * Constructor that takes the name of the task in the task name.
63      * @param taskName the name of the task.
64      * @since Ant 1.7
65      */

66     protected ConditionBase(String JavaDoc taskName) {
67         this.taskName = taskName;
68     }
69
70     /**
71      * Count the conditions.
72      *
73      * @return the number of conditions in the container
74      * @since 1.1
75      */

76     protected int countConditions() {
77         return conditions.size();
78     }
79
80     /**
81      * Iterate through all conditions.
82      *
83      * @return an enumeration to use for iteration
84      * @since 1.1
85      */

86     protected final Enumeration JavaDoc getConditions() {
87         return conditions.elements();
88     }
89
90     /**
91      * Sets the name to use in logging messages.
92      *
93      * @param name The name to use in logging messages.
94      * Should not be <code>null</code>.
95      * @since Ant 1.7
96      */

97     public void setTaskName(String JavaDoc name) {
98         this.taskName = name;
99     }
100
101     /**
102      * Returns the name to use in logging messages.
103      *
104      * @return the name to use in logging messages.
105      * @since Ant 1.7
106      */

107     public String JavaDoc getTaskName() {
108         return taskName;
109     }
110
111     /**
112      * Add an &lt;available&gt; condition.
113      * @param a an available condition
114      * @since 1.1
115      */

116     public void addAvailable(Available a) {
117         conditions.addElement(a);
118     }
119
120     /**
121      * Add an &lt;checksum&gt; condition.
122      *
123      * @param c a Checksum condition
124      * @since 1.4, Ant 1.5
125      */

126     public void addChecksum(Checksum c) {
127         conditions.addElement(c);
128     }
129
130     /**
131      * Add an &lt;uptodate&gt; condition.
132      *
133      * @param u an UpToDate condition
134      * @since 1.1
135      */

136     public void addUptodate(UpToDate u) {
137         conditions.addElement(u);
138     }
139
140     /**
141      * Add an &lt;not&gt; condition "container".
142      *
143      * @param n a Not condition
144      * @since 1.1
145      */

146     public void addNot(Not n) {
147         conditions.addElement(n);
148     }
149
150     /**
151      * Add an &lt;and&gt; condition "container".
152      *
153      * @param a an And condition
154      * @since 1.1
155      */

156     public void addAnd(And a) {
157         conditions.addElement(a);
158     }
159
160     /**
161      * Add an &lt;or&gt; condition "container".
162      *
163      * @param o an Or condition
164      * @since 1.1
165      */

166     public void addOr(Or o) {
167         conditions.addElement(o);
168     }
169
170     /**
171      * Add an &lt;equals&gt; condition.
172      *
173      * @param e an Equals condition
174      * @since 1.1
175      */

176     public void addEquals(Equals e) {
177         conditions.addElement(e);
178     }
179
180     /**
181      * Add an &lt;os&gt; condition.
182      *
183      * @param o an Os condition
184      * @since 1.1
185      */

186     public void addOs(Os o) {
187         conditions.addElement(o);
188     }
189
190     /**
191      * Add an &lt;isset&gt; condition.
192      *
193      * @param i an IsSet condition
194      * @since Ant 1.5
195      */

196     public void addIsSet(IsSet i) {
197         conditions.addElement(i);
198     }
199
200     /**
201      * Add an &lt;http&gt; condition.
202      *
203      * @param h an Http condition
204      * @since Ant 1.5
205      */

206     public void addHttp(Http h) {
207         conditions.addElement(h);
208     }
209
210     /**
211      * Add a &lt;socket&gt; condition.
212      *
213      * @param s a Socket condition
214      * @since Ant 1.5
215      */

216     public void addSocket(Socket s) {
217         conditions.addElement(s);
218     }
219
220     /**
221      * Add a &lt;filesmatch&gt; condition.
222      *
223      * @param test a FilesMatch condition
224      * @since Ant 1.5
225      */

226     public void addFilesMatch(FilesMatch test) {
227         conditions.addElement(test);
228     }
229
230     /**
231      * Add a &lt;contains&gt; condition.
232      *
233      * @param test a Contains condition
234      * @since Ant 1.5
235      */

236     public void addContains(Contains test) {
237         conditions.addElement(test);
238     }
239
240     /**
241      * Add a &lt;istrue&gt; condition.
242      *
243      * @param test an IsTrue condition
244      * @since Ant 1.5
245      */

246     public void addIsTrue(IsTrue test) {
247         conditions.addElement(test);
248     }
249
250     /**
251      * Add a &lt;isfalse&gt; condition.
252      *
253      * @param test an IsFalse condition
254      * @since Ant 1.5
255      */

256     public void addIsFalse(IsFalse test) {
257         conditions.addElement(test);
258     }
259
260     /**
261      * Add an &lt;isreference&gt; condition.
262      *
263      * @param i an IsReference condition
264      * @since Ant 1.6
265      */

266     public void addIsReference(IsReference i) {
267         conditions.addElement(i);
268     }
269
270     /**
271      * Add an &lt;isfileselected&gt; condition.
272      * @param test the condition
273      */

274     public void addIsFileSelected(IsFileSelected test) {
275         conditions.addElement(test);
276     }
277
278     /**
279      * Add an arbitrary condition
280      * @param c a condition
281      * @since Ant 1.6
282      */

283     public void add(Condition c) {
284         conditions.addElement(c);
285     }
286
287     /**
288      * Create a dynamically discovered condition. Built-in conditions can
289      * be discovered from the org.apache.tools.ant.taskdefs.condition
290      * antlib.
291      * @param name the condition to create.
292      * @return the dynamic condition if found, null otherwise.
293      */

294     public Object JavaDoc createDynamicElement(String JavaDoc name) {
295         Object JavaDoc cond = ComponentHelper.getComponentHelper(getProject())
296             .createComponent(CONDITION_ANTLIB + name);
297         if (!(cond instanceof Condition)) {
298             return null;
299         }
300         log("Dynamically discovered '" + name + "' " + cond,
301             Project.MSG_DEBUG);
302         add((Condition) cond);
303         return cond;
304     }
305
306 }
307
Popular Tags