01: /*
02: * Copyright 2006 Dan Shellman
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.iscreen;
17:
18: /**
19: * Implementations of this interface are expected to validate a JavaBean's
20: * properties. The JavaBean to be validated is the one returned by the call
21: * to constructBeanToValidate().
22: *
23: * The lifecycle of Validators (implementations of this interface) is as
24: * follows: <br />
25: * <ul>
26: * <li>Construction: Validators should have a public, no-parameter constructor.</li>
27: * <li>Constraints: Constraints (properties) on the Validator (from configuration)
28: * are set.</li>
29: * <li>Failure Messages: Properties configured as "Failure Messages" are set.
30: * These properties are used to report validation failures.</li>
31: * <li>For each validation: constructBeanToValidate() is called to get the JavaBean
32: * that will have properties mapped to it so that the
33: * constructed bean can be passed in to the validate() method.</li>
34: * <li>For each validation: validate() is called to validate the passed in JavaBean.</li>
35: * </ul>
36: *
37: * @author Shellman, Dan
38: */
39: public interface Validator {
40: /**
41: * This is the method that's called to validate the "bean-to-validate."
42: * Use the passed in ValidatorContext to report validation failures, etc.
43: * The passed-in "bean-to-validate" is the same instance returned from
44: * the call to constructBeanToValidate(), but with all of the appropriate
45: * properties set (based upon the configured mapping).
46: *
47: * @param context The ValidatorContext, which is used to report failures.
48: * @param beanToValidate The JavaBean to validate.
49: */
50: void validate(ValidatorContext context, Object beanToValidate);
51:
52: /**
53: * This is called prior to calling the validate() method. This method is
54: * meant to construct a JavaBean that will have properties mapped to it
55: * for use by the validator.
56: *
57: * @return Returns a JavaBean that will have properties mapped to it for
58: * use by the call to the validate() method.
59: */
60: Object constructBeanToValidate();
61: }
|