001: /*
002: Mdarad-Toolobox is a collection of tools for Architected RAD
003: (Rapid Application Development) based on an MDA approach.
004: The toolbox contains frameworks and generators for many environments
005: (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
006: applications from a design Model
007: Copyright (C) 2004-2005 Elapse Technologies Inc.
008:
009: This library is free software; you can redistribute it and/or
010: modify it under the terms of the GNU General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: General Public License for more details.
018:
019: You should have received a copy of the GNU General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: package org.mdarad.framework.expr;
024:
025: import java.util.Collection;
026: import java.util.Hashtable;
027: import java.util.Iterator;
028: import java.util.Locale;
029: import java.util.Map;
030:
031: /**
032: * This class keeps the possible values of the operator types associated
033: * to the search criteria.
034: * <ul>
035: * <li>{@link #EQUAL Equal Operator}</li>
036: * <li>{@link #LOWER_THAN Lower than operator type}</li>
037: * <li>{@link #LOWER_THAN_OR_EQUAL Lower than or equal operator type}</li>
038: * <li>{@link #GREATER_THAN Greater than operator type}</li>
039: * <li>{@link #GREATER_THAN_OR_EQUAL Greater than or equal operator type}</li>
040: * <li>{@link #BOOLEAN Boolean operator type}</li>
041: * <li>{@link #LIKE Like operator type}</li>
042: * <li>{@link #START_WITH Starts with operator}</li>
043: * <li>{@link #END_WITH Ends with operator}</li>
044: * </ul>
045: *
046: * @author Philippe Brouillette
047: * @version 1.0
048: */
049: public class OperatorTypes {
050:
051: /**
052: * Map of the items contained in the enumeration class
053: */
054: protected static Map operatorTypes = new Hashtable();
055:
056: //Constants
057: /**
058: * Equal Operator
059: */
060: public static OperatorType EQUAL = new OperatorType(new String(
061: "EQUAL"), "EQUAL");
062: /**
063: * Lower than operator type
064: */
065: public static OperatorType LOWER_THAN = new OperatorType(
066: new String("LOWER_THAN"), "LOWER_THAN");
067: /**
068: * Lower than or equal operator type
069: */
070: public static OperatorType LOWER_THAN_OR_EQUAL = new OperatorType(
071: new String("LOWER_OR_EQUAL"), "LOWER_OR_EQUAL");
072: /**
073: * Greater than operator type
074: */
075: public static OperatorType GREATER_THAN = new OperatorType(
076: new String("GREATER_THAN"), "GREATER_THAN");
077: /**
078: * Greater than or equal operator type
079: */
080: public static OperatorType GREATER_THAN_OR_EQUAL = new OperatorType(
081: new String("GREATER_THAN_OR_EQUAL"),
082: "GREATER_THAN_OR_EQUAL");
083: /**
084: * boolean operator type
085: */
086: public static OperatorType BOOLEAN = new OperatorType(new String(
087: "BOOLEAN"), "BOOLEAN");
088: /**
089: * Like operator type
090: */
091: public static OperatorType LIKE = new OperatorType(new String(
092: "LIKE"), "LIKE");
093: /**
094: * Starts with operator
095: */
096: public static OperatorType START_WITH = new OperatorType(
097: new String("START_WITH"), "START_WITH");
098: /**
099: * Ends with operator
100: */
101: public static OperatorType END_WITH = new OperatorType(new String(
102: "END_WITH"), "END_WITH");
103: /**
104: * In operator
105: */
106: public static OperatorType IN = new OperatorType(new String("IN"),
107: "IN");
108:
109: // add the constants to the enumeration
110: static {
111: add(EQUAL);
112: add(LOWER_THAN);
113: add(GREATER_THAN);
114: add(LOWER_THAN_OR_EQUAL);
115: add(GREATER_THAN_OR_EQUAL);
116: add(BOOLEAN);
117:
118: }
119:
120: /**
121: * Method that adds an OperatorType to this map
122: * @param allowable OperatorType that must be added
123: * to the map
124: */
125: protected static final void add(OperatorType allowable) {
126: operatorTypes.put(allowable.getValue(), allowable);
127: }
128:
129: /**
130: * This method returns the Operator
131: * item associated to the value passed as argument.
132: * If the item associated to the value doesn't exist,
133: * the method returns <code>null</code>
134: * @param value key of the item to get
135: * @return Operator that is associated to the
136: * key passed as argument
137: */
138: public static OperatorType getAllowableOperators(String value) {
139: // if the property value is null, return a null value
140: if (value == null) {
141: return null;
142: }
143:
144: // get the allowable item
145: OperatorType allowable = (OperatorType) operatorTypes
146: .get(value);
147:
148: // catch the exception, if the value is null
149: if (allowable == null) {
150: throw new IllegalStateException("Code:" + value);
151: }
152:
153: return allowable;
154: }
155:
156: /**
157: * Method that returns an array of the
158: * labels of the enumeration
159: * @return Array of strings with the labels
160: * of the enumeration
161: */
162: public static String[] getAllowableLabels(Locale locale) {
163: // ensure the locale is valid
164: if (locale == null)
165: throw new IllegalArgumentException(
166: "The locale object must not be null to retreive the labels");
167:
168: // variables declaration
169: String[] labels = new String[operatorTypes.size()];
170: int i = 0;
171: Iterator iterator = operatorTypes.values().iterator();
172: // iterate through the items of the enumeration
173: // and get the labels of the items
174: while (iterator.hasNext()) {
175: OperatorType allowable = (OperatorType) iterator.next();
176: labels[i++] = allowable.getLabel(); //allowable.getResource(locale);
177: }
178: return labels;
179: }
180:
181: /**
182: * Method that returns a collection of the
183: * values of the enumeration
184: * @return Collection object with the values
185: * of the enumeration
186: */
187: public static Collection getAllowableValues() {
188: return operatorTypes.keySet();
189: }
190:
191: /**
192: * Method that returns all the values as a string.
193: * @return the values of the allowable code
194: */
195: public String toString() {
196: return operatorTypes.toString();
197: }
198:
199: }
|