KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > construct > PerformTaskTask


1 /**
2  * $Id: PerformTaskTask.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2005 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.construct;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.UnknownElement;
34
35 import com.idaremedia.antx.AntX;
36 import com.idaremedia.antx.AssertableTask;
37 import com.idaremedia.antx.FixtureExaminer;
38 import com.idaremedia.antx.apis.Requester;
39 import com.idaremedia.antx.ownhelpers.TaskExaminer;
40 import com.idaremedia.antx.ownhelpers.UEContainerProxy;
41
42 /**
43  * Executes a previously cached task instance. The instance's reference is automatically
44  * removed from the project's reference table unless the <span class="src">keep</span>
45  * option is activated.
46  * <p/>
47  * <b>Example Usage:</b><pre>
48  * &lt;assign var="_junitinstance" value="${$random:string}"/&gt;
49  * &lt;createtask name="${$var:_junitinstance}"&gt;
50  * &lt;junit printsummary="yes" haltonfailure="yes"&gt;
51  * &#8230;
52  * &lt;/junit&gt;
53  * &lt;/createtask&gt;
54  * &#8230;<i>[alter task definition]</i>
55  * &lt;<b>performtask</b> name="${$var:_junitinstance}" keep="no"/&gt;
56  * &lt;unassign var="_junitinstance"/&gt;
57  * </pre>
58  *
59  * @since JWare/AntX 0.5
60  * @author ssmc, &copy;2005 <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 CreateTaskTask
65  **/

66
67 public final class PerformTaskTask extends AssertableTask
68 {
69     /**
70      * Initializesa new performtask task instance.
71      **/

72     public PerformTaskTask()
73     {
74         super(AntX.utilities+"PerformTaskTask:");
75     }
76
77
78
79     /**
80      * Tells this editor the reference id of the task under construction.
81      * This task should've been installed by the AntX task creator method.
82      * @param refId reference id of task under construction (non-null)
83      **/

84     public void setName(String JavaDoc refId)
85     {
86         require_(refId!=null,"setName- nonzro refid");
87         m_itemUC = (UEContainerProxy)FixtureExaminer.getReferencedObject(getProject(),
88             new Requester.ForComponent(this), refId, UEContainerProxy.class);
89         m_itemUCRefId = refId;
90     }
91
92
93
94     /**
95      * Tells this task whether it should clear the task under construction
96      * after it's been performed (the default). Only keep components that
97      * can be reset.
98      * @param keepIt <i>true</i> to keep task under construction
99      **/

100     public void setKeep(boolean keepIt)
101     {
102         m_purgeRefId = !keepIt;
103     }
104
105
106
107     /**
108      * Ensures the referenced item under construction's proxy is performed.
109      * If the proxy is to be kept, a <em>copy</em> of the proxy is performed;
110      * the original is left intact.
111      * @see #setKeep setKeep(&#8230;)
112      */

113     public void execute()
114     {
115         verifyCanExecute_("exec");
116
117         if (m_purgeRefId) {
118             getProject().getReferences().remove(m_itemUCRefId);
119             m_itemUCRefId = null;
120         }
121         UnknownElement ue = m_itemUC.getUE();
122         if (!m_purgeRefId) {
123             ue = TaskExaminer.copyUEProxy(ue,getProject(),null);
124         }
125         ue.setLocation(getLocation());
126         ue.perform();
127         m_itemUC = null;
128     }
129
130
131
132     /**
133      * Ensures we've been given a reference to a task to perform.
134      */

135     protected void verifyCanExecute_(String JavaDoc calr)
136     {
137         verifyInProject_(calr);
138
139         if (m_itemUC==null) {
140             String JavaDoc ermsg = uistrs().get("task.needs.name", getTaskName());
141             log(ermsg,Project.MSG_ERR);
142             throw new BuildException(ermsg,getLocation());
143         }
144     }
145
146
147     private UEContainerProxy m_itemUC;//item under construction (non-null after name known)
148
private String JavaDoc m_itemUCRefId;
149     private boolean m_purgeRefId=true;//Remove task under construction from project
150
}
151
152 /* end-of-PerformTaskTask.java */
Popular Tags