KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: IsSet.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003-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 com.idaremedia.antx.parameters.Handling;
32 import com.idaremedia.antx.parameters.IgnoreWhitespaceEnabled;
33 import com.idaremedia.antx.parameters.IsA;
34 import com.idaremedia.antx.parameters.MalformedCheckEnabled;
35
36 /**
37  * Simple Is-Set condition check that supports references and AntX variables. Example
38  * usage: <pre>
39  * &lt;isset property="jdk14.present"/&gt;
40  * &lt;isset property="module.id" whitespace="reject"/&gt;
41  * &lt;isset variable="__loopcount"/&gt;
42  * &lt;isset reference="build.num"/&gt;
43  * &lt;isset property="build.ROOT" whitespace="reject" malformed="reject"/&gt;
44  *</pre>
45  *
46  * @since JWare/AntX 0.2
47  * @author ssmc, &copy;2003-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
48  * @version 0.5
49  * @.safety single
50  * @.group api,infra
51  **/

52
53 public class IsSet extends SimpleFlexCondition
54     implements IgnoreWhitespaceEnabled, MalformedCheckEnabled
55 {
56     /**
57      * Initializes new IsSet condition. A value type must be
58      * specified before this condition is evaluated.
59      **/

60     public IsSet()
61     {
62         super();
63     }
64
65
66     /**
67      * Initializes a fully-defined IsSet condition.
68      * @param property the property against which condition checks
69      **/

70     public IsSet(String JavaDoc property)
71     {
72         setProperty(property);
73     }
74
75
76     /**
77      * Initializes an IsSet condition to either a property or
78      * a variable value check.
79      * @param value property or variable against which condition checks
80      * @param isP <i>true</i> if <span class="src">value</span> is
81      * property's name
82      **/

83     public IsSet(String JavaDoc value, boolean isP)
84     {
85         if (isP) {
86             setProperty(value);
87         } else {
88             setVariable(value);
89         }
90     }
91
92
93
94     /**
95      * Tells this condition whether a property containing only
96      * whitespace is considered "not set". If the choice is
97      * one of "ignore", "reject", or "balk" then an all-whitespace
98      * property are considered not set.
99      **/

100     public void setWhitespace(Handling response)
101     {
102         getValueHelper().setWhitespace(response);
103     }
104
105
106     /**
107      * Returns <i>true</i> if values of all whitespace will be
108      * ignored (as if not set). Defaults <i>false</i>.
109      **/

110     public final boolean ignoreWhitespace()
111     {
112         return getValueHelper().isIgnoreWhitespace();
113     }
114
115
116     /**
117      * Tells this condition whether properties must be completely
118      * resolved to be considered "set". If the choice is
119      * either "ignore" or "accept" then unresolved property
120      * values are considered okidoki (set).
121      * @since JWare/AntX 0.4
122      **/

123     public void setMalformed(Handling response)
124     {
125         // malformed="accept|ignore"
126
if (Handling.isYes(response,Handling.REJECT)) {
127             m_checkUnresolved= false;
128         }
129         // malformed="reject|balk|inherit"
130
else {
131             m_checkUnresolved= true;
132         }
133     }
134
135
136     /**
137      * Returns how this condition will handle unresolved
138      * properties. Returnes either "accept" or "reject".
139      * @since JWare/AntX 0.4
140      **/

141     public Handling getMalformedHandling()
142     {
143         return m_checkUnresolved ? Handling.REJECT : Handling.ACCEPT;
144     }
145
146
147
148     /**
149      * Marks this condition's property as the default field
150      * set by a value URI.
151      * @since JWare/AntX 0.5
152      * @return IsA.PROPERTY always.
153      */

154     protected IsA getDefaultIsAForURI()
155     {
156         return IsA.PROPERTY;
157     }
158
159
160
161     /**
162      * Returns <i>true</i> if this condition's property, reference,
163      * or variable is explicitly set.
164      **/

165     public boolean eval()
166     {
167         verifyCanEvaluate_("eval");
168
169         if (isProperty()) {
170             if (m_checkUnresolved) {
171                 if (!LocalPropertyExaminer.verifyProperty
172                     (getProject(), getValueHelper())) {
173                     return false;
174                 }
175             }
176         }
177         else if (isReference()) {
178             Object JavaDoc o = getProject().getReference(getResolvedFlexValue());
179             if (!(o instanceof String JavaDoc)) {//otherwise apply modifiers(ssmc)
180
return o!=null;
181             }
182         }
183
184         return getValueHelper().getValue()!=null;
185     }
186
187
188     private boolean m_checkUnresolved;//NB:=> even unresolved=="set"
189
}
190
191 /* end-of-IsSet.java */
192
Popular Tags