KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
32  * This classe representes a criterion that is used with "string" properties.
33  * It defines the operators used with a numeric criterion.
34  * @author Philippe Brouillette
35  * @version 1.0
36  */

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

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

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

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

88     public void setPropertyValue(String JavaDoc value) {
89         if (value != null) {
90             setValue(value);
91         }
92     }
93     
94     /**
95      * Method that returns the value as a string. In this case, it converts
96      * from String to String.
97      * @see FormCriterion#getPropertyValue()
98      */

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

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

123     public Operator[] getOperators() {
124         return new Operator[] {
125             new Operator("operator.string.like.label", OperatorTypes.LIKE, getBundle(), getLocale()),
126             new Operator("operator.string.startWith.label", OperatorTypes.START_WITH, getBundle(), getLocale()),
127             new Operator("operator.string.endWith.label", OperatorTypes.END_WITH, getBundle(), getLocale())
128         };
129     }
130
131     /**
132      * Method that returns the displaying pattern.
133      *
134      * @see FormCriterion#getFormPattern()
135      */

136     public CriterionFormPattern getFormPattern() {
137         return CriterionFormPatterns.OPERATOR_INPUT;
138     }
139 }
140
Popular Tags