Source code: com/aendvari/griffin/validation/validator/Handler.java
1 /*
2 * Handler.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 * See the file LICENSE for terms of use.
7 *
8 */
9
10 package com.aendvari.griffin.validation.validator;
11
12 import java.io.*;
13 import java.util.*;
14 import java.beans.*;
15
16 import java.lang.reflect.*;
17 import java.lang.NoSuchMethodException;
18 import java.lang.IllegalAccessException;
19
20 import com.aendvari.common.*;
21
22 import com.aendvari.common.model.*;
23
24 import com.aendvari.griffin.validation.*;
25 import com.aendvari.griffin.validation.dataset.*;
26 import com.aendvari.griffin.validation.validator.*;
27
28
29 /**
30 * <p>This is the base class for handler classes.</p>
31 *
32 * <p>The {@link ErrorMethod} and {@link Handler} are both Handlers.</p>
33 *
34 * <p>
35 * A Handler is a described object that has a method and it's parameters.
36 * It is used to execute a Class's method with the required parameter values.
37 * </p>
38 *
39 * @author Scott Milne
40 *
41 */
42
43 public abstract class Handler
44 {
45 /* Variables */
46
47 /** The name of the handler. */
48 protected String name;
49
50 /** The name of the object (if defined) to use for calling validation methods */
51 protected String handlerObject;
52
53 /** The name of the class (if defined) to use for calling validation methods */
54 protected String handlerClass;
55
56 /** The {@link HandlerMethod} to call from the handlerObject or handlerClass */
57 protected HandlerMethod handlerMethod;
58
59 /** The list of parameter "define" name/value pairs to use for the method */
60 protected HashMap parameterDefines;
61
62
63 /* Constructors. */
64
65
66 /**
67 * Constructs a <code>Handler</code> instance.
68 *
69 */
70
71 public Handler()
72 {
73 parameterDefines = new HashMap();
74
75 name = "";
76 handlerObject = "";
77 handlerClass = "";
78 }
79
80 /**
81 * Get the name of the handler.
82 *
83 * @return The name of the handler.
84 *
85 */
86
87 public String getName()
88 {
89 return name;
90 }
91
92 /**
93 * Set the name of the handler.
94 *
95 * @param setName The name of the handler.
96 *
97 */
98
99 public void setName( String setName )
100 {
101 name = setName;
102 }
103
104 /**
105 * Get the handlerObject of the handler.
106 *
107 * @return The handlerObject of the handler.
108 *
109 */
110
111 public String getHandlerObject()
112 {
113 return handlerObject;
114 }
115
116 /**
117 * Set the handlerObject of the handler.
118 *
119 * @param setHandlerObject The handlerObject of the handler.
120 *
121 */
122
123 public void setHandlerObject( String setHandlerObject )
124 {
125 handlerObject = setHandlerObject;
126 }
127
128 /**
129 * Get the classpath for the Class of the handler.
130 *
131 * @return The handlerClass of the handler.
132 *
133 */
134
135 public String getHandlerClass()
136 {
137 return handlerClass;
138 }
139
140 /**
141 * Set the classpath for the Class of the handler.
142 *
143 * @param setHandlerClass The classpath to the Class of the handler.
144 *
145 */
146
147 public void setHandlerClass( String setHandlerClass )
148 {
149 handlerClass = setHandlerClass;
150 }
151
152 /**
153 * Get the handler method.
154 *
155 * @return The {@link HandlerMethod} instance.
156 *
157 */
158
159 public HandlerMethod getValidateMethod()
160 {
161 return handlerMethod;
162 }
163
164 /**
165 * Set the handler method.
166 *
167 * @param setMethod A {@link HandlerMethod} instance.
168 *
169 */
170
171 public void setHandlerMethod( HandlerMethod setMethod )
172 {
173 handlerMethod = setMethod;
174 }
175
176 /**
177 * Add a param define.
178 *
179 * @param name The name of the parameter define.
180 * @param define The {@link ParameterDefine} instance to add.
181 *
182 */
183
184 public void setParameterDefine( String name, ParameterDefine define )
185 {
186 parameterDefines.put(name, define);
187 }
188
189 /**
190 * Get the default value of a parameter define.
191 *
192 * @param name The name of the parameter define.
193 *
194 * @return String for the default value of the parameter define.
195 *
196 */
197
198 public ParameterDefine getParameterDefine( String name )
199 {
200 return (ParameterDefine)parameterDefines.get(name);
201 }
202
203 /**
204 * Get the count of parameter defines.
205 *
206 * @return The parameter defines.
207 *
208 */
209
210 public int getParameterDefineCount()
211 {
212 return parameterDefines.size();
213 }
214
215 /**
216 * Verify that the given name is a parameter define.
217 *
218 * @param name The name of the parameter define.
219 *
220 */
221
222 public boolean isValidParameterDefine( String name )
223 {
224 return parameterDefines.containsKey(name);
225 }
226
227 /**
228 * Executes this classes' part of a <code>Dataset</code> validation.
229 *
230 * @param property A {@link Property} instance for the value to test.
231 * @param handlers A <code>HashMap</code> of {@link ValidationHandler} instances.
232 *
233 * @return Returns boolean for determining if the validate was successful.
234 *
235 */
236
237 public abstract boolean executeValidation( Property property, HashMap handlers ) throws Exception;
238
239 /**
240 * Convert this object into a String representation.
241 *
242 */
243
244 public String toString()
245 {
246 String data = "Handler [";
247 data += "name=" + name + ",";
248 data += "handlerObject=" + handlerObject + ",";
249 data += "handlerClass=" + handlerClass + ",";
250 data += "handlerMethod=" + handlerMethod + ",";
251 data += "parameterDefines="+parameterDefines;
252 data += "]";
253 return data;
254 }
255 }
256