KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > go > Iff


1 /**
2  * $Id: Iff.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003-2005 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.go;
30
31 import org.apache.tools.ant.Project;
32
33 import com.idaremedia.antx.helpers.Tk;
34
35 /**
36  * Implementation of the general <em>if</em> and <em>ifTrue</em> test for all
37  * conditional components.
38  *
39  * @since JWare/AntX 0.3
40  * @author ssmc, &copy;2003-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
41  * @version 0.5
42  * @.safety multiple
43  * @.group impl,helper
44  * @see Go
45  * @see IffAll
46  **/

47
48 public final class Iff
49 {
50     /**
51      * Tests whether or not the given property name resolves to
52      * an existing project property. The empty string always
53      * returns <i>true</i>.
54      * @param property the property name (non-null)
55      * @param P the project to check against (non-null)
56      * @return <i>true</i> if the property is defined
57      **/

58     public static final boolean allowed(String JavaDoc property, Project P)
59     {
60         return allowed(property,P,false);
61     }
62
63
64
65     /**
66      * Tests whether or not the given property name resolves to
67      * a project property with a positive boolean value. The empty
68      * string always returns <i>true</i>.
69      * @param property the property to test (non-null)
70      * @param P the project to check against (non-null)
71      * @param onlyIfTrue <i>true</i> if property must be defined
72      * to a positive boolean string (like "yes")
73      * @return <i>true</i> if the property is defined to a
74      * positive boolean string
75      **/

76     public static final boolean allowed(String JavaDoc property, Project P,
77                                         boolean onlyIfTrue)
78     {
79         if (property==null || "".equals(property)) {
80             return true;
81         }
82         String JavaDoc test = Tk.resolveString(P,property);
83         if (onlyIfTrue) {
84             return Tk.booleanFrom(P.getProperty(test));//allow on,yes,true
85
}
86         return P.getProperty(test)!=null;
87     }
88
89
90
91     /**
92      * Execute test for a simple "if" conditional parameter. Null
93      * property names are not allowed.
94      * @since JWare/AntX 0.4
95      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
96      * @version 0.5
97      * @.safety single
98      * @.group impl,helper
99      **/

100     public static final class Exists extends Go.TestSkeleton {
101         public Exists() {
102         }
103         public Exists(String JavaDoc property) {
104             super(property);
105         }
106         public boolean pass(Project P) {
107             verifyInited();
108             return Iff.allowed(getParameter(),P,false);
109         }
110         public String JavaDoc getParameterName() {
111             return "if";
112         }
113     }
114
115
116     /**
117      * Execute test for a simple "if-true" conditional parameter.
118      * Null property names are not allowed.
119      * @since JWare/AntX 0.4
120      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
121      * @version 0.5
122      * @.safety single
123      * @.group impl,helper
124      **/

125     public static final class IsTrue extends Go.TestSkeleton {
126         public IsTrue() {
127         }
128         public IsTrue(String JavaDoc list) {
129             super(list);
130         }
131         public boolean pass(Project P) {
132             verifyInited();
133             return Iff.allowed(getParameter(),P,true);
134         }
135         public String JavaDoc getParameterName() {
136             return "ifTrue";
137         }
138     }
139
140
141
142     /**
143      * Execute test for a simple "unless" conditional parameter.
144      * Null property names are not allowed.
145      * @since JWare/AntX 0.4
146      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
147      * @version 0.5
148      * @.safety single
149      * @.group impl,helper
150      * @see Unless
151      **/

152     public static final class NotExists extends Go.TestSkeleton {
153         public NotExists() {
154         }
155         public NotExists(String JavaDoc property) {
156             super(property);
157         }
158         public boolean pass(Project P) {
159             verifyInited();
160             return Unless.allowed(getParameter(),P,false);
161         }
162         public String JavaDoc getParameterName() {
163             return "unless";
164         }
165     }
166
167
168     /**
169      * Execute test for a simple "unless-true" conditional
170      * parameter. Null property names are not allowed.
171      * @since JWare/AntX 0.4
172      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
173      * @version 0.5
174      * @.safety single
175      * @.group impl,helper
176      * @see Unless
177      **/

178     public static final class IsNotTrue extends Go.TestSkeleton {
179         public IsNotTrue() {
180         }
181         public IsNotTrue(String JavaDoc list) {
182             super(list);
183         }
184         public boolean pass(Project P) {
185             verifyInited();
186             return Unless.allowed(getParameter(),P,true);
187         }
188         public String JavaDoc getParameterName() {
189             return "unlessTrue";
190         }
191     }
192
193
194     /** Don't allow **/
195     private Iff()
196     {
197     }
198 }
199
200 /* end-of-Iff.java */
201
Popular Tags