KickJava   Java API By Example, From Geeks To Geeks.

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


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.Locale JavaDoc;
26
27 import org.mdarad.framework.expr.Operator;
28 import org.mdarad.framework.expr.OperatorTypes;
29
30 /**
31  * This classe representes a criterion that is used with "numeric" properties.
32  * It defines the operators used with a numeric criterion.
33  * @author Philippe Brouillette
34  * @version 1.0
35  */

36 public class NumericCriterion extends FormCriterionWithOperator {
37
38     /**
39      * Constructor that takes all the needed properties to
40      * initialize a numeric criterion.
41      * @param name name of the criterion, this name is used as a key
42      * in the criterion map
43      * @param associatedEntity class type associated to this criterion
44      * @param property property used for the query criterion
45      * @param bundleName bundle name
46      * @param locale locale information
47      * @see FormCriterion#FormCriterion(String, CriterionProperty, String, Locale) FormCriterion
48      */

49     public NumericCriterion(String JavaDoc name, Class JavaDoc associatedEntity, CriterionProperty property, String JavaDoc bundleName, Locale JavaDoc locale) {
50         super(name, associatedEntity, property, bundleName, locale);
51     }
52     
53     /**
54      * Constructor that takes all the properties to initialize a search
55      * criterion.
56      * @param name name of the criterion. This name must be unique
57      * as it is a key in a map.
58      * @param associatedEntity class type associated to this criterion
59      * @param property property used for the query criterion
60      * @param bundleName bundle name
61      * @param locale locale information
62      * @param isDynamic boolean that indicates if the criterion is dynamic
63      * @see FormCriterion#FormCriterion(String, CriterionProperty, String, Locale) FormCriterion
64      */

65     public NumericCriterion(String JavaDoc name, Class JavaDoc associatedEntity, CriterionProperty property, String JavaDoc bundleName, Locale JavaDoc locale, boolean isDynamic) {
66         super(name, associatedEntity, property, bundleName, locale, isDynamic);
67     }
68     
69     /**
70      * Constructor that clones a query criterion. This constructor is used
71      * to instanciate a criterion in a search form when the form
72      * contains dynamic criteria.
73      * @param criterion query criterion that must be of
74      * type <code>NumericCriterion</code>
75      * @see FormCriterion#FormCriterion(FormCriterion) FormCriterion
76      */

77     public NumericCriterion(NumericCriterion criterion) {
78         super(criterion);
79     }
80     
81     /**
82      * Method that assigns the value of the criterion as a String. This method
83      * is needed for the user interface which uses only string values.
84      * @param value value to be assigned
85      * @see FormCriterion#setPropertyValue(java.lang.String)
86      */

87     public void setPropertyValue(String JavaDoc value) {
88         if (value != null) {
89             try {
90                 setValue(new Integer JavaDoc(value));
91             } catch (NumberFormatException JavaDoc nfe) {
92                 // do nothing because the value is not an integer
93
}
94         }
95     }
96     
97     /**
98      * Method that returns the value as a string. In this case, it converts
99      * from Integer to String.
100      * @see FormCriterion#getPropertyValue()
101      */

102     public String JavaDoc getPropertyValue() {
103         if (getValue() != null) {
104             return getValue().toString();
105         }
106         
107         return "";
108     }
109
110     /**
111      * Method that returns the object type of the criterion value. In this
112      * case it returns a Integer object.
113      *
114      * @see FormCriterion#getObjectType()
115      */

116     public Class JavaDoc getObjectType() {
117         return Integer JavaDoc.class;
118     }
119
120     /**
121      * Returns the list of operators that can be used with this criterion. The operator
122      * must be instanciated as {@link Operator Operator}.
123      * @return array of operators
124      */

125     public Operator[] getOperators() {
126         
127         return new Operator[] {
128             new Operator("operator.numeric.equal.label", OperatorTypes.EQUAL, getBundle(), getLocale()),
129             new Operator("operator.numeric.lowerThan.label", OperatorTypes.LOWER_THAN, getBundle(), getLocale()),
130             new Operator("operator.numeric.higherThan.label", OperatorTypes.GREATER_THAN, getBundle(), getLocale()),
131             new Operator("operator.numeric.lowerThanOrEqual.label", OperatorTypes.LOWER_THAN_OR_EQUAL, getBundle(), getLocale()),
132             new Operator("operator.numeric.higherThanOrEqual.label", OperatorTypes.GREATER_THAN_OR_EQUAL, getBundle(), getLocale())
133         };
134     }
135
136     /**
137      * Method that returns the displaying pattern.
138      *
139      * @see FormCriterion#getFormPattern()
140      */

141     public CriterionFormPattern getFormPattern() {
142         return CriterionFormPatterns.OPERATOR_INPUT;
143     }
144 }
145
Popular Tags