KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: PropertySource.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 possible sources of a project property in the Ant
36  * runtime. The following list explains what kinds of properties are lumped under
37  * the various source categories:<ul>
38  * <li><span class="src">all</span>: All project properties regardless of origin.</li>
39  * <li><span class="src">all--</span>: Like "<span class="src">all</span>" but
40  * with the standard immutable Java/Sun properties removed.</li>
41  * <li><span class="src">command</span>: Project properties that were either defined
42  * as command arguments to main Ant process (via CLI or GUI) or is one of a small
43  * set of special Ant runtime properties (like
44  * <span class="src">ant.version</span>).</li>
45  * <li><span class="src">control</span>: Non-command properties that were defined
46  * by the project's Ant launch context (like the nested properties inside an
47  * originating <span class="src">&lt;antcall&gt;</span>).</li>
48  * <li><span class="src">script</span>: Properties that are neither command nor
49  * control properties. This group includes the regular Java runtime's
50  * <span class="src">System</span> properties and properties defined within the
51  * current Ant context or <span class="src">Project</span>.</li>
52  * <li><span class="src">script--</span>: Like "<span class="src">script</span>" but
53  * with the standard immutable Java/Sun properties removed.</li>
54  * <li><span class="src">jre</span>: Properties that are defined in the
55  * standard Java runtime's <span class="src">System Properties</span>.</li>
56  * <li><span class="src">fixture</span>: Properties that are defined in either the
57  * AntX fixture or the <span class="src">System</span> properties.</li>
58  * </ul>
59  *
60  * @since JWare/AntX 0.4
61  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
62  * @version 0.5
63  * @.safety multiple
64  * @.group api,helper
65  **/

