KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: IffAll.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 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 (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any 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 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 GNU 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 java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import org.apache.tools.ant.Project;
35
36 import com.idaremedia.antx.helpers.Tk;
37
38 /**
39  * Implementation of the general <i>ifAll</i> and <i>ifAllTrue</i> tests for all
40  * conditional components. The <span class="src">IffAll</span> criteria passes if
41  * all of the named properties in a list exist within a specified project.
42  *
43  * @since JWare/AntX 0.4
44  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
45  * @version 0.5
46  * @.safety multiple
47  * @.group impl,helper
48  * @.pattern GoF.Strategy
49  * @see Go
50  * @see Iff
51  * @see UnlessAll
52  **/

53
54 public final class IffAll
55 {
56     /**
57      * Returns <i>true</i> if all of the named properties in given
58      * list exist in project.
59      * @param list comma-delimited list of property names
60      * @param P project from which properties read
61      * @param onlyIfTrue <i>true</i> if each property must also be
62      * a valid positive boolean string
63      **/

64     public static boolean pass(String JavaDoc list, Project P, boolean onlyIfTrue)
65     {
66         if (Tk.isWhitespace(list)) {
67             return false;
68         }
69         list = Tk.resolveString(P,list);
70         List JavaDoc l= Tk.splitList(list);
71         Iterator JavaDoc itr= l.iterator();
72         while (itr.hasNext()) {
73             if (!Iff.allowed(itr.next().toString(),P,onlyIfTrue)) {
74                 return false;
75             }
76         }
77         return true;
78     }
79
80
81     /**
82      * Execute test for an "if-all" conditional parameter. Null
83      * name lists are not allowed.
84      * @since JWare/AntX 0.4
85      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
86      * @version 0.5
87      * @.safety single
88      * @.group impl,helper
89      **/

90     public static final class Exists extends Go.TestSkeleton {
91         public Exists() {
92         }
93         public Exists(String JavaDoc list) {
94             super(list);
95         }
96         public boolean pass(Project P) {
97             verifyInited();
98             return IffAll.pass(getParameter(),P,false);
99         }
100         public String JavaDoc getParameterName() {
101             return "ifAll";
102         }
103     }
104
105
106     /**
107      * Execute test for an "unless-all" conditional parameter.
108      * Null name lists are not allowed.
109      * @since JWare/AntX 0.4
110      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
111      * @version 0.5
112      * @.safety single
113      * @.group impl,helper
114      * @see UnlessAll
115      **/

116     public static final class NotExists extends Go.TestSkeleton {
117         public NotExists() {
118         }
119         public NotExists(String JavaDoc list) {
120             super(list);
121         }
122         public boolean pass(Project P) {
123             verifyInited();
124             return UnlessAll.pass(getParameter(),P,false);
125         }
126         public String JavaDoc getParameterName() {
127             return "unlessAll";
128         }
129     }
130
131
132     /**
133      * Execute test for an "if-all-true" conditional parameter.
134      * Null name lists are not allowed.
135      * @since JWare/AntX 0.4
136      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
137      * @version 0.5
138      * @.safety single
139      * @.group impl,helper
140      **/

141     public static final class IsTrue extends Go.TestSkeleton {
142         public IsTrue() {
143         }
144         public IsTrue(String JavaDoc list) {
145             super(list);
146         }
147         public boolean pass(Project P) {
148             verifyInited();
149             return IffAll.pass(getParameter(),P,true);
150         }
151         public String JavaDoc getParameterName() {
152             return "ifAllTrue";
153         }
154     }
155
156
157     /**
158      * Execute test for an "if-all-true" conditional parameter.
159      * Null name lists are not allowed.
160      * @since JWare/AntX 0.4
161      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
162      * @version 0.5
163      * @.safety single
164      * @.group impl,helper
165      **/

166     public static final class IsNotTrue extends Go.TestSkeleton {
167         public IsNotTrue() {
168         }
169         public IsNotTrue(String JavaDoc list) {
170             super(list);
171         }
172         public boolean pass(Project P) {
173             verifyInited();
174             return UnlessAll.pass(getParameter(),P,true);
175         }
176         public String JavaDoc getParameterName() {
177             return "unlessAllTrue";
178         }
179     }
180
181
182     /**
183      * Prevent; only helpers public.
184      **/

185     private IffAll() {
186     }
187 }
188
189 /* end-of-IffAll.java */
190
Popular Tags