KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: MainField.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.helpers.Tk;
32 import com.idaremedia.antx.parameters.EnumSkeleton;
33
34 /**
35  * A BuildEvent's main information categories. MainFields are used to create a default
36  * (minimal) {@linkplain EventEmitConduit hierarchy} of captured Ant log messages. They
37  * also form the basis for user-controlled category {@linkplain GroupingMapper groupings}.
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 impl,helper
44  * @see EventEmitConduit
45  * @see GroupingMapper
46  **/

47
48 public final class MainField extends EnumSkeleton
49 {
50     public static final int INCLUDE_THREAD = 0x01;
51     public static final int INCLUDE_PROJECT = 0x02;
52     public static final int INCLUDE_TARGET = 0x04;
53     public static final int INCLUDE_TASK = 0x08;
54     public static final int INCLUDE_NESTED = 0x10;
55     public static final int INCLUDE_ALL = 0xff;
56     public static final int DEFAULT_FILTER = INCLUDE_ALL;
57
58
59     /** Index of {@linkplain #PROJECT PROJECT}. **/
60     public static final int PROJECT_INDEX= 0;
61     /** Index of {@linkplain #TARGET TARGET}. **/
62     public static final int TARGET_INDEX= PROJECT_INDEX+1;
63     /** Index of {@linkplain #TASK TASK}. **/
64     public static final int TASK_INDEX= TARGET_INDEX+1;
65     /** Index of {@linkplain #MESSAGE MESSAGE}. **/
66     public static final int MESSAGE_INDEX= TASK_INDEX+1;
67     /** Index of {@linkplain #INDICATOR INDICATOR}. **/
68     public static final int INDICATOR_INDEX= MESSAGE_INDEX+1;
69     /** Index of {@linkplain #UNKNOWN UNKNOWN}. **/
70     public static final int UNKNOWN_INDEX= INDICATOR_INDEX+1;
71
72     /** Singleton "project" field. **/
73     public static final MainField PROJECT =
74         new MainField("project",PROJECT_INDEX,INCLUDE_PROJECT);
75     /** Singleton "target" field. **/
76     public static final MainField TARGET =
77         new MainField("target",TARGET_INDEX,INCLUDE_TARGET);
78     /** Singleton "task" field. **/
79     public static final MainField TASK =
80         new MainField("task",TASK_INDEX,INCLUDE_TASK);
81     /** Singleton "message" field. **/
82     public static final MainField MESSAGE =
83         new MainField("message",MESSAGE_INDEX, INCLUDE_ALL);
84     /** Singleton "indicator" field. **/
85     public static final MainField INDICATOR =
86         new MainField("indicator",INDICATOR_INDEX, INCLUDE_ALL);
87     /** Singleton unknown field. **/
88     public static final MainField UNKNOWN =
89         new MainField("_any_",UNKNOWN_INDEX, INCLUDE_ALL);
90
91
92     /**
93      * Required bean void constructor for Ant's introspector.
94      **/

95     public MainField()
96     {
97         super();
98     }
99
100
101     /**
102      * Use to create public singletons. Ensure it's initialized
103      * as with default Ant Introspector helper thingy.
104      **/

105     private MainField(String JavaDoc v, int i, int filter)
106     {
107         super(v);
108         m_filter = filter;
109     }
110
111
112     /**
113      * Returns copy of all possible mainfield values as an ordered
114      * string array. Note: ordering should be same as singletons indice.
115      **/

116     public String JavaDoc[] getValues()
117     {
118         return new String JavaDoc[] {"project","target","task","message",
119                              "indicator","_any_"};
120     };
121
122
123     /**
124      * Returns this fields associated filter or zero (0) if none.
125      **/

126     final int getFilter()
127     {
128         return m_filter;
129     }
130
131
132     /**
133      * Helper that converts a scalar to a known MainField. Returns
134      * <i>null</i> if value does not match any of expected fields.
135      * @param i the index to be matched
136      **/

137     public static MainField from(int i)
138     {
139         if (i==TASK.index) { return TASK; }
140         if (i==MESSAGE.index) { return MESSAGE; }
141         if (i==TARGET.index) { return TARGET; }
142         if (i==PROJECT.index) { return PROJECT; }
143         if (i==INDICATOR.index) { return INDICATOR; }
144         if (i==UNKNOWN.index) { return UNKNOWN; }
145         return null;
146     }
147
148
149     /**
150      * Same as {@linkplain #from(int) from(int)} but with a
151      * default value if value does not match any known MainField's
152      * index.
153      * @param i the index to be matched
154      * @param dflt the default MainField if necessary
155      **/

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

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

195     public static MainField from(String JavaDoc s, MainField dflt)
196     {
197         MainField mf= from(s);
198         return (mf==null) ? dflt : mf;
199     }
200
201
202     private int m_filter;
203 }
204
205 /* end-of-MainField.java */
206
Popular Tags