KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > config > PropertyConfig


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.config;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13
14 /**
15  * <p>
16  * This class stores the configuration used to validate a
17  * single property within the form bean of the form based
18  * MVC.
19  * </p>
20  *
21  * @author Brian Pontarelli
22  * @since 2.0
23  * @version 2.0
24  */

25 public class PropertyConfig extends BaseConfig {
26
27     private String JavaDoc id;
28     private String JavaDoc property;
29     private String JavaDoc type;
30     private String JavaDoc key;
31     private String JavaDoc bundleName;
32     private String JavaDoc errorMsg;
33     private Map JavaDoc parameters;
34     private boolean primitiveWrapper;
35
36
37     /**
38      * Construsts a new <code>PropertyConfig</code>.
39      *
40      * @param id The name of the property to validate
41      * @param type The type of validator to use for validation
42      * @param key (optional) The key of the error message to generate on failed
43      * validation
44      * @param bundleName (optional) The name of the bundle from which to
45      * retrieve the error message to generate on failed validation
46      * @param errorMsg (optional) The error message to use if the key is not
47      * specified
48      * @param parameters The parameters to pass to the validator
49      */

50     public PropertyConfig(String JavaDoc id, String JavaDoc property, String JavaDoc type, String JavaDoc key,
51             String JavaDoc bundleName, String JavaDoc errorMsg, Map JavaDoc parameters) {
52         super(id + "." + property);
53         this.id = id;
54         this.property = property;
55         this.type = type;
56         this.key = key;
57         this.bundleName = bundleName;
58         this.errorMsg = errorMsg;
59         this.parameters = parameters;
60
61         if (type != null) {
62             primitiveWrapper = (type.equals("char") || type.equals("byte") ||
63                 type.equals("short") || type.equals("int") ||
64                 type.equals("long") || type.equals("float") ||
65                 type.equals("double"));
66         }
67     }
68
69
70     /**
71      * Returns the id of this property, which is the name of the form bean that
72      * this property belongs to.
73      *
74      * @return The id of the form bean
75      */

76     public String JavaDoc getID() {
77         return id;
78     }
79
80     /**
81      * Returns the name of the property that this property is associated with.
82      * This must be a valid property on the form bean described by id.
83      *
84      * @return The property name
85      */

86     public String JavaDoc getProperty() {
87         return property;
88     }
89
90     /**
91      * The name of the bundle to use to retrieve the error message from using the
92      * ErrorRegistry. This may be null.
93      *
94      * @return The bundle to use to retrieve the error message
95      */

96     public String JavaDoc getBundleName() {
97         return bundleName;
98     }
99
100     /**
101      * Gets the error message to use if the key was not specified. Could be null.
102      *
103      * @return The error message or null
104      */

105     public String JavaDoc getErrorMsg() {
106         return errorMsg;
107     }
108
109     /**
110      * The key to use to retrieve the error message from a the ErrorRegistry. This
111      * may be null.
112      *
113      * @return The key to use to retrieve the error message
114      */

115     public String JavaDoc getKey() {
116         return key;
117     }
118
119     /**
120      * The Map of parameters to pass to the validator. This Map is not the live
121      * Map. This is a copy of the live Map and contains the same key/value entries
122      * that the live list contains.
123      *
124      * @return The Map of parameters
125      */

126     public Map JavaDoc getParameters() {
127         return new HashMap JavaDoc(parameters);
128     }
129
130     /**
131      * Sets the Map of parameters to pass to the validator.
132      *
133      * @param parameters The new parameters
134      */

135     void setParameters(Map JavaDoc parameters) {
136         this.parameters = parameters;
137     }
138
139     /**
140      * Returns the live modifiable Map of parameters.
141      *
142      * @return The live Map. Changes effect this class and should not be made
143      * except during startup
144      */

145     Map JavaDoc getLiveParameters() {
146         return parameters;
147     }
148
149     /**
150      * The type of validation to use to validate the property.
151      *
152      * @return The type of validation to do
153      */

154     public String JavaDoc getType() {
155         return type;
156     }
157
158     /**
159      * Sets the type of validation to perform on the property.
160      *
161      * @param type The new type
162      */

163     void setType(String JavaDoc type) {
164         this.type = type;
165     }
166
167     /**
168      * Returns true if the type is one of the special primitive/wrapper types
169      * (i.e. char, int, float, double, etc).
170      */

171     public boolean isPrimitiveOrWrapper() {
172         return primitiveWrapper;
173     }
174 }
Popular Tags