KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > expr > Operator


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.expr;
24
25 import java.io.Serializable JavaDoc;
26 import java.util.Locale JavaDoc;
27
28 import org.mdarad.framework.resources.ResourceMapped;
29 import org.mdarad.framework.resources.ResourcesUtils;
30
31 /**
32  * This class represents a criterion operator. It is used with the
33  * {@link Criterion} class.
34  * @author Philippe Brouillette
35  * @version 1.0
36  * @since 1.4
37  */

38 public class Operator implements Serializable JavaDoc,
39                                  ResourceMapped {
40
41     /**
42      * Constructor that takes all the argument to get a resources
43      * bundle
44      * @param key key of the resource
45      * @param type operator type
46      * @param bundleName resource bundle
47      * @param locale Locale object to get the right language.
48      */

49     public Operator(String JavaDoc key, OperatorType type, String JavaDoc bundleName, Locale JavaDoc locale) {
50         setKey(key);
51         setType(type);
52         setLocale(locale);
53         setBundle(bundleName);
54     }
55
56     /**
57      * Constructor that associates the resource key with
58      * an operator type.
59      * @param key resource key
60      * @param type operator
61      */

62     public Operator(String JavaDoc key, OperatorType type) {
63         this(key, type, "", null);
64     }
65
66     /**
67      * Property that keeps the resource key that identifies
68      * this operator.
69      */

70     private String JavaDoc key;
71
72     /**
73      * Getter for the resource key of the operator.
74      * @return resource key of the operator
75      */

76     public String JavaDoc getKey() {
77         return key;
78     }
79
80     /**
81      * Setter for the resource key of the operator.
82      * @param the resource key of the operator.
83      */

84     public void setKey(String JavaDoc key) {
85         this.key = key;
86     }
87
88     /**
89      * Property that keeps the operator type as
90      * an allowable value from an enumeration class
91      */

92     private OperatorType type;
93
94     public OperatorType getType() {
95         return type;
96     }
97
98     public void setType(OperatorType type) {
99         this.type = type;
100     }
101
102     /**
103      * Method that returns the resource from the bundle name
104      * @param bundleName resource bundle name
105      * @param locale objet locale informations
106      * @return resource from the bundle associated with the key
107      */

108     public String JavaDoc getResource(String JavaDoc bundleName, Locale JavaDoc locale) {
109         String JavaDoc label = ResourcesUtils.getMessage(bundleName, getKey(), locale);
110         return label;
111         
112     }
113
114     /**
115      * Method that returns the resource from the bundle
116      * @return resource as a string
117      */

118     public String JavaDoc getResource() {
119         return getResource(getBundle(), getLocale());
120     }
121
122     /**
123      * Method that keeps the locales informations
124      */

125     private Locale JavaDoc locale = Locale.getDefault();
126
127     public Locale JavaDoc getLocale() {
128         return locale;
129     }
130
131     public void setLocale(Locale JavaDoc locale) {
132         if (locale != null) {
133             this.locale = locale;
134         }
135     }
136
137     /**
138      * Property that keeps the resource bundle name
139      */

140     private String JavaDoc bundleName = "";
141     
142     public String JavaDoc getBundle() {
143         return bundleName;
144     }
145
146     public void setBundle(String JavaDoc bundle) {
147         this.bundleName = bundle;
148     }
149 }
Popular Tags