View Javadoc

1   /*
2    * $Id: ValidatorDelegate.java,v 1.2 2004/04/09 09:47:37 eelco12 Exp $
3    * $Revision: 1.2 $
4    * $Date: 2004/04/09 09:47:37 $
5    *
6    * ====================================================================
7    * Copyright (c) 2003, Open Edge B.V.
8    * All rights reserved.
9    * Redistribution and use in source and binary forms, with or without 
10   * modification, are permitted provided that the following conditions are met:
11   * Redistributions of source code must retain the above copyright notice, 
12   * this list of conditions and the following disclaimer. Redistributions 
13   * in binary form must reproduce the above copyright notice, this list of 
14   * conditions and the following disclaimer in the documentation and/or other 
15   * materials provided with the distribution. Neither the name of OpenEdge B.V. 
16   * nor the names of its contributors may be used to endorse or promote products 
17   * derived from this software without specific prior written permission.
18   * 
19   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
20   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
21   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
22   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
23   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
24   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
25   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
26   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
27   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
28   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
29   * THE POSSIBILITY OF SUCH DAMAGE.
30   */
31  package nl.openedge.baritus;
32  
33  import java.util.Map;
34  
35  import org.infohazard.maverick.flow.ControllerContext;
36  
37  /***
38   * ValidatorDelegates can do validation on input and populated form beans.
39   * Besides the allways used DefaultValidatorDelegate, users of Baritus
40   * can register additional delegates, for instance to be able to plug in
41   * validator mechanisms like FormProc or Commons Validator.
42   * 
43   * @author Eelco Hillenius
44   */
45  interface ValidatorDelegate
46  {
47  	/***
48  	 * handle the validation for all provided parameters. The parameters consist
49  	 * typically of the request parameters, possibly (depending on the also
50  	 * provided instance of ExecutionParams) with the addition of Maverick
51  	 * configuration parameters, session attributes and request attributes.
52  	 * 
53  	 * Implementers should take care to only use the fields stored in parameters
54  	 * and not to get the field directly from e.g. the http request.
55  	 * 
56  	 * The populated form is stored in the formBeanContext. If implementors have
57  	 * validation errors, they should store the error messages in the instance of
58  	 * FormBeanContext (using method(s) setError/ setErrors), and they should save
59  	 * the original input values (as stored in Map parameters) as override values
60  	 * in the formBeanContext (using method(s) setOverrideField)
61  	 * 
62  	 * @param cctx controller context
63  	 * @param formBeanContext form bean context with populated bean
64  	 * @param execParams execution parameters
65  	 * @param parameters the map in which the requested values are stored. This
66  	 * 		map has at least the request parameters stored and depending on the
67  	 * 		execution parameters the maverick configuration parameters, session
68  	 * 		attributes and request attributes.
69  	 * @param succeeded whether population/ validation succeeded so far (did not
70  	 * 		generate any errors).
71  	 * @return whether validation passed
72  	 * 
73  	 * NOTE: implementors should take note that it is possible that population/ 
74  	 * 		validation allready failed before this method is called (in that case
75  	 * 		succeeded is false). If you do not want to override the errors (what
76  	 * 		is probably is good idea), you can check the current error map or 
77  	 * 		overwrite value map in the formBeanContext. This allways works for
78  	 * 		properties that failed to populate, though it might not work for
79  	 * 		failed validations as that depends on the registrations that the
80  	 * 		individual validators make in the error map.
81  	 */
82  	public boolean doValidation(
83  		ControllerContext cctx,
84  		FormBeanContext formBeanContext,
85  		ExecutionParams execParams,
86  		Map parameters,
87  		boolean succeeded);
88  }