KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > solo > ShortHandHelper


1 /**
2  * $Id: ShortHandHelper.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.condition.solo;
30
31 import java.io.File JavaDoc;
32
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.ProjectComponent;
35 import org.apache.tools.ant.RuntimeConfigurable;
36 import org.apache.tools.ant.taskdefs.Available;
37 import org.apache.tools.ant.taskdefs.condition.Condition;
38 import org.apache.tools.ant.taskdefs.condition.Http;
39 import org.apache.tools.ant.taskdefs.condition.IsFalse;
40 import org.apache.tools.ant.taskdefs.condition.IsTrue;
41 import org.apache.tools.ant.taskdefs.condition.Os;
42 import org.apache.tools.ant.types.Path;
43 import org.apache.tools.ant.types.Reference;
44
45 import com.idaremedia.antx.AssertableProjectComponent;
46 import com.idaremedia.antx.StringEquality;
47
48 import com.idaremedia.antx.condition.AllSet;
49 import com.idaremedia.antx.condition.AnySet;
50 import com.idaremedia.antx.condition.FlexCondition;
51 import com.idaremedia.antx.condition.IsAntVersion;
52 import com.idaremedia.antx.condition.IsBoolean;
53 import com.idaremedia.antx.condition.IsNotSet;
54 import com.idaremedia.antx.condition.IsNotWhitespace;
55 import com.idaremedia.antx.condition.IsNumeric;
56 import com.idaremedia.antx.condition.IsReference;
57 import com.idaremedia.antx.condition.IsSet;
58 import com.idaremedia.antx.condition.IsSetTrue;
59 import com.idaremedia.antx.condition.NoneSet;
60 import com.idaremedia.antx.condition.ShortHandConditions;
61
62 import com.idaremedia.antx.helpers.Strings;
63 import com.idaremedia.antx.helpers.Tk;
64 import com.idaremedia.antx.parameters.Handling;
65 import com.idaremedia.antx.parameters.IgnoreCaseEnabled;
66 import com.idaremedia.antx.parameters.IgnoreWhitespaceEnabled;
67 import com.idaremedia.antx.parameters.IsA;
68 import com.idaremedia.antx.parameters.MalformedCheckEnabled;
69 import com.idaremedia.antx.parameters.SynonymsEnabled;
70 import com.idaremedia.antx.parameters.TrimEnabled;
71 import com.idaremedia.antx.parameters.ValueMatchEnabled;
72
73 /**
74  * Shareable implementation of the {@linkplain ShortHandConditions} interface. Public-facing
75  * rule tasks can implement the entire ShortHandConditions interface by delegating to
76  * an instance of this class. Implementation Note: the owning rule <em>must</em> synchronize
77  * this helper's project with its own; otherwise, none of the conditions created by this
78  * helper will function.
79  *
80  * @since JWare/AntX 0.2
81  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
82  * @version 0.5
83  * @.safety single
84  * @.group impl,helper
85  * @see AssertTask
86  * @see PreferTask
87  **/

