KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > AnySet


1 /**
2  * $Id: AnySet.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;
30
31 import java.util.Iterator JavaDoc;
32
33 import org.apache.tools.ant.Project;
34
35 import com.idaremedia.antx.AntX;
36 import com.idaremedia.antx.ExportedProperties;
37 import com.idaremedia.antx.FlexString;
38 import com.idaremedia.antx.helpers.Strings;
39 import com.idaremedia.antx.helpers.Tk;
40 import com.idaremedia.antx.parameters.Handling;
41
42 /**
43  * Shortcut condition that returns <i>true</i> if at least one of the nested items is
44  * set in the project's environment. Empty sets always evaluate <i>false</i>.
45  * <p>
46  * <b>Example Usage:</b><pre>
47  * &lt;tally&gt;
48  * &lt;available classname="junit.framework.Assert" property="junit.present"/&gt;
49  * &lt;available classname="com.idaremedia.pet.PET" property="pet.present"/&gt;
50  * &lt;<b>isanyset</b> trueproperty="run.tests.enable"&gt;
51  * &lt;property name="junit.present/&gt;
52  * &lt;property name="pet.present/&gt;
53  * &lt;/isanyset&gt;
54  * &lt;/tally&gt;
55  * </pre>
56  *
57  * @since JWare/AntX 0.2
58  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
59  * @version 0.5
60  * @.safety single
61  * @.group api,infra
62  * @see AllSet
63  * @see NoneSet
64  **/

65
66 public class AnySet extends CheckSetCondition implements URIable
67 {
68     /**
69      * Initializes new AnySet condition. Will return <i>false</i>
70      * if evaluated and still empty.
71      **/

72     public AnySet()
73     {
74         super(AntX.rules+"anyset");
75     }
76
77
78
79     /**
80      * Initializes a filled-in AnySet instance.
81      * @param properties comma-delimited list of properties (non-null)
82      * @param P condition's project
83      **/

84     public AnySet(String JavaDoc properties,Project P)
85     {
86         super(AntX.rules+"anyset",properties,P);
87     }
88
89
90
91     /**
92      * Returns <i>true</i> if any of the condition's items are
93      * defined.
94      **/

95     public boolean eval()
96     {
97         verifyInProject_("eval");
98
99         final Project P = getProject();
100         boolean istrue = false;//=> empty=failure, noneset=failure
101

102         if (!getIncludes().isEmpty()) {
103
104             boolean ignoreWS = ignoreWhitespace();
105             boolean iffTrue = isTruesOnly();
106             boolean checkUnresolved = getMalformedHandling()==Handling.REJECT;
107             Iterator JavaDoc itr = getIncludesIterator();
108
109             while (itr.hasNext()) {
110                 FlexString xv = (FlexString)itr.next();
111                 String JavaDoc v = null;
112
113                 if (xv.isProperty() && checkUnresolved) {
114                     if (LocalPropertyExaminer.verifyProperty(P, xv)) {
115                         v = xv.getValue(P);
116                     }
117                 } else {
118                     v = xv.getValue(P);
119                 }
120                 if (v!=null) {
121                     if (ignoreWS && Tk.isWhitespace(v)) {
122                         v = null;
123                     } else if (iffTrue && Tk.string2PosBool(v)!=Boolean.TRUE) {
124                         v = null;
125                     }
126                 }
127                 if (v!=null) {
128                     istrue=true;
129                     break;
130                 }
131             }
132         }
133
134         if (istrue && getUpdateProperty()!=null) {
135             String JavaDoc what = Strings.TRUE;
136             if (isUpdateVariable()) {
137                 ExportedProperties.set(getUpdateProperty(),what);
138             } else {
139                 getProject().setNewProperty(getUpdateProperty(),what);
140             }
141         }
142
143         return istrue;
144     }
145
146
147
148     /**
149      * Sets this condition's list of properties as part of
150      * a value URI.
151      * @param fragment the value uri bits (non-null)
152      * @since JWare/AntX 0.5
153      */

154     public void xsetFromURI(String JavaDoc fragment)
155     {
156         xsetFromURIFragment(fragment);
157     }
158 }
159
160 /* end-of-AnySet.java */
161
Popular Tags