KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > match > MatchString


1 /**
2  * $Id: MatchString.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.flowcontrol.match;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.types.Reference;
34
35 import com.idaremedia.antx.FlexString;
36 import com.idaremedia.antx.StringEquality;
37 import com.idaremedia.antx.parameters.IgnoreCaseEnabled;
38 import com.idaremedia.antx.parameters.TrimEnabled;
39
40 /**
41  * Superclass of the AntX equals and like choice tasks. By default works for <i>equals</i>
42  * comparision with trim and case-sensitivity variants.
43  *
44  * @since JWare/AntX 0.1 (Pushed down from ChoiceTask JWare/AntX 0.5)
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  * @see SwitchTask
50  **/

51
52 public abstract class MatchString extends ChoiceTask
53     implements IgnoreCaseEnabled, TrimEnabled
54 {
55     /**
56      * Initializes new string choice task.
57      **/

58     protected MatchString(String JavaDoc iam)
59     {
60         super(iam);
61     }
62
63
64
65     /**
66      * Initializes new string choice task with custom delay configuration.
67      * @param iam CV-label
68      * @param delayConfiguration <i>true</i> if delay nested task configuration
69      **/

70     protected MatchString(String JavaDoc iam, boolean delayConfiguration)
71     {
72         super(iam,delayConfiguration);
73     }
74
75
76
77     /**
78      * Initializes the enclosing project of this component. Updates
79      * any internal project-components too.
80      **/

81     public void setProject(Project P)
82     {
83         super.setProject(P);
84         getTest().setProject(P);
85     }
86
87
88
89     /**
90      * Returns this choice task's underlying StringEquality test.
91      * Never returns <i>null</i>.
92      **/

93     protected StringEquality getTest()
94     {
95         return m_eqTest;
96     }
97
98
99
100     /**
101      * Returns this choice's underlying match value (as-is). The returned
102      * value can represent a literal value, a property's name, a variable's
103      * name, or a reference's identifier.
104      * @since JWare/AntX 0.2
105      **/

106     public final String JavaDoc getFlexValue()
107     {
108         return getTest().getKnownValueGetter().get();
109     }
110
111
112
113     /**
114      * Sets the match value for this choice task. How the incoming value
115      * is actually used is up to the concrete choice subclass.
116      * @param value the new choice (the known)
117      **/

118     public void setValue(String JavaDoc value)
119     {
120         require_(value!=null,"setvalu- nonzro valu");
121         getTest().setKnownArg(value,false);
122     }
123
124
125
126     /**
127      * Returns this choice's match value (as set). Will return <i>null</i>
128      * if never set or underlying value is not a literal string (used as-is).
129      **/

130     public final String JavaDoc getValue()
131     {
132         FlexString eqT= getTest().getKnownValueGetter();
133         return eqT.isLiteral() ? eqT.get() : null;
134     }
135
136
137
138     /**
139      * Sets the match property for this choice task. The property will be
140      * read at the comparision time; how the returned value is used in the
141      * comparision is up to the specific choice subclass.
142      * @param property the property containing the choice (the known-later)
143      **/

144     public void setProperty(String JavaDoc property)
145     {
146         require_(property!=null,"setprop- nonzro name");
147         getTest().setKnownArg(property,true);
148     }
149
150
151
152     /**
153      * Returns this choice's property name (as set). Will return <i>null</i>
154      * if never set or the underlying value is not a property name.
155      **/

156     public final String JavaDoc getProperty()
157     {
158         FlexString eqT= getTest().getKnownValueGetter();
159         return eqT.isProperty() ? eqT.get() : null;
160     }
161
162
163
164     /**
165      * Sets the match variable for this choice task. The variable will be
166      * read at the comparision time; how the returned value is used in the
167      * comparision is up to the specific choice subclass.
168      * @param variable the variable containing the choice (the known-later)
169      * @since JWare/AntX 0.2
170      **/

171     public void setVariable(String JavaDoc variable)
172     {
173         require_(variable!=null,"setVar- nonzro name");
174         getTest().setKnownArg(variable,false);
175         getTest().getKnownValueGetter().setIsExported(true);
176     }
177
178
179
180     /**
181      * Returns this choice's variable name (as set). Will return <i>null</i>
182      * if never set or the underlying value is not a variable's name.
183      * @since JWare/AntX 0.2
184      **/

185     public final String JavaDoc getVariable()
186     {
187         FlexString eqT= getTest().getKnownValueGetter();
188         return eqT.isExported() ? eqT.get() : null;
189     }
190
191
192
193     /**
194      * Sets the match reference for this choice task. The reference will be
195      * read at the comparision time; how the returned value is used in the
196      * comparision is up to the specific choice subclass.
197      * @param refid the reference containing the choice (the known-later)
198      * @since JWare/AntX 0.2
199      **/

200     public void setReference(String JavaDoc refid)
201     {
202         require_(refid!=null,"setRef- nonzro refid");
203         getTest().setKnownArg(refid,false);
204         getTest().getKnownValueGetter().setIsReference(true);
205     }
206
207
208
209     /**
210      * Returns this choice's reference identifier (as set). Will return <i>null</i>
211      * if never set or the underlying value is not a reference name.
212      * @since JWare/AntX 0.2
213      **/

214     public final String JavaDoc getReference()
215     {
216         FlexString eqT= getTest().getKnownValueGetter();
217         return eqT.isReference() ? eqT.get() : null;
218     }
219
220
221
222     /**
223      * Returns <i>true</i> if this choice has not been defined properly.
224      **/

225     public final boolean isUndefined()
226     {
227         return getTest().getKnownValueGetter().isUndefined();
228     }
229
230
231
232     /**
233      * Returns the actual value used in this choice's comparision. Returns
234      * <i>null</i> if value never defined or determined value doesn't
235      * exist; for example, if the named reference doesn't exist in project.
236      **/

237     public final String JavaDoc getVUT()
238     {
239         return getTest().getKnownValue();
240     }
241
242
243
244     /**
245      * Set the case-sensitivity of the comparision function. This setting
246      * applies to both the known and unknown values.
247      * @param ignore <i>true</i> if comparision should be case insensitive
248      **/

249     public void setIgnoreCase(boolean ignore)
250     {
251         getTest().setIgnoreCase(ignore);
252     }
253
254
255
256     /**
257      * Returns <i>true</i> if a case insensitive comparision will be done.
258      **/

259     public final boolean isIgnoreCase()
260     {
261         return getTest().isIgnoreCase();
262     }
263
264
265
266     /**
267      * Set the will-trim option of the comparision condition.
268      * @param trim <i>true</i> if strings should be trimmed before
269      * comparision
270      **/

271     public void setTrim(boolean trim)
272     {
273         getTest().setTrim(trim);
274     }
275
276
277
278     /**
279      * Returns <i>true</i> if both arguments will be trimmed before
280      * comparision.
281      **/

282     public final boolean willTrim()
283     {
284         return getTest().willTrim();
285     }
286
287
288
289     /**
290      * Evaluates this choice's condition for a hit. Returns
291      * <i>true</i> if this choice's criteria are met by the incoming
292      * value under consideration.
293      * @param vut value under test (vut-vut)
294      * @param context [unused] evaluation context
295      * @throws BuildException if this task isn't nested properly
296      **/

297     public boolean eval(String JavaDoc vut, Reference context) throws BuildException
298     {
299         verifyCanExecute_("eval");
300
301         if (vut==null) {
302             return false;//never matches
303
}
304
305         StringEquality test= getTest();
306
307         test.setUnknownArg(vut);
308
309         return test.eval();
310     }
311
312
313
314     private StringEquality m_eqTest = new StringEquality();
315 }
316
317 /* end-of-MatchString.java */
318
Popular Tags