KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: ExecutionMode.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 ways a task can be run by the Ant
36  * runtime (or some other execution controller). The following list explains what
37  * the various settings mean:<ul>
38  * <li><span class="src">local</span>: The task should be executed within the
39  * current project's scope.</li>
40  * <li><span class="src">localthread</span>: The task should be executed
41  * within the current project's scope but from a different thread.</li>
42  * <li><span class="src">isolated</span>: The task should be executed within
43  * it's own (child) project's scope. Similar to how the
44  * <span class="src">&lt;antcall&gt;</span> task works; most modifications
45  * to the child project are not seen by the current (parent) project.</li>
46  * <li><span class="src">external</span>: The task should be executed in its
47  * own VM instance.</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 ExecutionMode extends EnumSkeleton
58 {
59     /** Index of {@linkplain #LOCAL LOCAL}. **/
60     public static final int LOCAL_INDEX = 0;
61     /** Index of {@linkplain #LOCALTHREAD LOCALTHREAD}. **/
62     public static final int LOCALTHREAD_INDEX = LOCAL_INDEX+1;
63     /** Index of {@linkplain #ISOLATED ISOLATED}. **/
64     public static final int ISOLATED_INDEX = LOCALTHREAD_INDEX+1;
65     /** Index of {@linkplain #EXTERNAL EXTERNAL}. **/
66     public static final int EXTERNAL_INDEX = ISOLATED_INDEX+1;
67
68
69     /** Singleton "<span class="src">local</span>" choice. **/
70     public static final ExecutionMode LOCAL=
71         new ExecutionMode("local",LOCAL_INDEX);
72
73     /** Singleton "<span class="src">localthread</span>" choice. **/
74     public static final ExecutionMode LOCALTHREAD=
75         new ExecutionMode("localthread",LOCALTHREAD_INDEX);
76
77     /** Singleton "<span class="src">isolated</span>" choice. **/
78     public static final ExecutionMode ISOLATED=
79         new ExecutionMode("isolated",ISOLATED_INDEX);
80
81     /** Singleton "<span class="src">external</span>" choice. **/
82     public static final ExecutionMode EXTERNAL=
83         new ExecutionMode("external",EXTERNAL_INDEX);
84
85
86     /**
87      * Required bean void constructor for Ant's introspector.
88      **/

89     public ExecutionMode()
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 ExecutionMode(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[] {"local", "localthread",
114                              "isolated", "external"};
115     };
116
117
118
119     /**
120      * Helper that converts a scalar to a known ExecutionMode.
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 ExecutionMode from(int i)
126     {
127         if (i==LOCAL.index) { return LOCAL; }
128         if (i==ISOLATED.index) { return ISOLATED; }
129         if (i==EXTERNAL.index) { return EXTERNAL; }
130         if (i==LOCALTHREAD.index) { return LOCALTHREAD; }
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      * ExecutionMode's index.
139      * @param i the index to be matched
140      * @param dflt the default ExecutionMode if necessary
141      **/

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

154     public static ExecutionMode 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 (LOCAL.value.equals(s)) { return LOCAL; }
163                 if (ISOLATED.value.equals(s)) { return ISOLATED; }
164                 if (EXTERNAL.value.equals(s)) { return EXTERNAL; }
165                 if (Strings.DEFAULT.equals(s)) { return ISOLATED; }/*safest*/
166                 if (LOCALTHREAD.value.equals(s)){ return LOCALTHREAD; }
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      * ExecutionMode's name.
177      * @param s the symbolic name to be matched
178      * @param dflt the default ExecutionMode if necessary
179      **/

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