KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > feedback > IndicatorZone


1 /**
2  * $Id: IndicatorZone.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003-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 as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * 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 (GNU Lesser General Public License) 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 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.feedback;
30
31 import com.idaremedia.antx.NoiseLevel;
32 import com.idaremedia.antx.helpers.Tk;
33 import com.idaremedia.antx.parameters.EnumSkeleton;
34
35 /**
36  * Emitted feedback's possible indicator zones. Three options: <i>Problems</i>,
37  * <i>Status</i>, and <i>Diagnostics</i>.
38  *
39  * @since JWare/AntX 0.3
40  * @author ssmc, &copy;2003-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
41  * @version 0.5
42  * @.safety multiple
43  * @.group api,infra
44  **/

45
46 public final class IndicatorZone extends EnumSkeleton
47 {
48     /** Index of {@linkplain #PROBLEMS PROBLEM}. **/
49     public static final int PROBLEMS_INDEX= 0;
50     /** Index of {@linkplain #STATUS STATUS}. **/
51     public static final int STATUS_INDEX= PROBLEMS_INDEX+1;
52     /** Index of {@linkplain #DIAGNOSTICS DIAGNOSTICS}. **/
53     public static final int DIAGNOSTICS_INDEX= STATUS_INDEX+1;
54
55     /** Singleton "problems" indicator zone. **/
56     public static final IndicatorZone PROBLEMS =
57         new IndicatorZone("problems",PROBLEMS_INDEX);
58     /** Singleton "status" indicator zone. **/
59     public static final IndicatorZone STATUS =
60         new IndicatorZone("status",STATUS_INDEX);
61     /** Singleton "diagnostics" indicator zone. **/
62     public static final IndicatorZone DIAGNOSTICS =
63         new IndicatorZone("diagnostics",DIAGNOSTICS_INDEX);
64
65
66     /**
67      * Required bean void constructor for Ant's introspector.
68      **/

69     public IndicatorZone()
70     {
71         super();
72     }
73
74
75     /**
76      * Use to create public singletons. Ensure it's initialized
77      * as with default Ant Introspector helper thingy.
78      **/

79     private IndicatorZone(String JavaDoc v, int i)
80     {
81         super(v);
82     }
83
84
85     /**
86      * Returns copy of all possible indicator-zone values as an ordered
87      * string array. Note: ordering should be same as singletons indice.
88      **/

89     public String JavaDoc[] getValues()
90     {
91         return new String JavaDoc[] {"problems","status","diagnostics"};
92     };
93
94
95
96     /**
97      * Helper that converts a scalar to a known IndicatorZone. Returns
98      * <i>null</i> if value does not match any of expected indicator-zones.
99      * @param i the index to be matched
100      **/

101     public static IndicatorZone from(int i)
102     {
103         if (i==DIAGNOSTICS.index) { return DIAGNOSTICS; }
104         if (i==STATUS.index) { return STATUS; }
105         if (i==PROBLEMS.index) { return PROBLEMS; }
106         return null;
107     }
108
109
110     /**
111      * Same as {@linkplain #from(int) from(int)} but with a
112      * default value if value does not match any known IndicatorZone's
113      * index.
114      * @param i the index to be matched
115      * @param dflt the default IndicatorZone if necessary
116      **/

117     public static IndicatorZone from(int i, IndicatorZone dflt)
118     {
119         IndicatorZone iz= from(i);
120         return (iz==null) ? dflt : iz;
121     }
122
123
124     /**
125      * Helper that converts a NoiseLevel to a known IndicatorZone
126      * singleton. Returns <i>null</i> if noise level is <i>null</i>.
127      * @param nl noiselevel
128      **/

129     public static IndicatorZone from(NoiseLevel nl)
130     {
131         if (nl!=null) {
132             switch(nl.getIndex()) {
133                 case NoiseLevel.FATAL_INDEX:
134                 case NoiseLevel.ERROR_INDEX:
135                 case NoiseLevel.WARNING_INDEX: {
136                     return PROBLEMS;
137                 }
138                 case NoiseLevel.INFO_INDEX: {
139                     return STATUS;
140                 }
141                 default: {
142                     return DIAGNOSTICS;
143                 }
144             }
145         }
146         return null;
147     }
148
149
150     /**
151      * Same as {@linkplain #from(NoiseLevel) from(NoiseLevel)} but
152      * with a default value if value does not match any known
153      * IndicatorZone's noise levels.
154      * @param nl the noise level to be matched
155      * @param dflt the default IndicatorZone if necessary
156      **/

157     public static IndicatorZone from(NoiseLevel nl, IndicatorZone dflt)
158     {
159         IndicatorZone iz= from(nl);
160         return (iz==null) ? dflt : iz;
161     }
162
163
164     /**
165      * Helper that converts a string to a known IndicatorZone singleton.
166      * Returns <i>null</i> if string unrecognized. String can be
167      * either IndicatorZone's symbolic name, its index, or a noiselevel's
168      * name.
169      **/

170     public static IndicatorZone from(String JavaDoc s)
171     {
172         if (s!=null && s.length()>1) {
173             s = Tk.lowercaseFrom(s);
174             if (Character.isDigit(s.charAt(0))) {
175                 try { return from(Integer.parseInt(s)); }
176                 catch(Exception JavaDoc nfx) {/*burp*/}
177             } else {
178                 if (DIAGNOSTICS.value.equals(s)) { return DIAGNOSTICS; }
179                 if (STATUS.value.equals(s)) { return STATUS; }
180                 if (PROBLEMS.value.equals(s)) { return PROBLEMS; }
181
182                 NoiseLevel nl= NoiseLevel.from(s);
183                 if (nl!=null) {
184                     return from(nl);
185                 }
186             }
187         }
188         return null;
189     }
190
191
192     /**
193      * Same as {@linkplain #from(String) from(String)} but
194      * with a default value if value does not match any known
195      * IndicatorZone's or NoiseLevel's name.
196      * @param s the symbolic name to be matched
197      * @param dflt the default IndicatorZone if necessary
198      **/

199     public static IndicatorZone from(String JavaDoc s, IndicatorZone dflt)
200     {
201         IndicatorZone iz= from(s);
202         return (iz==null) ? dflt : iz;
203     }
204 }
205
206 /* end-of-IndicatorZone.java */
207
Popular Tags