KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > call > InlineStep


1 /**
2  * $Id: InlineStep.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 of the License, or (at your option) any later
9  * 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.flowcontrol.call;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.Task;
34
35 import com.idaremedia.antx.AntX;
36 import com.idaremedia.antx.flowcontrol.ConditionalTaskSet;
37 import com.idaremedia.antx.helpers.TaskHandle;
38 import com.idaremedia.antx.helpers.Tk;
39 import com.idaremedia.antx.starters.Quiet;
40
41 /**
42  * A series of tasks defined as an inner target. Steps are passive (do nothing via
43  * the standard Ant-execution mechanism). Steps must be actively executed indirectly
44  * through a CallerTask control task (like a &lt;callforeach&gt; or &lt;call&gt;).
45  * <p>
46  * To use call steps you <em>must</em> define the special AntX step-launch target;
47  * see {@linkplain StepLauncherInstallTask}.
48  * <p>
49  * <b>Example Usage:</b><pre>
50  * &lt;target name="TheTarget"&gt;
51  * &lt;step name="clean"&gt;
52  * &lt;delete quiet="true" includeEmptyDir="yes" dir="..."/&gt;
53  * &lt;/step&gt;
54  * &lt;step name="extract"&gt;
55  * &lt;cvs dest="..." command="update -d" .../&gt;
56  * &lt;checkpoint tofile=".../checkout.last"/&gt;
57  * &lt;/step&gt;
58  * &lt;step name="transform"&gt;
59  * &lt;copy todir="...">...&lt;/copy&gt;
60  * &lt;xslt .../&gt;
61  * &lt;checkpoint tofile=".../merged.last"/&gt;
62  * &lt;/step&gt;
63  * ...
64  * &lt;callforeach i="module" list="${module.list}"
65  * steps="clean,extract,transform"/&gt;
66  * ...
67  * &lt;/target&gt;
68  * </pre>
69  *
70  * @since JWare/AntX 0.1
71  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
72  * @version 0.5
73  * @.safety single
74  * @.group impl,infra
75  **/

76
77 public class InlineStep extends ConditionalTaskSet
78     implements Quiet, InlinedTarget, InlinedTargetContainer
79 {
80     /**
81      * Initializes a new empty step.
82      **/

83     public InlineStep()
84     {
85         super(AntX.flow+"step");
86     }
87
88
89     /**
90      * Initializes a new CV-labeled empty step.
91      * @param iam CV-label (non-null)
92      **/

93     protected InlineStep(String JavaDoc iam)
94     {
95         super(iam);
96     }
97
98
99     /**
100      * Sets this step's name.
101      * @param name new name (non-null)
102      **/

103     public void setName(String JavaDoc name)
104     {
105         require_(name!=null,"setName- nonzro name");
106         m_name = name;
107     }
108
109
110     /**
111      * Returns this step's name; returns <i>null</i>
112      * if never set.
113      **/

114     public String JavaDoc getName()
115     {
116         return m_name;
117     }
118
119
120     /**
121      * Returns this step's name (can be the string "null").
122      **/

123     public String JavaDoc toString()
124     {
125         return getName();
126     }
127
128
129     /**
130      * Returns <i>true</i> if task is not another inline step
131      * definition. For now, cannot nest inline steps.
132      **/

133     protected boolean includeTask(TaskHandle taskH)
134     {
135         Task task = candidateTask(taskH,COI_);
136         return (task!=null) && !(task instanceof InlineStep);
137     }
138
139
140     /**
141      * No-op. Steps are explicitly run from StepLauncher's
142      * sending message to the step's {@linkplain #run run} method.
143      **/

144     public void execute()
145     {
146         verifyCanExecute_("execute");
147         //ssshhhhh....
148
}
149
150
151     /**
152      * Runs sub-tasks iff if/unless conditions met. Otherwise,
153      * behaves like the standard Ant <i>sequential</i> task.
154      **/

155     public void run() throws BuildException
156     {
157         verifyCanExecute_("run");
158
159         //NOTE: should there be a call to maybeConfigure here (ssmc)
160
//getRuntimeConfigurableWrapper().maybeConfigure(getProject(),true);
161

162         performNestedTasks();
163     }
164
165
166     /**
167      * Ensure this step has been named.
168      **/

169     protected void verifyCanExecute_(String JavaDoc calr)
170         throws BuildException
171     {
172         super.verifyCanExecute_(calr);
173
174         if (Tk.isWhitespace(getName())) {
175             String JavaDoc ermsg = uistrs().get("flow.task.needs.name",this.getTaskName());
176             log(ermsg, Project.MSG_ERR);
177             throw new BuildException(ermsg, getLocation());
178         }
179     }
180
181
182     private String JavaDoc m_name;//NB:required
183

184
185     /**
186      * Controls the amount of peek-under for UnknownElement placeholders
187      * nested inside task containers.
188      * @since JWare/AntX 0.4
189      **/

190     private static final Class JavaDoc[] COI_= {
191         InlineStep.class
192     };
193 }
194
195 /* end-of-InlineStep.java */
196
Popular Tags