KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > util > struts > criteria > CriterionFormPatterns


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.util.struts.criteria;
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 display patterns of criteria associated
33  * to the search criteria. This class has the following patterns :
34  * <ul>
35  * <li>{@link #NO_OPERATOR_LIST Criterion with no operator, only an allowable list of elements}</li>
36  * <li>{@link #OPERATOR_INPUT Criterion with a operator and an input}</li>
37  * <li>{@link #NO_OPERATOR_MULTIPLE_LIST Criterition without operator and with a multiple selection list}</li>
38  * </ul>
39  *
40  * @author Philippe Brouillette
41  * @version 1.0
42  */

43 public class CriterionFormPatterns {
44
45
46     /**
47      * Map of the items contained in the enumeration class
48      */

49     protected static Map JavaDoc formPatterns = new Hashtable JavaDoc();
50
51
52     //Declaration of the constants of the enumeration class
53
/**
54      * Criterion with no operator, only an allowable list of elements
55      */

56     static CriterionFormPattern NO_OPERATOR_LIST = new CriterionFormPattern(new String JavaDoc("NO_OPERATOR_LIST"), "NO_OPERATOR_LIST");
57     /**
58      * Criterion with a operator and an input
59      */

60     static CriterionFormPattern OPERATOR_INPUT = new CriterionFormPattern(new String JavaDoc("OPERATOR_INPUT"), "OPERATOR_INPUT");
61     /**
62      * Criterition without operator and with a multiple selection list
63      */

64     static CriterionFormPattern NO_OPERATOR_MULTIPLE_LIST = new CriterionFormPattern(new String JavaDoc("NO_OPERATOR_MULTIPLE_LIST"), "NO_OPERATOR_MULTIPLE_LIST");
65     
66     // add the constants to the enumeration
67
static {
68         add(NO_OPERATOR_LIST);
69         add(OPERATOR_INPUT);
70         add(NO_OPERATOR_MULTIPLE_LIST);
71     }
72
73
74     /**
75      * Method that adds an CriterionFormPattern to this map
76      * @param allowable CriterionFormPattern object that must be added
77      * to the map
78      */

79     protected static final void add(CriterionFormPattern allowable) {
80         formPatterns.put(allowable.getValue(), allowable);
81     }
82
83     /**
84      * This method returns the Operator
85      * item associated to the value passed as argument.
86      * If the item associated to the value doesn't exist,
87      * the method returns <code>null</code>
88      * @param value key of the item to get
89      * @return Operator that is associated to the
90      * key passed as argument
91      */

92     public static CriterionFormPattern getAllowableFormPattern(String JavaDoc value) {
93         // if the property value is null, return a null value
94
if( value == null) {
95             return null;
96         }
97
98         // get the allowable item
99
CriterionFormPattern allowable = (CriterionFormPattern) formPatterns.get(value);
100
101         // catch the exception, if the value is null
102
if (allowable == null) {
103             throw new IllegalStateException JavaDoc("Code:" + value);
104         }
105
106         return allowable;
107     }
108
109     /**
110      * Method that returns an array of the
111      * labels of the enumeration
112      * @return Array of strings with the labels
113      * of the enumeration
114      */

115     public static String JavaDoc[] getAllowableLabels(Locale JavaDoc locale) {
116         // ensure the locale is valid
117
if (locale == null)
118             throw new IllegalArgumentException JavaDoc("The locale object must not be null to retreive the labels");
119
120         // variables declaration
121
String JavaDoc [] labels = new String JavaDoc[formPatterns.size()];
122         int i = 0;
123         Iterator JavaDoc iterator = formPatterns.values().iterator();
124         // iterate through the items of the enumeration
125
// and get the labels of the items
126
while(iterator.hasNext()) {
127             CriterionFormPattern allowable = (CriterionFormPattern) iterator.next();
128             labels[i++] = allowable.getLabel(); //allowable.getResource(locale);
129
}
130         return labels;
131     }
132
133     /**
134      * Method that returns a collection of the
135      * values of the enumeration
136      * @return Collection object with the values
137      * of the enumeration
138      */

139     public static Collection JavaDoc getAllowableValues() {
140         return formPatterns.keySet();
141     }
142
143     /**
144      * Method that returns all the values as a string.
145      * @return the values of the allowable code
146      */

147     public String JavaDoc toString () {
148         return formPatterns.toString();
149     }
150
151
152 }
153
Popular Tags