66
67 public final class PropertySource extends EnumSkeleton
68 {
69     /** Index of {@linkplain #ALL ALL}. **/
70     public static final int ALL_INDEX = 0;
71     /** Index of {@linkplain #ALLlite ALLlite}. **/
72     public static final int ALLlite_INDEX = ALL_INDEX+1;
73
74     /** Index of {@linkplain #COMMAND COMMAND}. **/
75     public static final int COMMAND_INDEX = ALLlite_INDEX+1;
76     /** Index of {@linkplain #CONTROL CONTROL}. **/
77     public static final int CONTROL_INDEX = COMMAND_INDEX+1;
78
79     /** Index of {@linkplain #SCRIPT SCRIPT}. **/
80     public static final int SCRIPT_INDEX = CONTROL_INDEX+1;
81     /** Index of {@linkplain #SCRIPTlite SCRIPTlite}. **/
82     public static final int SCRIPTlite_INDEX = SCRIPT_INDEX+1;
83
84     /** Index of {@linkplain #JRE JRE}. **/
85     public static final int JRE_INDEX = SCRIPTlite_INDEX+1;
86     /** Index of {@linkplain #FIXTURE FIXTURE}. **/
87     public static final int FIXTURE_INDEX = JRE_INDEX+1;
88
89
90     /** Singleton "<span class="src">all</span>" choice. **/
91     public static final PropertySource ALL=
92         new PropertySource("all",ALL_INDEX);
93
94     /** Singleton "<span class="src">all--</span>" choice. **/
95     public static final PropertySource ALLlite=
96         new PropertySource("all--",ALLlite_INDEX);
97
98     /** Singleton "<span class="src">command</span>" choice. **/
99     public static final PropertySource COMMAND=
100         new PropertySource("command",COMMAND_INDEX);
101
102     /** Singleton "<span class="src">control</span>" choice. **/
103     public static final PropertySource CONTROL=
104         new PropertySource("control",CONTROL_INDEX);
105
106     /** Singleton "<span class="src">script</span>" choice. **/
107     public static final PropertySource SCRIPT=
108         new PropertySource("script",SCRIPT_INDEX);
109
110     /** Singleton "<span class="src">script--</span>" choice. **/
111     public static final PropertySource SCRIPTlite=
112         new PropertySource("script--",SCRIPTlite_INDEX);
113
114     /** Singleton "<span class="src">jre</span>" choice. **/
115     public static final PropertySource JRE=
116         new PropertySource("jre",JRE_INDEX);
117
118     /** Singleton "<span class="src">fixture</span>" choice. **/
119     public static final PropertySource FIXTURE=
120         new PropertySource("fixture",FIXTURE_INDEX);
121
122
123
124     /**
125      * Required bean void constructor for Ant's introspector.
126      **/

127     public PropertySource()
128     {
129         super();
130     }
131
132
133     /**
134      * Use to create public singletons. Ensures this enum is
135      * initialized as if with the default Ant Introspector
136      * helper thingy.
137      **/

138     private PropertySource(String JavaDoc v, int i)
139     {
140         super(v);
141     }
142
143
144     /**
145      * Returns copy of all possible source values as an ordered
146      * string array. Note: ordering should be same as our
147      * singleton indices.
148      **/

149     public String JavaDoc[] getValues()
150     {
151         return new String JavaDoc[] {"all", "all--",
152                              "command", "control",
153                              "script", "script--",
154                              "jre", "fixture"};
155     };
156
157
158
159     /**
160      * Helper that converts a scalar to a known PropertySource.
161      * Returns <i>null</i> if value does not match any of expected
162      * source.
163      * @param i the index to be matched
164      **/

165     public static PropertySource from(int i)
166     {
167         if (i==COMMAND.index) { return COMMAND; }
168         if (i==ALL.index) { return ALL; }
169         if (i==ALLlite.index) { return ALLlite; }
170         if (i==CONTROL.index) { return CONTROL; }
171         if (i==SCRIPT.index) { return SCRIPT; }
172         if (i==SCRIPTlite.index) { return SCRIPTlite; }
173         if (i==FIXTURE.index) { return FIXTURE; }
174         if (i==JRE.index) { return JRE; }
175         return null;
176     }
177
178
179     /**
180      * Same as {@linkplain #from(int) from(int)} but with a
181      * default value if value does not match any known
182      * PropertySource's index.
183      * @param i the index to be matched
184      * @param dflt the default PropertySource if necessary
185      **/

186     public static PropertySource from(int i, PropertySource dflt)
187     {
188         PropertySource choice= from(i);
189         return (choice==null) ? dflt : choice;
190     }
191
192
193     /**
194      * Helper that converts a string to a known PropertySource
195      * singleton. Returns <i>null</i> if string unrecognized. String
196      * can be either PropertySource's symbolic name or its index.
197      **/

198     public static PropertySource from(String JavaDoc s)
199     {
200         if (s!=null && s.length()>1) {
201             s = Tk.lowercaseFrom(s);
202             if (Character.isDigit(s.charAt(0))) {
203                 try { return from(Integer.parseInt(s)); }
204                 catch(Exception JavaDoc nfx) {/*burp*/}
205             } else {
206                 // NOTE: We must support the pre AntX-0.4 choices of
207
// "all", "user", etc. as well as the names used
208
// by the standard <propertyset> command [ssmc]
209
if (COMMAND.value.equals(s)) { return COMMAND; }
210                 if (Strings.USER.equals(s)) { return COMMAND; }
211                 if (ALL.value.equals(s)) { return ALL; }
212                 if (ALLlite.value.equals(s)) { return ALLlite; }
213                 if (SCRIPT.value.equals(s)) { return SCRIPT; }
214                 if (SCRIPTlite.value.equals(s)) { return SCRIPTlite; }
215                 if (CONTROL.value.equals(s)) { return CONTROL; }
216                 if (FIXTURE.value.equals(s)) { return FIXTURE; }
217                 if (JRE.value.equals(s)) { return JRE; }
218                 if (Strings.DEFAULT.equals(s)) { return ALL; }
219                 if ("commandline".equals(s)) { return COMMAND; }//<propertyset>
220
if ("system".equals(s)) { return JRE; }
221                 if ("antx".equals(s)) { return FIXTURE; }
222             }
223         }
224         return null;
225     }
226
227
228     /**
229      * Same as {@linkplain #from(String) from(String)} but with a
230      * default value if supplied value does not match any known
231      * PropertySource's name.
232      * @param s the symbolic name to be matched
233      * @param dflt the default PropertySource if necessary
234      **/

235     public static PropertySource from(String JavaDoc s, PropertySource dflt)
236     {
237         PropertySource choice= from(s);
238         return (choice==null) ? dflt : choice;
239     }
240 }
241
242 /* end-of-PropertySource.java */
243
Popular Tags