KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > parameters > FixturePassthru


1 /**
2  * $Id: FixturePassthru.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.parameters;
30
31 import com.idaremedia.antx.helpers.Strings;
32 import com.idaremedia.antx.helpers.Tk;
33
34 /**
35  * Enumeration that represents the various fixture elements that an execution
36  * context can pass-along to a subcontext. The following list explains what
37  * the various settings <em>typically</em> mean (refer to a task's description to get
38  * task-specific details):<ul>
39  * <li><span class="src">none</span>: No fixture information should be passed on.</li>
40  * <li><span class="src">all</span>: All relevant fixture information should be
41  * passed on.</li>
42  * <li><span class="src">properties</span>: Only project properties should be
43  * passed on. Similar to the common "<span class="src">inheritAll</span>"
44  * parameter.</li>
45  * <li><span class="src">references</span>: Only project references should be
46  * passed on. Similar to the common "<span class="src">inheritRefs</span>"
47  * parameter.</li>
48  * </ul>
49  *
50  * @since JWare/AntX 0.4
51  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
52  * @version 0.5
53  * @.safety multiple
54  * @.group api,helper
55  **/

56
57 public final class FixturePassthru extends EnumSkeleton
58 {
59     /** Index of {@linkplain #ALL ALL}. **/
60     public static final int ALL_INDEX = 0;
61     /** Index of {@linkplain #NONE NONE}. **/
62     public static final int NONE_INDEX = ALL_INDEX+1;
63     /** Index of {@linkplain #PROPERTIES PROPERTIES}. **/
64     public static final int PROPERTIES_INDEX = NONE_INDEX+1;
65     /** Index of {@linkplain #REFERENCES REFERENCES}. **/
66     public static final int REFERENCES_INDEX = PROPERTIES_INDEX+1;
67
68
69     /** Singleton "<span class="src">all</span>" choice. **/
70     public static final FixturePassthru ALL=
71         new FixturePassthru("all",ALL_INDEX);
72
73     /** Singleton "<span class="src">none</span>" choice. **/
74     public static final FixturePassthru NONE=
75         new FixturePassthru("none",NONE_INDEX);
76
77     /** Singleton "<span class="src">properties</span>" choice. **/
78     public static final FixturePassthru PROPERTIES=
79         new FixturePassthru("properties",PROPERTIES_INDEX);
80
81     /** Singleton "<span class="src">references</span>" choice. **/
82     public static final FixturePassthru REFERENCES=
83         new FixturePassthru("references",REFERENCES_INDEX);
84
85
86     /**
87      * Required bean void constructor for Ant's introspector.
88      **/

89     public FixturePassthru()
90     {
91         super();
92     }
93
94
95     /**
96      * Use to create public singletons. Ensures this enum is
97      * initialized as if with the default Ant Introspector
98      * helper thingy.
99      **/

100     private FixturePassthru(String JavaDoc v, int i)
101     {
102         super(v);
103     }
104
105
106     /**
107      * Returns copy of all possible source values as an ordered
108      * string array. Note: ordering should be same as our
109      * singleton indices.
110      **/

111     public String JavaDoc[] getValues()
112     {
113         return new String JavaDoc[] {"all", "none",
114                              "properties", "references"};
115     };
116
117
118
119     /**
120      * Helper that converts a scalar to a known FixturePassthru.
121      * Returns <i>null</i> if value does not match any of expected
122      * source.
123      * @param i the index to be matched
124      **/

125     public static FixturePassthru from(int i)
126     {
127         if (i==ALL.index) { return ALL; }
128         if (i==PROPERTIES.index) { return PROPERTIES; }
129         if (i==REFERENCES.index) { return REFERENCES; }
130         if (i==NONE.index) { return NONE; }
131         return null;
132     }
133
134
135     /**
136      * Same as {@linkplain #from(int) from(int)} but with a
137      * default value if value does not match any known
138      * FixturePassthru's index.
139      * @param i the index to be matched
140      * @param dflt the default FixturePassthru if necessary
141      **/

142     public static FixturePassthru from(int i, FixturePassthru dflt)
143     {
144         FixturePassthru choice= from(i);
145         return (choice==null) ? dflt : choice;
146     }
147
148
149     /**
150      * Helper that converts a string to a known FixturePassthru
151      * singleton. Returns <i>null</i> if string unrecognized. String
152      * can be either FixturePassthru's symbolic name or its index.
153      **/

154     public static FixturePassthru from(String JavaDoc s)
155     {
156         if (s!=null && s.length()>1) {
157             s = Tk.lowercaseFrom(s);
158             if (Character.isDigit(s.charAt(0))) {
159                 try { return from(Integer.parseInt(s)); }
160                 catch(Exception JavaDoc nfx) {/*burp*/}
161             } else {
162                 if (ALL.value.equals(s)) { return ALL; }
163                 if (PROPERTIES.value.equals(s)) { return PROPERTIES; }
164                 if (REFERENCES.value.equals(s)) { return REFERENCES; }
165                 if (Strings.DEFAULT.equals(s)) { return PROPERTIES; }/*std*/
166                 if (NONE.value.equals(s)) { return NONE; }
167             }
168         }
169         return null;
170     }
171
172
173     /**
174      * Same as {@linkplain #from(String) from(String)} but with a
175      * default value if supplied value does not match any known
176      * FixturePassthru's name.
177      * @param s the symbolic name to be matched
178      * @param dflt the default FixturePassthru if necessary
179      **/

180     public static FixturePassthru from(String JavaDoc s, FixturePassthru dflt)
181     {
182         FixturePassthru choice= from(s);
183         return (choice==null) ? dflt : choice;
184     }
185 }
186
187 /* end-of-FixturePassthru.java */
188
Popular Tags