KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > starters > ConditionalTaskSet


1 /**
2  * $Id: ConditionalTaskSet.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2004 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.starters;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33
34 import com.idaremedia.antx.ownhelpers.OptionalExecuteHelper;
35 import com.idaremedia.antx.parameters.Conditional;
36
37 /**
38  * Taskset that has builtin support for the standard if/unless conditional execution.
39  * This taskset is <em>not</em> the standard AntX &lt;do&gt; task which supports a
40  * large collection of condition types. Instead this class is a lite variant of
41  * the always-executed taskset that AntX-dependent tools use as a starting point for
42  * their own task containers.
43  *
44  * @since JWare/AntX 0.1
45  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
46  * @version 0.5
47  * @.safety single
48  * @.group impl,infra
49  **/

50
51 public class ConditionalTaskSet extends TaskSet implements Conditional
52 {
53     /**
54      * Initializes a new empty conditional taskset.
55      **/

56     public ConditionalTaskSet()
57     {
58         super();
59     }
60
61
62
63     /**
64      * Initializes a new CV-labeled empty conditional taskset.
65      * @param iam CV-label (non-null)
66      **/

67     protected ConditionalTaskSet(String JavaDoc iam)
68     {
69         super(iam);
70     }
71
72
73
74     /**
75      * Updates this task's and any helper's enclosing project.
76      **/

77     public void setProject(Project project)
78     {
79         super.setProject(project);
80         m_guard.setProject(project);
81     }
82
83
84
85     /**
86      * Initializes new configuration-delaying taskset.
87      * @param iam CV-label (non-null)
88      * @param delayConfigure <i>true</i> if nested tasks configured
89      * when they're actually executed
90      **/

91     protected ConditionalTaskSet(String JavaDoc iam, boolean delayConfigure)
92     {
93         super(iam,delayConfigure);
94     }
95
96
97
98     /**
99      * Runs nested tasks if all 'if' conditiona met and not if
100      * any 'unless' conditions met.
101      **/

102     protected void performNestedTasks() throws BuildException
103     {
104         boolean passIf= testIfCondition();
105
106         if (passIf && testUnlessCondition()) {
107             performTheCheckedTasks();
108         }
109         else {
110             logSkippedBecause(passIf, Project.MSG_VERBOSE);
111         }
112     }
113
114
115
116     /**
117      * Called to perform this taskset's nested tasks <em>after</em>
118      * the various if/unless conditions have been verified. Subclasses
119      * should override this method if they want to keep the standard
120      * condition testing identical.
121      * @since JWare/AntX 0.4
122      **/

123     protected void performTheCheckedTasks()
124     {
125         performTheTasksList();
126     }
127
128
129
130     /**
131      * Adds a simple if-condition to this taskset.
132      **/

133     public void setIf(String JavaDoc property)
134     {
135         m_guard.setIf(property);
136     }
137
138
139
140     /**
141      * Returns this taskset's (raw) if-condition if any. Returns
142      * empty string if condition never set.
143      **/

144     public String JavaDoc getIfProperty()
145     {
146         String JavaDoc s = m_guard.getIfProperty();
147         return s==null ? "" : s;
148     }
149
150
151
152     /**
153      * Adds the unless-condition to this taskset.
154      **/

155     public void setUnless(String JavaDoc property)
156     {
157         m_guard.setUnless(property);
158     }
159
160
161
162     /**
163      * Returns this taskset's (raw) unless-condition if any.
164      * Returns empty string if condition never set.
165      **/

166     public String JavaDoc getUnlessProperty()
167     {
168         String JavaDoc s = m_guard.getUnlessProperty();
169         return s==null ? "" : s;
170     }
171
172
173
174     /**
175      * Tests whether or not all of this taskset's "if"
176      * conditions are met.
177      * @return <i>true</i> if all "if" condition are met
178      * @see OptionalExecuteHelper
179      **/

180     public boolean testIfCondition()
181     {
182         return m_guard.testIfCondition();
183     }
184
185
186
187     /**
188      * Tests whether or not all of this taskset's "unless"
189      * conditions are met.
190      * @return <i>true</i> if all "unless" conditions are met
191      * @see OptionalExecuteHelper
192      **/

193     public boolean testUnlessCondition()
194     {
195         return m_guard.testUnlessCondition();
196     }
197
198
199
200     /**
201      * Helper that shows why this task didn't run (if/unless).
202      * Message is logged at requested level.
203      **/

204     protected final void logSkippedBecause(boolean passIf, int logLevel)
205     {
206         m_guard.logSkippedBecause(this,passIf,logLevel);
207     }
208
209
210
211     /**
212      * Helper that shows why this task didn't run (if/unless).
213      * Message is logged at VERBOSE level.
214      **/

215     protected final void logSkippedBecause(boolean passIf)
216     {
217         m_guard.logSkippedBecause(this,passIf,Project.MSG_VERBOSE);
218     }
219
220
221
222     /** Actual if/unless determiner. **/
223     protected final OptionalExecuteHelper m_guard =
224         new OptionalExecuteHelper();
225 }
226
227 /* end-of-ConditionalTaskSet.java */
228
Popular Tags