KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > expr > OperatorTypes


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23 package org.mdarad.framework.expr;
24
25 import java.util.Collection JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Locale JavaDoc;
29 import java.util.Map JavaDoc;
30
31 /**
32  * This class keeps the possible values of the operator types associated
33  * to the search criteria.
34  * <ul>
35  * <li>{@link #EQUAL Equal Operator}</li>
36  * <li>{@link #LOWER_THAN Lower than operator type}</li>
37  * <li>{@link #LOWER_THAN_OR_EQUAL Lower than or equal operator type}</li>
38  * <li>{@link #GREATER_THAN Greater than operator type}</li>
39  * <li>{@link #GREATER_THAN_OR_EQUAL Greater than or equal operator type}</li>
40  * <li>{@link #BOOLEAN Boolean operator type}</li>
41  * <li>{@link #LIKE Like operator type}</li>
42  * <li>{@link #START_WITH Starts with operator}</li>
43  * <li>{@link #END_WITH Ends with operator}</li>
44  * </ul>
45  *
46  * @author Philippe Brouillette
47  * @version 1.0
48  */

49 public class OperatorTypes {
50
51
52     /**
53      * Map of the items contained in the enumeration class
54      */

55     protected static Map JavaDoc operatorTypes = new Hashtable JavaDoc();
56
57
58     //Constants
59
/**
60      * Equal Operator
61      */

62     public static OperatorType EQUAL = new OperatorType(new String JavaDoc("EQUAL"), "EQUAL");
63     /**
64      * Lower than operator type
65      */

66     public static OperatorType LOWER_THAN = new OperatorType(new String JavaDoc("LOWER_THAN"), "LOWER_THAN");
67     /**
68      * Lower than or equal operator type
69      */

70     public static OperatorType LOWER_THAN_OR_EQUAL = new OperatorType(new String JavaDoc("LOWER_OR_EQUAL"), "LOWER_OR_EQUAL");
71     /**
72      * Greater than operator type
73      */

74     public static OperatorType GREATER_THAN = new OperatorType(new String JavaDoc("GREATER_THAN"), "GREATER_THAN");
75     /**
76      * Greater than or equal operator type
77      */

78     public static OperatorType GREATER_THAN_OR_EQUAL = new OperatorType(new String JavaDoc("GREATER_THAN_OR_EQUAL"), "GREATER_THAN_OR_EQUAL");
79     /**
80      * boolean operator type
81      */

82     public static OperatorType BOOLEAN = new OperatorType(new String JavaDoc("BOOLEAN"), "BOOLEAN");
83     /**
84      * Like operator type
85      */

86     public static OperatorType LIKE = new OperatorType(new String JavaDoc("LIKE"), "LIKE");
87     /**
88      * Starts with operator
89      */

90     public static OperatorType START_WITH = new OperatorType(new String JavaDoc("START_WITH"), "START_WITH");
91     /**
92      * Ends with operator
93      */

94     public static OperatorType END_WITH = new OperatorType(new String JavaDoc("END_WITH"), "END_WITH");
95     /**
96      * In operator
97      */

98     public static OperatorType IN = new OperatorType(new String JavaDoc("IN"), "IN");
99
100     
101     // add the constants to the enumeration
102
static {
103         add(EQUAL);
104         add(LOWER_THAN);
105         add(GREATER_THAN);
106         add(LOWER_THAN_OR_EQUAL);
107         add(GREATER_THAN_OR_EQUAL);
108         add(BOOLEAN);
109
110     }
111
112
113     /**
114      * Method that adds an OperatorType to this map
115      * @param allowable OperatorType that must be added
116      * to the map
117      */

118     protected static final void add(OperatorType allowable) {
119         operatorTypes.put(allowable.getValue(), allowable);
120     }
121
122     /**
123      * This method returns the Operator
124      * item associated to the value passed as argument.
125      * If the item associated to the value doesn't exist,
126      * the method returns <code>null</code>
127      * @param value key of the item to get
128      * @return Operator that is associated to the
129      * key passed as argument
130      */

131     public static OperatorType getAllowableOperators(String JavaDoc value) {
132         // if the property value is null, return a null value
133
if( value == null) {
134             return null;
135         }
136
137         // get the allowable item
138
OperatorType allowable = (OperatorType) operatorTypes.get(value);
139
140         // catch the exception, if the value is null
141
if (allowable == null) {
142             throw new IllegalStateException JavaDoc("Code:" + value);
143         }
144
145         return allowable;
146     }
147
148     /**
149      * Method that returns an array of the
150      * labels of the enumeration
151      * @return Array of strings with the labels
152      * of the enumeration
153      */

154     public static String JavaDoc[] getAllowableLabels(Locale JavaDoc locale) {
155         // ensure the locale is valid
156
if (locale == null)
157             throw new IllegalArgumentException JavaDoc("The locale object must not be null to retreive the labels");
158
159         // variables declaration
160
String JavaDoc [] labels = new String JavaDoc[operatorTypes.size()];
161         int i = 0;
162         Iterator JavaDoc iterator = operatorTypes.values().iterator();
163         // iterate through the items of the enumeration
164
// and get the labels of the items
165
while(iterator.hasNext()) {
166             OperatorType allowable = (OperatorType) iterator.next();
167             labels[i++] = allowable.getLabel(); //allowable.getResource(locale);
168
}
169         return labels;
170     }
171
172     /**
173      * Method that returns a collection of the
174      * values of the enumeration
175      * @return Collection object with the values
176      * of the enumeration
177      */

178     public static Collection JavaDoc getAllowableValues() {
179         return operatorTypes.keySet();
180     }
181
182     /**
183      * Method that returns all the values as a string.
184      * @return the values of the allowable code
185      */

186     public String JavaDoc toString () {
187         return operatorTypes.toString();
188     }
189
190
191 }
192
Popular Tags