KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > wrap > IsolatedTaskSet


1 /**
2  * $Id: IsolatedTaskSet.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 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 (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any 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 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 GNU 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.flowcontrol.wrap;
30
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import org.apache.tools.ant.BuildException;
35 import org.apache.tools.ant.Project;
36
37 import com.idaremedia.antx.AntX;
38 import com.idaremedia.antx.FixtureOverlay;
39 import com.idaremedia.antx.apis.Requester;
40 import com.idaremedia.antx.helpers.Strings;
41 import com.idaremedia.antx.helpers.Tk;
42 import com.idaremedia.antx.starters.TaskSet;
43
44 /**
45  * A taskset that isolates the effects of its nested tasks away from the enclosing project.
46  * Basically the standard AntX way to install a generic {@linkplain ExecutionBubble}.
47  * <p>
48  * <b>Example Usage:</b><pre>
49  * &lt;assert isnotset="a.property"/&gt;
50  * &lt;<b>isolate</b> warnproperty="whoopsies"&gt;
51  * &lt;property name="a.property" value="hi!"/&gt;
52  * &lt;assign name="a.time" op="now" scope="project"/&gt;
53  * &lt;/isolate&gt;
54  * &lt;assert isnotset="a.property"/&gt;
55  * &lt;assert isnotset="a.time" isa="reference"/&gt;
56  * &lt;assert isnotset="whoopsies" msg="No object issues found"/&gt;
57  * </pre>
58  *
59  * @since JWare/AntX 0.4
60  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
61  * @version 0.5
62  * @.safety single
63  * @.group api,helper
64  * @see Locals
65  * @see LocalExecutionBubble
66  * @see com.idaremedia.antx.solo.LocalFixtureTaskSet LocalFixtureTaskSet
67  **/

