KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: IffAny.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>ifAny</i>, <i>ifAnyTrue</i>, <i>unlessAny</i>,
40  * and <i>unlessAnyTrue</i> tests for all conditional components. The
41  * <span class="src">IffAny</span> criteria passes if any of the named properties in
42  * a list exist within a specified project. It fails if none exist.
43  *
44  * @since JWare/AntX 0.4
45  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
46  * @version 0.5
47  * @.safety multiple
48  * @.group impl,helper
49  * @.pattern GoF.Strategy
50  * @see Go
51  * @see IffAll
52  **/

53
54 public final class IffAny
55 {
56     /**
57      * Returns <i>true</i> if any 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 the 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 JavaDoc l= Tk.splitList(list);
70         Iterator JavaDoc itr= l.iterator();
71         while (itr.hasNext()) {
72             if (Iff.allowed(itr.next().toString(),P,onlyIfTrue)) {
73                 return true;
74             }
75         }
76         return false;
77     }
78
79
80     /**
81      * Execute test for an "if-any" conditional parameter. Null
82      * name lists are not allowed.
83      * @since JWare/AntX 0.4
84      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
85      * @version 0.5
86      * @.safety single
87      * @.group impl,helper
88      **/

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

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

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

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

183     private IffAny() {
184     }
185 }
186
187 /* end-of-IffAny.java */
188
Popular Tags