KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
26 import java.util.Locale JavaDoc;
27
28 import org.mdarad.framework.expr.Criterion;
29 import org.mdarad.framework.expr.Operator;
30 import org.mdarad.framework.expr.OperatorType;
31
32
33 /**
34  * This abstract class is a search criterion that uses an operator (ex: =, <, >, etc).
35  * USAGE: To use the search criterion, the implementation should derive from
36  * <code>FormCriterionWithOperator</code> and implements the method
37  * {@link #getOperators()() getOperators}.
38  * @author Philippe Brouillette
39  * @version 1.0
40  */

41 public abstract class FormCriterionWithOperator extends FormCriterion
42                                                 implements Serializable JavaDoc {
43
44     /**
45      * Constructor that takes all the properties to initialize a search
46      * criterion. By default, the criterion is dynamic.
47      * @param name name of the criterion. This name must be unique
48      * as it is a key in a map.
49      * @param associatedEntity class type associated to this criterion
50      * @param property property used for the query criterion
51      * @param bundleName bundle name
52      * @param locale locale information
53      * @see FormCriterion#FormCriterion(String, CriterionProperty, String, Locale) FormCriterion
54      */

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

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

85     public FormCriterionWithOperator(FormCriterionWithOperator criterion) {
86         super(criterion);
87     }
88
89     private Operator operator;
90     
91     /**
92      * Returns the list of operators that can be used with this criterion. The operator
93      * must be instanciated as {@link Operator Operator}.
94      * @return array of operators
95      */

96     abstract public Operator[] getOperators();
97
98
99     /**
100      * Return the opertator selected in the user interface as a string
101      * @return the selected operator as a string.
102      */

103     public String JavaDoc getOperator() {
104         if (operator != null) {
105             return operator.getKey();
106         }
107         else return new String JavaDoc();
108     }
109
110
111     /**
112      * Return the operator as an object type {@link Operator Operator}
113      * @return operator as an object.
114      */

115     public Operator getOperatorObject() {
116         return operator;
117     }
118     
119     
120     /**
121      * Method that set an operator using a string.
122      * @param operator stirng that contains the key of the operator.
123      */

124     public void setOperator(String JavaDoc operator) {
125         Operator [] operators = getOperators();
126         for (int i = 0; i < operators.length; i++) {
127             if (operators[i].getKey().equals(operator)) {
128                 this.operator = operators[i];
129             }
130         }
131     }
132     
133     /**
134      * Method that returns the criterion from the expression
135      * framework. ({@link Criterion})
136      * <p><b>NOTE:</b> The implementation must take care of the type
137      * of operator that is used to determine the criterion to use.
138      * @return the criterion
139      */

140     public Criterion getExprCriterion() {
141         Criterion crit = null;
142         OperatorType type = getOperatorObject().getType();
143         crit = new Criterion(getAssociatedEntity(), getProperty().getName(), type, getValue(), getLocale());
144     
145         return crit;
146     }
147 }
148
Popular Tags