68
69 public class IsolatedTaskSet extends TaskSet
70     implements FixtureOverlay
71 {
72     /**
73      * Initializes a new isolated task set.
74      **/

75     public IsolatedTaskSet()
76     {
77         super(AntX.flow+"isolated");
78     }
79
80
81
82     /**
83      * Initializes a new enclosed isolated task set.
84      * @param iam CV-label
85      **/

86     public IsolatedTaskSet(String JavaDoc iam)
87     {
88         super(iam);
89     }
90
91
92
93     /**
94      * Initializes a new subclassed isolated task set.
95      * @param iam CV-label
96      * @param delayConfigure <i>true</i> to delay configuration
97      * of nested items
98      **/

99     public IsolatedTaskSet(String JavaDoc iam, boolean delayConfigure)
100     {
101         super(iam,delayConfigure);
102     }
103
104
105
106     /**
107      * Creates this taskset's execution bubble. Subclasses who
108      * override this method <em>must</em> call this inherited
109      * method before they access the bubble.
110      * @see #newRunBubble newRunBubble(&#8230;)
111      */

112     public void init()
113     {
114         super.init();
115         m_bubble = newRunBubble();
116         m_bubble.setProject(getProject());
117     }
118
119
120
121     /**
122      * Tells this isolated taskset to be carefully check project
123      * references on exit. Will issue warnings for deleted or
124      * changed references.
125      * @param careful <i>true</i> to issue warnings for altered
126      * project fixture
127      **/

128     public void setCareful(boolean careful)
129     {
130         m_bubble.setCarefulObjectChecks(careful);
131     }
132
133
134
135     /**
136      * Tells this isolated taskset to update a property (or a
137      * set of properties) with warnings about changed
138      * or deleted references. Because it's possible that multiple
139      * categories of fixture items are changed, each fixture
140      * category stores its warnings under a property that combines
141      * the given property name and a category specific suffix;
142      * for example, references store warnings under a property
143      * named <span class="src">property-refs</span> while
144      * context reset methods store warnings under a property named
145      * <span class="src">property-<i>adminId</i></span> where
146      * "<i>adminId</i>" is the name of the fixture administrator.
147      * @param property name of property to update
148      * @.sideeffect Turns on {@linkplain #setCareful careful} checking.
149      **/

150     public void setWarnProperty(String JavaDoc property)
151     {
152         m_bubble.setWarningsUpdateProperty(property);
153         setCareful(true);
154     }
155
156
157
158     /**
159      * Tells this isolated taskset to reset top-level iteration
160      * fixture administrators. <em>DO NOT USE THIS OPTION UNLESS
161      * YOU REALLY KNOW WHAT YOU'RE DOING.</em> While the ability
162      * to reset fixture administrators is critical in test scripts,
163      * it is almost never a good idea in a regular build situation.
164      * Example Usage:<pre>
165      * &lt;isolate resetfixture="stringmanagers=default,outputrecorders=all"&gt;
166      * ...
167      * &lt;/isolate&gt;
168      * </pre>
169      * @param fixidList comma-delimited list of <i>component</i>=<i>aspect</i>
170      * pairs.
171      **/

172     public void setResetFixture(String JavaDoc fixidList)
173     {
174         require_(fixidList!=null,"resetFix- nonzro idlist");
175         List JavaDoc l= Tk.splitList(fixidList);
176         if (!l.isEmpty()) {
177             int i;
178             String JavaDoc fxid,aspect;
179             for (Iterator JavaDoc itr=l.iterator();itr.hasNext();) {
180                 fxid= itr.next().toString();
181                 aspect = Strings.ALL;
182                 i= fxid.indexOf('=');
183                 if (i>0) {
184                     aspect= fxid.substring(i+1);
185                     fxid= fxid.substring(0,i);
186                 }
187                 m_bubble.addFixtureReset(fxid,aspect);
188             }
189         }
190     }
191
192
193
194     /**
195      * Makes this task's bubble porous by allowing all modifications
196      * through except those named. See {@linkplain Locals}.
197      * @param localsId name of locals definition (non-null)
198      * @since JWare/AntX 0.5
199      * @throws BuildException if unable to locate installed locals
200      * of given name.
201      **/

202     public final void setBlock(String JavaDoc localsId)
203     {
204         require_(localsId!=null,"setBlock- nonzro id");
205         setFilters(localsId,true);
206     }
207
208
209
210
211     /**
212      * Makes this task's bubble porous by allowing the named
213      * modifications through. See {@linkplain Locals}.
214      * @param localsId name of locals definition (non-null)
215      * @since JWare/AntX 0.5
216      * @throws BuildException if unable to locate installed locals
217      * of given name.
218      **/

219     public final void setAllow(String JavaDoc localsId)
220     {
221         require_(localsId!=null,"setAllow- nonzro id");
222         setFilters(localsId,false);
223     }
224
225
226
227
228     /**
229      * Tells this task whether default fixture exclusions should
230      * be ignored. For backward compatibility, fixture exclusions
231      * are ignored unless explicitly turned on at the task level
232      * or using the global defaults option.
233      * @param letEmPassThru <i>true</i> to let exclusion thru
234      * @since JWare/AntX 0.5
235      * @see com.idaremedia.antx.Defaults
236      **/

237     public void setFixtureExcludes(boolean letEmPassThru)
238     {
239         m_bubble.setFixtureExcludes(letEmPassThru);
240     }
241
242
243
244     /**
245      * Executes this taskset's nested tasks within an standard
246      * execution bubble.
247      */

248     protected void performNestedTasks()
249     {
250         Requester me = new Requester.ForComponent(this);
251         m_bubble.enter(me);
252         try {
253             performTheTasksList();
254         } finally {
255             m_bubble.leave(me);
256         }
257     }
258
259
260
261     /**
262      * Factory method for this taskset's local execution bubble.
263      * Called by {@linkplain #init init()} method.
264      * @see LocalExecutionBubble
265      */

266     protected LocalExecutionBubble newRunBubble()
267     {
268         return new LocalExecutionBubble();
269     }
270
271
272
273
274     /**
275      * Common work involved to assign a set of filter controls
276      * to this taskset's execution bubble.
277      * @param localsId id for filter instructions (non-null)
278      * @param blocking <i>true</i> if locals will be removed
279      * @since JWare/AntX 0.5
280      **/

281     private void setFilters(String JavaDoc localsId, boolean blocking)
282     {
283         if (m_bubble.isFiltered()) {
284             String JavaDoc error = getAntXMsg("task.one.or.other.attr","allow","deny");
285             log(error, Project.MSG_ERR);
286             throw new BuildException(error,getLocation());
287         }
288         Locals locals = (Locals)getReferencedObject(null,localsId,Locals.class);
289         locals.uninstall(new Requester.ForComponent(this));
290         locals.setBlocking(blocking);
291         m_bubble.setFilterControls(locals);
292     }
293
294
295     private LocalExecutionBubble m_bubble;
296 }
297
298
299 /* end-of-IsolatedTaskSet.java */
300
Popular Tags