KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: FeedbackLevel.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 level of script-facing feedback a task might
36  * implement. Script-facing feedback may or may not include developer-targetted
37  * implementation diagnostics. Similarly, telling a task container to be quiet
38  * may or may not affect its nested tasks (this too must be task defined). The
39  * following list explains what the various settings mean:<ul>
40  * <li><span class="src">none</span>: No script-facing feedback should be generated.
41  * Whether this turns off developer diagnostics (ant -debug) is task defined.</li>
42  * <li><span class="src">verbose</span>: As much feedback should be generated as
43  * implemented. Whether this is the same as verbose developer diagnostics
44  * is task defined.</li>
45  * <li><span class="src">normal</span>: The normal feedback should be done. Usually
46  * this limits feedback to alerts, warnings, or worse conditions.</li>
47  * <li><span class="src">quiet</span>: Feedback should be limited to serious but not
48  * necessarily critical problems. Whether this setting applies to tasks launched
49  * by the primary task is task defined (the lauched task might, for instance, have
50  * its own settings).</li>
51  * <li><span class="src">veryquiet</span>: All feedback should be dropped except that
52  * which precedes a build error. This instruction should apply (when possible) to
53  * subtasks or external processes run on the primary task's behalf.</li>
54  * </ul>
55  *
56  * @since JWare/AntX 0.5
57  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
58  * @version 0.5
59  * @.safety multiple
60  * @.group api,helper
61  **/