88
89 public final class ShortHandHelper extends AssertableProjectComponent
90     implements ShortHandConditions, ValueMatchEnabled
91 {
92     /**
93      * Initializes a new condition short hand helper for specific
94      * rule.
95      * @param rule owning rule (non-null)
96      **/

97     public ShortHandHelper(BooleanRule rule)
98     {
99         super(rule.cvlabel_());
100         m_rule = rule;
101     }
102
103
104     /**
105      * Initializes a new CV-labeled condition short hand helper
106      * for specific rule
107      * @param iam CV-label (non-null)
108      * @param rule owning rule (non-null)
109      **/

110     public ShortHandHelper(String JavaDoc iam, BooleanRule rule)
111     {
112         super(iam);
113         require_(rule!=null,"ctor- nonzro rul");
114         m_rule = rule;
115     }
116
117
118     /**
119      * Returns the rule with which this helper is associated.
120      * Never returns <i>null</i>; defined at construction.
121      **/

122     public BooleanRule getOwningRule()
123     {
124         return m_rule;
125     }
126
127
128     /**
129      * Returns <i>true</i> if this short-hand helper has been activated
130      * with a short-hand condition. If <i>true</i> owning rule will allow
131      * only the short-hand root condition at evaluation time.
132      **/

133     public final boolean isActivated()
134     {
135         return m_isActivated;
136     }
137
138
139     /**
140      * Marks this helper as activated into short-hand (single
141      * condition) mode.
142      * @param c inlined conditon (root condition)
143      * @param who identifier used in error message if already activated
144      **/

145     public final void activateCondition(Condition c, String JavaDoc who)
146     {
147         boolean ok= m_rule.xaddRootCondition(c);
148         ensure_(ok,who+BooleanRule.ONLY_ONE);
149         applyPendingModifiers(c);
150         m_isActivated = true; //Latch flipped
151
}
152
153
154     /**
155      * Returns "true" of boolean is <i>true</i>; otherwise returns
156      * "false".
157      **/

158     private static final String JavaDoc tf(boolean b)
159     {
160         return b ? Strings.TRUE : Strings.FALSE;
161     }
162
163
164 // ---------------------------------------------------------------------------------------
165
// Latched literal-based conditions inherited from Ant:
166
// ---------------------------------------------------------------------------------------
167

168     public void setIsTrue(String JavaDoc value)
169     {
170         IsTrue t= new IsTrue();
171         t.setProject(getProject());
172         Boolean JavaDoc B = Tk.string2PosBool(value);
173         t.setValue(B==null ? false : B.booleanValue());
174         activateCondition(t,"setIsTrue");
175     }
176
177
178     public void setIsFalse(String JavaDoc value)
179     {
180         IsFalse f= new IsFalse();
181         f.setProject(getProject());
182         Boolean JavaDoc B = Tk.string2NegBool(value);
183         f.setValue(B==null ? false : B.booleanValue());
184         activateCondition(f,"setIsFalse");
185     }
186
187
188     public void setOSFamily(String JavaDoc family)
189     {
190         Os t= new Os(family);
191         activateCondition(t,"setOSFamily");
192     }
193
194
195     public void setOS(String JavaDoc selector)
196     {
197         IsOS t= new IsOS(getProject());
198         t.setSelector(selector);
199         activateCondition(t,"setOS");
200     }
201
202
203     public void setHttpAlive(String JavaDoc url)
204     {
205         Http t= new Http();
206         t.setProject(getProject());
207         t.setUrl(url);
208         activateCondition(t,"setHttpAlive");
209     }
210
211
212     public void setIsFile(File JavaDoc file)
213     {
214         Available t= getIsAvailableCondition();
215         t.setFile(file);
216         Available.FileDir filetype= new Available.FileDir();
217         Tk.initEnum(filetype,"file");
218         t.setType(filetype);
219         activateCondition(t,"setIsFile");
220     }
221
222
223     public void setIsDirectory(File JavaDoc dir)
224     {
225         Available t= getIsAvailableCondition();
226         t.setFile(dir);
227         Available.FileDir dirtype= new Available.FileDir();
228         Tk.initEnum(dirtype,"dir");
229         t.setType(dirtype);
230         activateCondition(t,"setIsDirectory");
231     }
232
233
234     public void setFilepath(Path filp)
235     {
236         m_rule.checkModify("setFilpath");
237         Available t= getIsAvailableCondition();
238         t.setFilepath(filp);
239     }
240
241
242     public void setIsResource(String JavaDoc resource)
243     {
244         Available t= getIsAvailableCondition();
245         t.setResource(resource);
246         activateCondition(t,"setIsResource");
247     }
248
249
250     public void setIsClass(String JavaDoc classname)
251     {
252         Available t= getIsAvailableCondition();
253         t.setClassname(classname);
254         activateCondition(t,"setIsClass");
255     }
256
257
258     public void setClasspath(Path clsp)
259     {
260         m_rule.checkModify("setClazpath");
261         Available t= getIsAvailableCondition();
262         t.setClasspath(clsp);
263     }
264
265
266     public void setClasspathRef(Reference cpr)
267     {
268         m_rule.checkModify("setClzpath");
269         Available t= getIsAvailableCondition();
270         t.setClasspathRef(cpr);
271     }
272
273
274     public void setSystemClasses(boolean included)
275     {
276         m_rule.checkModify("setSystemClazes");
277         Available t= getIsAvailableCondition();
278         t.setIgnoresystemclasses(!included);
279     }
280
281 // ---------------------------------------------------------------------------------------
282
// Latched literal-based <antversion> variants:
283
// ---------------------------------------------------------------------------------------
284

285     /**
286      * Defines short hand &lt;antversion is="&#8230;"/&gt;
287      * condition.
288      * @since JWare/AntX 0.4
289      **/

290     public void setAntIs(String JavaDoc version)
291     {
292         IsAntVersion t= new IsAntVersion();
293         t.setProject(getProject());
294         t.setIs(version);
295         activateCondition(t,"setAntIs");
296     }
297
298     /**
299      * Defines short hand &lt;antversion like="&#8230;"/&gt;
300      * condition.
301      * @since JWare/AntX 0.4
302      **/

303     public void setAntLike(String JavaDoc pattern)
304     {
305         IsAntVersion t= new IsAntVersion();
306         t.setProject(getProject());
307         t.setLike(pattern);
308         activateCondition(t,"setAntLike");
309     }
310
311
312 // ---------------------------------------------------------------------------------------
313
// Literal-based unless overridden with an 'isa' modifier:
314
// ---------------------------------------------------------------------------------------
315

316     public void setIsBoolean(String JavaDoc value)
317     {
318         IsBoolean t= (IsBoolean)getHalfBakedObject(IsBoolean.class);
319         t.setValue(value);
320         activateCondition(t,"setIsBoolean");
321     }
322
323
324     public void setIsNotWhitespace(String JavaDoc value)
325     {
326         IsNotWhitespace t= (IsNotWhitespace)getHalfBakedObject(IsNotWhitespace.class);
327         t.setValue(value);
328         activateCondition(t,"setIsNotWSpc");
329     }
330
331
332     public void setIsNumeric(String JavaDoc value)
333     {
334         IsNumeric t= (IsNumeric)getHalfBakedObject(IsNumeric.class);
335         t.setValue(value);
336         activateCondition(t,"setIsNumeric");
337     }
338
339
340     /**
341      * 'greather-than-or-equal' modifier for a short-hand
342      * 'isnumeric' condition.
343      * @since JWare/AntX 0.3
344      **/

345     public void setGT(String JavaDoc gt)
346     {
347         m_rule.checkModify("setGT");
348         IsNumeric t = (IsNumeric)getHalfBakedObject("gt",gt);
349         if (t!=null) {
350             t.setGT(Tk.longFrom(gt,Tk.NO_NUM));
351         }
352     }
353
354
355     /**
356      * 'greather-than' modifier for a short-hand 'isnumeric'
357      * condition.
358      * @since JWare/AntX 0.3
359      **/

360     public void setGTE(String JavaDoc gte)
361     {
362         m_rule.checkModify("setGTE");
363         IsNumeric t = (IsNumeric)getHalfBakedObject("gte",gte);
364         if (t!=null) {
365             t.setGTE(Tk.longFrom(gte,Tk.NO_NUM));
366         }
367     }
368
369
370     /**
371      * 'less-than' modifier for a short-hand 'isnumeric' condition.
372      * @since JWare/AntX 0.3
373      **/

374     public void setLT(String JavaDoc lt)
375     {
376         m_rule.checkModify("setLT");
377         IsNumeric t = (IsNumeric)getHalfBakedObject("lt",lt);
378         if (t!=null) {
379             t.setLT(Tk.longFrom(lt,Tk.NO_NUM));
380         }
381     }
382
383
384     /**
385      * 'less-than-or-equal' modifier for a short-hand 'isnumeric'
386      * condition.
387      * @since JWare/AntX 0.3
388      **/

389     public void setLTE(String JavaDoc lte)
390     {
391         m_rule.checkModify("setLTE");
392         IsNumeric t = (IsNumeric)getHalfBakedObject("lte",lte);
393         if (t!=null) {
394             t.setLTE(Tk.longFrom(lte,Tk.NO_NUM));
395         }
396     }
397
398 // ---------------------------------------------------------------------------------------
399
// Property-based unless overridden with an 'isa' modifier:
400
// ---------------------------------------------------------------------------------------
401

402     public void setIsSet(String JavaDoc property)
403     {
404         IsSet t= (IsSet)getHalfBakedObject(IsSet.class);
405         t.setProperty(property);
406         activateCondition(t,"setIsSet");
407     }
408
409
410     public void setIsSetTrue(String JavaDoc property)
411     {
412         IsSetTrue t= (IsSetTrue)getHalfBakedObject(IsSetTrue.class);
413         t.setProperty(property);
414         activateCondition(t,"setIsSetTrue");
415     }
416
417
418     public void setIsNotSet(String JavaDoc property)
419     {
420         IsNotSet t= (IsNotSet)getHalfBakedObject(IsNotSet.class);
421         t.setProperty(property);
422         activateCondition(t,"setIsNotSet");
423     }
424
425
426 // ---------------------------------------------------------------------------------------
427
// Latched variable-based <isset>,<isnotset>,<issettrue>:
428
// ---------------------------------------------------------------------------------------
429

430     public void setVarSet(String JavaDoc variable)
431     {
432         IsSet t= (IsSet)getHalfBakedObject(IsSet.class);
433         t.setVariable(variable);
434         disableIsA();
435         activateCondition(t,"setVarSet");
436     }
437
438
439     public void setVarSetTrue(String JavaDoc variable)
440     {
441         IsSetTrue t= (IsSetTrue)getHalfBakedObject(IsSetTrue.class);
442         t.setVariable(variable);
443         disableIsA();
444         activateCondition(t,"setVarSetTrue");
445     }
446
447
448     public void setVarNotSet(String JavaDoc variable)
449     {
450         IsNotSet t= (IsNotSet)getHalfBakedObject(IsNotSet.class);
451         t.setVariable(variable);
452         disableIsA();
453         activateCondition(t,"setVarNotSet");
454     }
455
456
457 // ---------------------------------------------------------------------------------------
458
// Latched reference-based <isreference>:
459
// ---------------------------------------------------------------------------------------
460

461
462     /**
463      * Parameter short-hand for a 'isreference' condition.
464      **/

465     public void setIsRef(String JavaDoc refId)
466     {
467         IsReference t= (IsReference)getHalfBakedObject(IsReference.class);
468         t.setName(refId);
469         activateCondition(t,"setIsRef");
470     }
471
472
473     /**
474      * Parameter short-hand for a &lt;not&gt;'isreference' condition.
475      * @since JWare/AntX 0.5
476      **/

477     public void setIsNotRef(String JavaDoc refId)
478     {
479         IsReference t= (IsReference)getHalfBakedObject(IsReference.class);
480         t.setName(refId);
481         t.xsetNoExist(true);
482         activateCondition(t,"setIsNotRef");
483     }
484
485
486     /**
487      * Modifier for a short-hand for a 'isreference' condition.
488      **/

489     public void setClassName(String JavaDoc clzId)
490     {
491         m_rule.checkModify("setRefClaz");
492         IsReference ref= getIsReferenceCondition();
493         ref.setClassName(clzId);
494     }
495
496
497     /**
498      * Modifier for a short-hand for a 'isreference' condition.
499      **/

500     public void setIsKindOf(boolean isKindOf)
501     {
502         m_rule.checkModify("setRefKndOf");
503         IsReference ref= getIsReferenceCondition();
504         ref.setKindOf(isKindOf);
505     }
506
507
508 // ---------------------------------------------------------------------------------------
509
// Latched properties-based <allset>,<allsetLike>,<noneset>,<anyset>:
510
// ---------------------------------------------------------------------------------------
511

512     public void setAnySet(String JavaDoc properties)
513     {
514         require_(!Tk.isWhitespace(properties),"setAnySet- propertylist");
515         AnySet t= new AnySet(properties,getProject());
516         setHalfBakedObject(t);
517         activateCondition(t,"setAnySet");
518     }
519
520
521     public void setAllSet(String JavaDoc properties)
522     {
523         require_(!Tk.isWhitespace(properties),"setAllSet- propertylist");
524         AllSet t= new AllSet(properties,getProject());
525         setHalfBakedObject(t);
526         activateCondition(t,"setAllSet");
527     }
528
529
530     /**
531      * Like {@linkplain #setAllSet setAllSet()} but against the set
532      * of existing script properties.
533      * @param pattern the filtering pattern
534      * @since JWare/AntX 0.4
535      **/

536     public void setAllSetLike(String JavaDoc pattern)
537     {
538         require_(!Tk.isWhitespace(pattern),"setAllSetLike- pattern");
539         AllSet t= new AllSet();
540         t.setProject(getProject());
541         t.setPropertiesLike(pattern);
542         setHalfBakedObject(t);
543         activateCondition(t,"setAllSetLike");
544     }
545
546
547     public void setNoneSet(String JavaDoc properties)
548     {
549         require_(!Tk.isWhitespace(properties),"setNoneSet- propertylist");
550         NoneSet t= new NoneSet(properties,getProject());
551         setHalfBakedObject(t);
552         activateCondition(t,"setNoneSet");
553     }
554
555
556 // ---------------------------------------------------------------------------------------
557
// Shorthand (flex) string comparision condition and parameters:
558
// ---------------------------------------------------------------------------------------
559

560     public void setMatches(String JavaDoc pattern)
561     {
562         StringEquality t= getEqualityCondition();
563         t.setMatch(pattern);
564         activateCondition(t,"setMatches");
565     }
566
567
568     public final void setMatch(String JavaDoc pattern)
569     {
570         setMatches(pattern);
571     }
572
573
574     public void setVariable(String JavaDoc variable)
575     {
576         m_rule.checkModify("setStrEqVar");
577         StringEquality eqt = getEqualityCondition();
578         eqt.setUnknownArg(variable);
579         eqt.getUnknownValueGetter().setIsExported(true);
580     }
581
582
583     public void setProperty(String JavaDoc property)
584     {
585         m_rule.checkModify("setStrEqProp");
586         StringEquality eqt = getEqualityCondition();
587         eqt.setUnknownArg(property);
588         eqt.getUnknownValueGetter().setIsProperty(true);
589     }
590
591
592     public void setReference(String JavaDoc reference)
593     {
594         m_rule.checkModify("setStrEqRef");
595         StringEquality eqt = getEqualityCondition();
596         eqt.setUnknownArg(reference);
597         eqt.getUnknownValueGetter().setIsReference(true);
598     }
599
600
601     public void setValue(String JavaDoc value)
602     {
603         m_rule.checkModify("setStrEqValu");
604         Object JavaDoc t = getHalfBakedObject("value",value);
605         if (t!=null) {
606             ((ValueMatchEnabled)t).setValue(value);
607         }
608     }
609
610 // ---------------------------------------------------------------------------------------
611
// Multiple-condition options (stuf that applies to more than one condition):
612
// ---------------------------------------------------------------------------------------
613

614     public void setSynonyms(boolean allowAll)
615     {
616         m_rule.checkModify("setSynonyms");
617         Object JavaDoc t = getHalfBakedObject("synonyms",tf(allowAll));
618         if (t!=null) {
619             ((SynonymsEnabled)t).setSynonyms(allowAll);
620         }
621     }
622
623
624     public boolean allowSynonyms()
625     {
626         if (getHalfBakedObject() instanceof SynonymsEnabled) {
627             return ((SynonymsEnabled)getHalfBakedObject()).allowSynonyms();
628         }
629         return true;//Ant-default
630
}
631
632
633     public void setIgnoreCase(boolean ignore)
634     {
635         m_rule.checkModify("setIgnoreCase");
636         Object JavaDoc t = getHalfBakedObject("ignorecase",tf(ignore));
637         if (t!=null) {
638             ((IgnoreCaseEnabled)t).setIgnoreCase(ignore);
639         }
640     }
641
642
643     public boolean isIgnoreCase()
644     {
645         if (getHalfBakedObject() instanceof IgnoreCaseEnabled) {
646             return ((IgnoreCaseEnabled)
647                     getHalfBakedObject()).isIgnoreCase();
648         }
649         return false;
650     }
651
652
653     public void setTrim(boolean trim)
654     {
655         m_rule.checkModify("setTrim");
656         Object JavaDoc t = getHalfBakedObject("trim",tf(trim));
657         if (t!=null) {
658             ((TrimEnabled)t).setTrim(trim);
659         }
660     }
661
662
663     public boolean willTrim()
664     {
665         if (getHalfBakedObject() instanceof TrimEnabled) {
666             return ((TrimEnabled)getHalfBakedObject()).willTrim();
667         }
668         return false;
669     }
670
671
672     public void setWhitespace(Handling response)
673     {
674         m_rule.checkModify("setWhtSpc");
675         Object JavaDoc t = getHalfBakedObject("whitespace",response.getValue());
676         if (t!=null) {
677             ((IgnoreWhitespaceEnabled)t).setWhitespace(response);
678         }
679     }
680
681
682     public boolean ignoreWhitespace()
683     {
684         if (getHalfBakedObject() instanceof IgnoreWhitespaceEnabled) {
685             return ((IgnoreWhitespaceEnabled)
686                     getHalfBakedObject()).ignoreWhitespace();
687         }
688         return false;
689     }
690
691
692     public void setMalformed(Handling response)
693     {
694         m_rule.checkModify("setMalformd");
695         Object JavaDoc t = getHalfBakedObject("malformed",response.getValue());
696         if (t!=null) {
697             ((MalformedCheckEnabled)t).setMalformed(response);
698         }
699     }
700
701
702     public Handling getMalformedHandling()
703     {
704         if (getHalfBakedObject() instanceof MalformedCheckEnabled) {
705             return ((MalformedCheckEnabled)
706                     getHalfBakedObject()).getMalformedHandling();
707         }
708         return null;
709     }
710
711
712 // ---------------------------------------------------------------------------------------
713
// Type cast for flexible conditions that support value,property,variable,references:
714
// ---------------------------------------------------------------------------------------
715

716     /**
717      * Tells this helper that the 'isa' option is no longer a valid
718      * option. Used if the type is fixed by the shorthand condition's name
719      * like "<i>varnotset</i>". Latch operation; once set cannot be unset.
720      **/

721     public void disableIsA()
722     {
723         m_disableIsA=true;
724     }
725
726
727     /**
728      * Returns <i>true</i> if the 'isa' option is no longer a valid
729      * choice.
730      **/

731     public boolean noIsA()
732     {
733         return m_disableIsA;
734     }
735
736
737     /**
738      * Setter method to type-cast an inlined flex condition. Flex
739      * conditions are usually defaulted to literal values if never
740      * type-cast. This 'isa' parameter is unique to our rule tasks--
741      * it is a condensed version of the explicit FlexValueSupport
742      * interface. Soooo, we cannot put it with the regular "delayed
743      * modifiers" configurable; we need to interpret it again later.
744      * @param isa the explicit type-cast (non-null)
745      **/

746     public void setIsA(IsA isa)
747     {
748         m_rule.checkModify("setIsA");
749
750         require_(!noIsA(),"setIsA- Flex condition");
751
752         Object JavaDoc t = getHalfBakedObject();
753         if (t==null && m_delayedIsA==null) {//Wait-for-target-c!
754
m_delayedIsA = new IsAHandle(isa);
755             return;
756         }
757
758         require_((t instanceof FlexCondition),"setIsA- Flex condition");
759
760         FlexCondition c = (FlexCondition)t;
761
762         switch (isa.getIndex()) {
763             case IsA.PROPERTY_INDEX: {
764                 c.setProperty(c.getFlexValue());
765                 break;
766             }
767             case IsA.VARIABLE_INDEX: {
768                 c.setVariable(c.getFlexValue());
769                 break;
770             }
771             case IsA.REFERENCE_INDEX:{
772                 c.setReference(c.getFlexValue());
773                 break;
774             }
775             default: {
776                 c.setLiteral(c.getFlexValue());
777             }
778         }
779     }
780
781 // ---------------------------------------------------------------------------------------
782
// Multiple-option inlined attributes:
783
// ---------------------------------------------------------------------------------------
784

785     /**
786      * Getter/factory-method for a multi-option inlined condition.
787      * This method create a new condition instance if one does not
788      * already exist. Note that the generated condition must be a
789      * self-validating entity because this rule won't be able to tell
790      * if the condition is "fully baked" before trying to use it
791      *(hence the colorful name). Pending modifiers will be applied
792      * when a new condition is activated.
793      * @see #activateCondition activateCondition
794      **/

795     public final Object JavaDoc getHalfBakedObject(Class JavaDoc ofClass)
796     {
797         if (m_halfbakedObject==null) {
798             try {
799                 m_halfbakedObject = ofClass.newInstance();
800             } catch(Exception JavaDoc anyX) {
801                 throw new BuildException(anyX,m_rule.getLocation());
802             }
803             if (m_halfbakedObject instanceof ProjectComponent) {
804                 ((ProjectComponent)m_halfbakedObject).setProject(getProject());
805             }
806         }
807         else {
808             require_(ofClass.isInstance(m_halfbakedObject),
809                      "construction of a single condition-type inline");
810         }
811         return m_halfbakedObject;
812     }
813
814
815     /**
816      * Returns raw underlying half-baked condition as-is. Will return
817      * <i>null</i> if short hand condition not yet created.
818      **/

819     public final Object JavaDoc getHalfBakedObject()
820     {
821         return m_halfbakedObject;
822     }
823
824
825     /** Internal method that automatically inserts the modifier to the
826      * pending list if there is no active condition.
827      * @since JWare/AntX 0.4
828      **/

829     private Object JavaDoc getHalfBakedObject(String JavaDoc attr, String JavaDoc saved)
830     {
831         Object JavaDoc t = getHalfBakedObject();
832         if (t==null) {
833             getPendingModifiers().setAttribute(attr,saved);
834         }
835         return t;
836     }
837
838
839     /**
840      * Initializes the raw underlying half-baked object directly. Use
841      * when target condition is created outside our getter/factory
842      * API.
843      **/

844     private void setHalfBakedObject(Object JavaDoc object)
845     {
846         m_halfbakedObject = object;
847     }
848
849
850     /**
851      * Getter/factory method for an inlined string comparision
852      * condition like <span class="src">equals</span> or
853      * <span class="src">matches</span>. Never returns <i>null</i>.
854      **/

855     StringEquality getEqualityCondition()
856     {
857         return (StringEquality)getHalfBakedObject(StringEquality.class);
858     }
859
860
861     /**
862      * Getter/factory method for an inlined is-available
863      * condition like <span class="src">isfile</span> or
864      * <span class="src">isresource</span>. Never returns <i>null</i>.
865      **/

866     private Available getIsAvailableCondition()
867     {
868         return (Available)getHalfBakedObject(Available.class);
869     }
870
871
872     /**
873      * Getter/factory method for an inlined
874      * <span class="src">isreference</span> condition. Never returns
875      * <i>null</i>.
876      **/

877     private IsReference getIsReferenceCondition()
878     {
879         return (IsReference)getHalfBakedObject(IsReference.class);
880     }
881
882
883 // ---------------------------------------------------------------------------------------
884
// MacroDef+PreDef Support: Handle reordered parameter setting (Ant1.6)
885
// ---------------------------------------------------------------------------------------
886

887     private static final Object JavaDoc NOTHIN= new int[0];
888
889
890     /**
891      * Returns <i>true</i> if this helper has parameters
892      * configuration that is pending. Parameter application can
893      * be delayed when the Ant runtime reorders the parsed
894      * ordering of item attributes (like MacroDef does).
895      * @since JWare/AntX 0.4
896      **/

897     public final boolean havePendingModifiers()
898     {
899         return m_delayedParams!=null || m_delayedIsA!=null;
900     }
901
902
903     /**
904      * Applies any pending parameter configuration to given test.
905      * Also clears the set of pending items. No-op if no pending
906      * operations.
907      * @since JWare/AntX 0.4
908      **/

909     public final void applyPendingModifiers(Object JavaDoc test)
910     {
911         require_(test!=null,"applyMods- nonzro condition");
912         if (m_delayedParams!=null) {
913             m_delayedParams.setProxy(test);
914             RuntimeConfigurable helper = m_delayedParams;
915             m_delayedParams = null;
916             helper.reconfigure(getProject());
917             helper = null;
918         }
919         if (m_delayedIsA!=null) {
920             setIsA(m_delayedIsA.get());
921             m_delayedIsA = null;
922         }
923     }
924
925
926     /**
927      * Returns a holder for all modifiers that must wait for their
928      * target condition to be created. Never returns <i>null</i>.
929      * @see #applyPendingModifiers applyPendingModifiers
930      * @since JWare/AntX 0.4
931      **/

932     private RuntimeConfigurable getPendingModifiers()
933     {
934         if (m_delayedParams==null) {
935             m_delayedParams = new RuntimeConfigurable(NOTHIN,"shh");
936         }
937         return m_delayedParams;
938     }
939
940
941 // ---------------------------------------------------------------------------------------
942
// Seekrit Members:
943
// ---------------------------------------------------------------------------------------
944

945     private Object JavaDoc m_halfbakedObject;//NB:to support multi-option inlined conditons
946
private final BooleanRule m_rule;
947     private boolean m_disableIsA;//NB:latch off; allow by default
948
private boolean m_isActivated;//NB:false=>no short-hand condition has been set
949
private RuntimeConfigurable m_delayedParams;//NB:if non-null need to apply
950
private IsAHandle m_delayedIsA;//NB:if non-null need to apply
951
}
952
953 /* end-of-ShortHandHelper.java */
954
Popular Tags