KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > match > ChoiceType


1 /**
2  * $Id: ChoiceType.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.flowcontrol.match;
30
31 import com.idaremedia.antx.parameters.EnumSkeleton;
32
33 /**
34  * Helper enum that represents the known AntX choice types.
35  *
36  * @since JWare/AntX 0.5
37  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
38  * @version 0.5
39  * @.safety multiple
40  * @.group impl,helper
41  **/

42
43 final class ChoiceType extends EnumSkeleton
44 {
45     /** Index of {@linkplain #NONE NONE}. **/
46     static final int NONE_INDEX = 0;
47     /** Index of {@linkplain #SAME SAME}. **/
48     static final int SAME_INDEX = NONE_INDEX+1;
49     /** Index of {@linkplain #LIKE LIKE}. **/
50     static final int LIKE_INDEX = SAME_INDEX+1;
51     /** Index of {@linkplain #MEETS MEETS}. **/
52     static final int MEETS_INDEX = LIKE_INDEX+1;
53
54
55     /** Singleton "<span class="src">none</span>" choice. **/
56     static final ChoiceType NONE=
57         new ChoiceType("none",NONE_INDEX,false);
58
59     /** Singleton "<span class="src">same</span>" choice. **/
60     static final ChoiceType SAME=
61         new ChoiceType("equals",SAME_INDEX,true);
62
63     /** Singleton "<span class="src">like</span>" choice. **/
64     static final ChoiceType LIKE=
65         new ChoiceType("like",LIKE_INDEX,true);
66
67     /** Singleton "<span class="src">meets</span>" choice. **/
68     static final ChoiceType MEETS=
69         new ChoiceType("meets",MEETS_INDEX,false);
70
71
72     /**
73      * Use to create public singletons. Ensures this enum is
74      * initialized as if with the default Ant Introspector
75      * helper thingy.
76      **/

77     private ChoiceType(String JavaDoc v, int i, boolean landr)
78     {
79         super(v);
80         m_landr = landr;
81     }
82
83
84     /**
85      * Returns copy of all possible source values as an ordered
86      * string array. Note: ordering should be same as our
87      * singleton indices.
88      **/

89     public String JavaDoc[] getValues()
90     {
91         return new String JavaDoc[] {"none", "equals", "like", "meets"};
92     };
93
94
95
96     /**
97      * Returns whether this choice type needs both a known and
98      * unknown value for evaluation.
99      **/

100     boolean needsLeftAndRight()
101     {
102         return m_landr;
103     }
104
105
106     /**
107      * Helper that converts a string to a known ChoiceType
108      * singleton. Returns <i>null</i> if string unrecognized.
109      **/

110     static ChoiceType from(Class JavaDoc c)
111     {
112         if (c!=null) {
113             if (MatchEquals.class.isAssignableFrom(c)) {
114                 return SAME;
115             }
116             if (MatchLike.class.isAssignableFrom(c)) {
117                 return LIKE;
118             }
119             if (MatchCondition.class.isAssignableFrom(c)) {
120                 return MEETS;
121             }
122         }
123         return null;
124     }
125
126
127     /**
128      * Same as {@linkplain #from(Class) from(Class)} but with a
129      * default value if supplied value does not match any known
130      * ChoiceTask implementation.
131      * @param s the symbolic name to be matched
132      * @param dflt the default ChoiceType if necessary
133      **/

134     static ChoiceType from(Class JavaDoc c, ChoiceType dflt)
135     {
136         ChoiceType choice= from(c);
137         return (choice==null) ? dflt : choice;
138     }
139
140
141     private final boolean m_landr;//default for most types
142
}
143
144 /* end-of-ChoiceType.java */
Popular Tags