KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: OverlayParametersHelper.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.call;
30
31 import java.util.List JavaDoc;
32
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.Project;
35 import org.apache.tools.ant.Task;
36 import org.apache.tools.ant.TaskContainer;
37 import org.apache.tools.ant.taskdefs.Ant;
38 import org.apache.tools.ant.taskdefs.Property;
39 import org.apache.tools.ant.types.PropertySet;
40
41 import com.idaremedia.antx.AntX;
42 import com.idaremedia.antx.AntXFixture;
43 import com.idaremedia.antx.helpers.InnerNameValuePair;
44 import com.idaremedia.antx.helpers.Tk;
45 import com.idaremedia.antx.ownhelpers.ProjectDependentSkeleton;
46 import com.idaremedia.antx.solo.CopyReferenceTask;
47
48 /**
49  * Helper that interprets nested property and reference copying instructions
50  * for target callers. Originally part of the {@linkplain OnceTask}.
51  *
52  * @since JWare/AntX 0.4
53  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
54  * @version 0.5
55  * @.safety single
56  * @.group impl,helper
57  * @see CallerTask
58  **/

59
60 public final class OverlayParametersHelper extends ProjectDependentSkeleton
61 {
62     private static final String JavaDoc IAM_= AntX.utilities+"OverlayParametersHelper";
63
64
65     /**
66      * Initializes a new helper instance.
67      **/

68     public OverlayParametersHelper()
69     {
70     }
71
72
73     /**
74      * Initializes a new helper instance and associates
75      * w/ given project.
76      * @param project target project (non-null)
77      **/

78     public OverlayParametersHelper(Project project)
79     {
80         setProject(project);
81     }
82
83
84
85     /**
86      * Tells this overlay helper to defer parameter addition
87      * to another component.
88      * @param tc the thing to which we will defer
89      **/

90     public void addOverride(TaskContainer tc)
91     {
92         m_deferredTo = tc;
93     }
94
95
96
97     /**
98      * Returns this helper's active parameters list. Never returns
99      * <i>null</i> but can be empty list. Modifications to returned
100      * list are seen by this helper.
101      **/

102     protected List JavaDoc getParameters()
103     {
104         return m_paramsList;
105     }
106
107
108
109     /**
110      * Adds another parameter to this helper's active list. Item
111      * should be one of the accepted fixture controls (like a
112      * &lt;copyproperty&gt; or &lt;propertyset&gt;).
113      * @param item the configuration control (non-null)
114      **/

115     public void addParameter(Object JavaDoc item)
116     {
117         AntX.require_(item!=null,IAM_,"add- nonzro item");
118         if (m_deferredTo!=null && (item instanceof Task)) {
119             m_deferredTo.addTask((Task)item);
120         } else {
121             m_paramsList.add(item);//?possible leak?
122
}
123     }
124
125
126
127     /**
128      * Copies this helper's configuration instructions to the
129      * target caller's environment.
130      * @param helper the caller to configure (non-null)
131      * @throws BuildException if malformed instruction(s) found.
132      **/

133     public void transferParameters(TargetCaller helper)
134     {
135         List JavaDoc params = getParameters();
136         for (int i=0,N=params.size();i<N;i++) {
137             Object JavaDoc param = params.get(i);
138             if (param instanceof Property) {
139                 Property source = (Property)param;
140                 Property dest = helper.createProperty();
141                 Tk.transferProperty(source, dest);
142                 if (dest.getValue()==null) {
143                     String JavaDoc attr = "value|property|variable|reference";
144                     String JavaDoc ermsg = AntX.uistrs().get("task.needs.this.attr",
145                                                      source.getTaskName(),attr);
146                     source.log(ermsg,Project.MSG_ERR);
147                     throw new BuildException(ermsg,source.getLocation());
148                 }
149             }
150             else if (param instanceof PropertySet) {
151                 PropertySet dest = helper.createPropertySet();
152                 dest.addPropertyset((PropertySet)param);
153             }
154             else if (param instanceof CopyReferenceTask) {
155                 CopyReferenceTask source = (CopyReferenceTask)param;
156                 source.verifyExists(getProject(),null,null);
157                 Ant.Reference dest = helper.createReference();
158                 if (dest!=null) {
159                     dest.setRefId(source.getRefId());
160                     dest.setToRefid(source.getToRefId());
161                 } else {
162                     String JavaDoc warning = AntX.uistrs().
163                         get("taskset.nested.task.disallowed",
164                             "reference","call+mode=local");//?hack?
165
source.log(warning,Project.MSG_WARN);
166                 }
167             }
168             else if (param instanceof InnerNameValuePair) {
169                 if (helper instanceof ConfigurableCaller) {
170                     ConfigurableCaller cc = (ConfigurableCaller)helper;
171                     InnerNameValuePair source = (InnerNameValuePair)param;
172                     InnerNameValuePair dest = cc.createAttribute();
173                     dest.setNV(source.getName(),source.getValue());
174                 } else {
175                     InnerNameValuePair source = (InnerNameValuePair)param;
176                     source.verifyNamed();
177                     Property dest = helper.createProperty();
178                     dest.setName(source.getName());
179                     dest.setValue(source.getValue());
180                 }
181             }
182         }
183     }
184
185
186     private List JavaDoc m_paramsList= AntXFixture.newList();
187     private TaskContainer m_deferredTo;
188 }
189
190 /* end-of-OverlayParametersHelper.java */
191
Popular Tags