62
63 public final class FeedbackLevel extends EnumSkeleton
64 {
65     //@.impl ORDERING of static declarations is important! ------
66

67     //1) Indices (in order)
68

69     public static int VERBOSE_INDEX = 0;
70     public static int NORMAL_INDEX = VERBOSE_INDEX+1;
71     public static int QUIET_INDEX = NORMAL_INDEX+1;
72     public static int VERYQUIET_INDEX = QUIET_INDEX+1;
73     public static int NONE_INDEX = VERYQUIET_INDEX+1;
74
75
76     //2) Values (in order)
77

78     /** Values in same order as public indices. **/
79     private static final String JavaDoc[] VALUES_= new String JavaDoc[] {
80         "verbose", "normal", "quiet", "veryquiet", "none"
81     };
82
83
84     //3) Singletons (depend on Indices and Values already existing!)
85

86     /** Singleton "<span class="src">verbose</span>" level. **/
87     public static final FeedbackLevel VERBOSE=
88         new FeedbackLevel(VALUES_[VERBOSE_INDEX],VERBOSE_INDEX);
89
90     /** Singleton "<span class="src">normal</span>" level. **/
91     public static final FeedbackLevel NORMAL=
92         new FeedbackLevel(VALUES_[NORMAL_INDEX],NORMAL_INDEX);
93
94     /** Singleton "<span class="src">quiet</span>" level. **/
95     public static final FeedbackLevel QUIET=
96         new FeedbackLevel(VALUES_[QUIET_INDEX],QUIET_INDEX);
97
98     /** Singleton "<span class="src">veryquiet</span>" level. **/
99     public static final FeedbackLevel VERYQUIET=
100         new FeedbackLevel(VALUES_[VERYQUIET_INDEX],VERYQUIET_INDEX);
101
102     /** Singleton "<span class="src">none</span>" level. **/
103     public static final FeedbackLevel NONE=
104         new FeedbackLevel(VALUES_[NONE_INDEX],NONE_INDEX);
105
106
107
108     /**
109      * Required bean void constructor for Ant's introspector.
110      **/

111     public FeedbackLevel()
112     {
113         super();
114     }
115
116
117     /**
118      * Use to create public singletons. Ensures this enum is
119      * initialized as if with the default Ant Introspector
120      * helper thingy.
121      **/

122     private FeedbackLevel(String JavaDoc v, int i)
123     {
124         super(v);
125     }
126
127
128
129     /**
130      * Returns a <em>copy</em> of the standard feedback levels
131      * in order.
132      * @param fillin [optional] array of strings to update with values.
133      **/

134     public static String JavaDoc[] copyOfDefaultValues(String JavaDoc[] fillin)
135     {
136         if (fillin==null) {
137             fillin = new String JavaDoc[VALUES_.length];
138         }
139         System.arraycopy(VALUES_,0,fillin,0,VALUES_.length);
140         return fillin;
141     }
142
143
144
145     /**
146      * Returns copy of all possible feedback levels as an ordered
147      * string array. Note: ordering should be same as our
148      * singleton indices.
149      **/

150     public String JavaDoc[] getValues()
151     {
152         return FeedbackLevel.copyOfDefaultValues(null);
153     };
154
155
156
157     /**
158      * Helper that converts a scalar to a known FeedbackLevel.
159      * Returns <i>null</i> if value does not match any of expected
160      * source.
161      * @param i the index to be matched
162      **/

163     public static FeedbackLevel from(int i)
164     {
165         if (i==NORMAL.index) { return NORMAL; }
166         if (i==QUIET.index) { return QUIET; }
167         if (i==VERYQUIET.index) { return VERYQUIET; }
168         if (i==VERBOSE.index) { return VERBOSE; }
169         if (i==NONE.index) { return NONE; }
170         return null;
171     }
172
173
174     /**
175      * Same as {@linkplain #from(int) from(int)} but with a
176      * default value if value does not match any known
177      * FeedbackLevel's index.
178      * @param i the index to be matched
179      * @param dflt the default FeedbackLevel if necessary
180      **/

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

193     public static FeedbackLevel from(String JavaDoc s)
194     {
195         if (s!=null && s.length()>1) {
196             s = Tk.lowercaseFrom(s);
197             if (Character.isDigit(s.charAt(0))) {
198                 try { return from(Integer.parseInt(s)); }
199                 catch(Exception JavaDoc nfx) {/*burp*/}
200             } else {
201                 if (Strings.DEFAULT.equals(s)) { return NORMAL; }
202                 if (NORMAL.value.equals(s)) { return NORMAL; }
203                 if (QUIET.value.equals(s)) { return QUIET; }
204                 if (VERYQUIET.value.equals(s)) { return VERYQUIET; }
205                 if (VERBOSE.value.equals(s)) { return VERBOSE; }
206                 if (NONE.equals(s)) { return NONE; }
207                 if (Tk.string2NegBool(s)==Boolean.FALSE) {
208                     return NONE;
209                 }
210             }
211         }
212         return null;
213     }
214
215
216     /**
217      * Same as {@linkplain #from(String) from(String)} but with a
218      * default value if supplied value does not match any known
219      * FeedbackLevel's name.
220      * @param s the symbolic name to be matched
221      * @param dflt the default FeedbackLevel if necessary
222      **/

223     public static FeedbackLevel from(String JavaDoc s, FeedbackLevel dflt)
224     {
225         FeedbackLevel choice= from(s);
226         return (choice==null) ? dflt : choice;
227     }
228     
229
230
231     /**
232      * Separates the loud feedback levels from the non-loud ones.
233      * @param fbl feedback level under test (can be <i>null</i>)
234      * @param nullIsQuiet <i>true</i> if a null level is considered quiet.
235      * @return true if quiet-ish
236      **/

237     public static boolean isQuietish(FeedbackLevel fbl, boolean nullIsQuiet)
238     {
239         if (fbl==null) {
240             return nullIsQuiet;
241         }
242         return fbl.getIndex()>=QUIET_INDEX;
243     }
244     
245
246
247     /**
248      * Separates the loud feedback levels from the non-loud ones.
249      * Lets you specify whether <i>null</i> and NORMAL mean quiet.
250      * @param fbl feedback level under test (can be <i>null</i>)
251      * @param normalIsQuiet <i>true</i> if the normal level is considered quiet.
252      * @param nullIsQuiet <i>true</i> if a null level is considered quiet.
253      * @return true if quiet-ish
254      **/

255     public static boolean isQuietish(FeedbackLevel fbl, boolean normalIsQuiet,
256         boolean nullIsQuiet)
257     {
258         if (fbl==null) {
259             return nullIsQuiet;
260         }
261         if (fbl.getIndex()>=QUIET_INDEX) {
262             return true;
263         }
264         return NORMAL_INDEX==fbl.getIndex() ? normalIsQuiet : false;
265     }
266
267 }
268
269 /* end-of-FeedbackLevel.java */
Popular Tags