KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12
13 import com.inversoft.util.ReflectionException;
14 import com.inversoft.util.ReflectionTools;
15 import com.inversoft.verge.mvc.validator.Validator;
16
17
18 /**
19  * <p>
20  * This class stores the configuration information for a
21  * single Validator within the Form-Based MVC.
22  * </p>
23  *
24  * @author Brian Pontarelli
25  * @since 2.0
26  * @version 2.0
27  */

28 public class BaseValidatorConfig extends BaseConfig {
29
30     private Class JavaDoc validator;
31     private String JavaDoc failure;
32     private List JavaDoc properties;
33
34
35     /**
36      * Construsts a new <code>BaseValidatorConfig</code> with the given mapping
37      * name and validator Class.
38      *
39      * @param validator The validator Class
40      * @param failure The name of the failure definition
41      */

42     public BaseValidatorConfig(Class JavaDoc validator, String JavaDoc failure) {
43         this.validator = validator;
44         this.failure = failure;
45         this.properties = new ArrayList JavaDoc();
46
47         if (validator != null) {
48             setName(validator.getName());
49         }
50     }
51
52     /**
53      * Construsts a new <code>BaseValidatorConfig</code> that is a copy of the
54      * given <code>BaseValidatorConfig</code>. This is a deep copy to the
55      * collection level, not the collection element level.
56      *
57      * @param base The base object to copy from
58      */

59     public BaseValidatorConfig(BaseValidatorConfig base) {
60         this.validator = base.validator;
61         this.failure = base.failure;
62         this.properties = new ArrayList JavaDoc(base.properties);
63
64         if (validator != null) {
65             setName(validator.getName());
66         }
67     }
68
69
70     /**
71      * Gets the failure definition for this validator configuration. This might
72      * be a URL, a node definition or a Mapping name or anything else that could
73      * possibly be used.
74      *
75      * @return The failure definition for this validator configuration.
76      */

77     public String JavaDoc getFailureDefinition() {
78         return failure;
79     }
80
81     /**
82      * Sets the failure definition for this validator configuration.
83      *
84      * @param failure The new failure definition
85      */

86     public void setFailureDefinition(String JavaDoc failure) {
87         this.failure = failure;
88     }
89
90     /**
91      * Gets the validator Class for this validator configuration.
92      *
93      * @return The validator Class object
94      */

95     protected Class JavaDoc getValidator() {
96         return validator;
97     }
98
99     /**
100      * Gets the validator Class for this validator configuration.
101      *
102      * @param validator The validator Class
103      */

104     void setValidator(Class JavaDoc validator) {
105         this.validator = validator;
106     }
107
108     /**
109      * Returns if this config has a validator class or not
110      *
111      * @return True if this config has a validator class, false if not
112      */

113     public boolean isValidating() {
114         return (validator != null);
115     }
116
117     /**
118      * Returns an new instance of the Validator for this form
119      */

120     public Validator newValidator() throws ReflectionException {
121         return (Validator) ReflectionTools.instantiate(validator);
122     }
123
124     /**
125      * Adds the given PropertyConfig to this validator
126      *
127      * @param property The property configuration to add
128      */

129     public void addProperty(PropertyConfig property) {
130         properties.add(property);
131     }
132
133     /**
134      * Returns a list of the property configurations for this validator. This list
135      * is not live and is a copy of the live list. This copy contains the same
136      * objects as the live list.
137      *
138      * @return The list of property configurations for this validator
139      */

140     public List JavaDoc getProperties() {
141         return new ArrayList JavaDoc(properties);
142     }
143
144     /**
145      * Returns whether or not this validator has any auto-validate properties
146      */

147     public boolean hasProperties() {
148         return (properties.size() > 0);
149     }
150
151     /**
152      * Removes the given PropertyConfig from this validator.
153      *
154      * @param propConfig The PropertyConfig to remove
155      */

156     void removeProperty(PropertyConfig propConfig) {
157         properties.remove(propConfig);
158     }
159 }
Popular Tags