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.util.struts.criteria;
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 display patterns of criteria associated
033: * to the search criteria. This class has the following patterns :
034: * <ul>
035: * <li>{@link #NO_OPERATOR_LIST Criterion with no operator, only an allowable list of elements}</li>
036: * <li>{@link #OPERATOR_INPUT Criterion with a operator and an input}</li>
037: * <li>{@link #NO_OPERATOR_MULTIPLE_LIST Criterition without operator and with a multiple selection list}</li>
038: * </ul>
039: *
040: * @author Philippe Brouillette
041: * @version 1.0
042: */
043: public class CriterionFormPatterns {
044:
045: /**
046: * Map of the items contained in the enumeration class
047: */
048: protected static Map formPatterns = new Hashtable();
049:
050: //Declaration of the constants of the enumeration class
051: /**
052: * Criterion with no operator, only an allowable list of elements
053: */
054: static CriterionFormPattern NO_OPERATOR_LIST = new CriterionFormPattern(
055: new String("NO_OPERATOR_LIST"), "NO_OPERATOR_LIST");
056: /**
057: * Criterion with a operator and an input
058: */
059: static CriterionFormPattern OPERATOR_INPUT = new CriterionFormPattern(
060: new String("OPERATOR_INPUT"), "OPERATOR_INPUT");
061: /**
062: * Criterition without operator and with a multiple selection list
063: */
064: static CriterionFormPattern NO_OPERATOR_MULTIPLE_LIST = new CriterionFormPattern(
065: new String("NO_OPERATOR_MULTIPLE_LIST"),
066: "NO_OPERATOR_MULTIPLE_LIST");
067:
068: // add the constants to the enumeration
069: static {
070: add(NO_OPERATOR_LIST);
071: add(OPERATOR_INPUT);
072: add(NO_OPERATOR_MULTIPLE_LIST);
073: }
074:
075: /**
076: * Method that adds an CriterionFormPattern to this map
077: * @param allowable CriterionFormPattern object that must be added
078: * to the map
079: */
080: protected static final void add(CriterionFormPattern allowable) {
081: formPatterns.put(allowable.getValue(), allowable);
082: }
083:
084: /**
085: * This method returns the Operator
086: * item associated to the value passed as argument.
087: * If the item associated to the value doesn't exist,
088: * the method returns <code>null</code>
089: * @param value key of the item to get
090: * @return Operator that is associated to the
091: * key passed as argument
092: */
093: public static CriterionFormPattern getAllowableFormPattern(
094: String value) {
095: // if the property value is null, return a null value
096: if (value == null) {
097: return null;
098: }
099:
100: // get the allowable item
101: CriterionFormPattern allowable = (CriterionFormPattern) formPatterns
102: .get(value);
103:
104: // catch the exception, if the value is null
105: if (allowable == null) {
106: throw new IllegalStateException("Code:" + value);
107: }
108:
109: return allowable;
110: }
111:
112: /**
113: * Method that returns an array of the
114: * labels of the enumeration
115: * @return Array of strings with the labels
116: * of the enumeration
117: */
118: public static String[] getAllowableLabels(Locale locale) {
119: // ensure the locale is valid
120: if (locale == null)
121: throw new IllegalArgumentException(
122: "The locale object must not be null to retreive the labels");
123:
124: // variables declaration
125: String[] labels = new String[formPatterns.size()];
126: int i = 0;
127: Iterator iterator = formPatterns.values().iterator();
128: // iterate through the items of the enumeration
129: // and get the labels of the items
130: while (iterator.hasNext()) {
131: CriterionFormPattern allowable = (CriterionFormPattern) iterator
132: .next();
133: labels[i++] = allowable.getLabel(); //allowable.getResource(locale);
134: }
135: return labels;
136: }
137:
138: /**
139: * Method that returns a collection of the
140: * values of the enumeration
141: * @return Collection object with the values
142: * of the enumeration
143: */
144: public static Collection getAllowableValues() {
145: return formPatterns.keySet();
146: }
147:
148: /**
149: * Method that returns all the values as a string.
150: * @return the values of the allowable code
151: */
152: public String toString() {
153: return formPatterns.toString();
154: }
155:
156: }
|