KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > forms > FormValidator


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: FormValidator.java,v 1.8 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.forms;
21
22 import java.util.*;
23
24 /**
25  * <p>A FormValidator is designed to validate one or more FormElements
26  * within a FormMap, OR a FormMap itself. The real work occurs in the
27  * validate() method.
28  *
29  * <p>When the validate method is invoked, we start by performing element
30  * level validation by invoking the validateFormElement() methods for each
31  * of the elements in the form. If that succeeds, we validate the whole
32  * map by invoking validateForm() method to validate the form itself. Finally,
33  * we invoke any child validators. In this way, a validator is not considered
34  * validated until all it's rules plus those for all of it's children have
35  * passed muster.
36  *
37  * <p>When an invalid condition occurs, typically the developer will throw
38  * a ValidationException, which stops the validation process immediately and
39  * returns the specified error. There are times, however, where the developer
40  * will want to try and validate as many of the rules as possible in order
41  * to return all known errors at once. In this case, the developer should throw
42  * DeferredValidationExceptions. These are caught internally and added to one
43  * master validation exception, which is thrown when the validation process
44  * completes.
45  */

46 public interface FormValidator {
47
48     /**
49      * Set the error message to be used in the event of an error.
50      *
51      * @param ierrorMessage the error message to be used in the event
52      * of an error
53      */

54     public void setErrorMessage(String JavaDoc ierrorMessage);
55
56     /**
57      * Get the error message to be used in the event of an error.
58      *
59      * @return the error message to be used in the event
60      * of an error
61      */

62     public String JavaDoc getErrorMessage();
63
64     /**
65      * Set our defer policy. True indicates we whould throw
66      * DeferredValidationExceptions in the event of an error.
67      * By default, we throw regular ValidationExceptions.
68      *
69      * @param val true if we want to throw DeferredValidationExceptions
70      * as opposed to regular ValidationExceptions
71      */

72 // public void setDeferExceptions(boolean val);
73

74     /**
75      * Get our defer policy. True indicates we whould throw
76      * DeferredValidationExceptions in the event of an error.
77      *
78      * @return true if we want to throw DeferredValidationExceptions
79      * as opposed to regular ValidationExceptions
80      */

81 // public boolean deferExceptions();
82

83     /**
84      * Add a child validator
85      *
86      * @param validator the child validator to be added
87      */

88 // public void addValidator(FormValidator validator);
89

90     /**
91      * Remove a child validator
92      *
93      * @param validator the child validator to be removed
94      */

95 // public void removeValidator(FormValidator validator);
96

97     /**
98      * Get a list of all child validators
99      *
100      * @return a list of all child validators
101      */

102 // public List getValidators();
103

104     /**
105      * Validate a FormElement locally and allow any child
106      * validators a chance to validate as well.
107      *
108      * @param element the form element to be validated (null indicates
109      * we want to perform form level validation)
110      * @param formMap the map to which the element belongs (sometimes necessary
111      * to validate elements by comparing them with other elements)
112      * @param deferExceptions do we want to deferValidation exceptions
113      * and attempt to validate all elements so that we can process
114      * all the exceptions at once
115      * @throws ValidationException if the element is not valid
116      */

117     public void validate(FormElement element, FormMap formMap, boolean deferExceptions) throws ValidationException;
118
119     /**
120      * Validate an entire FormMap. This is the method developers should
121      * override to provide specific validation for the entire form, as
122      * opposed to validating a specific element within the form.
123      *
124      * To indicate a form is invalid, through a ValidationException,
125      * which will interrupt the validation process immediately. If you
126      * want to indicate an error, but would still like validation to
127      * continue (so that you can identify multiple errors in one
128      * validation pass) throw a DeferredValidationException instead.
129      *
130      * @param map the map to be validated
131      * @param deferExceptions do we want to deferValidation exceptions
132      * and attempt to validate all elements so that we can process
133      * all the exceptions at once
134      * @throws ValidationException if the element is not valid
135      */

136 // public void validateForm(FormMap map, boolean deferExceptions) throws ValidationException;
137

138     /**
139      * Validate a FormElement. This is the method developers should
140      * override to provide specific validation based on the value
141      * and (potentially) information contained in the FormElement.
142      *
143      * To indicate an element is invalid, through a ValidationException,
144      * which will interrupt the validation process immediately. If you
145      * want to indicate an error, but would still like validation to
146      * continue (so that you can identify multiple errors in one
147      * validation pass) throw a DeferredValidationException instead.
148      *
149      * @param val the actual value to be validated
150      * @param element the form element that contains the val
151      * to validate elements by comparing them with other elements)
152      * @param deferExceptions do we want to deferValidation exceptions
153      * and attempt to validate all elements so that we can process
154      * all the exceptions at once
155      * @throws ValidationException if the element is not valid
156      */

157 // public void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException;
158

159     /**
160      * Validate a FormElement. This is the method developers should
161      * override to provide specific validation based on the value
162      * and (potentially) information contained in the FormElement and
163      * FormMap structures.
164      *
165      * To indicate an element is invalid, through a ValidationException,
166      * which will interrupt the validation process immediately. If you
167      * want to indicate an error, but would still like validation to
168      * continue (so that you can identify multiple errors in one
169      * validation pass) throw a DeferredValidationException instead.
170      *
171      * @param val the actual value to be validated
172      * @param element the form element that contains the val
173      * @param map the map to which the element belongs (sometimes necessary
174      * to validate elements by comparing them with other elements)
175      * @param deferExceptions do we want to deferValidation exceptions
176      * and attempt to validate all elements so that we can process
177      * all the exceptions at once
178      * @throws ValidationException if the element is not valid
179      */

180 // public void validateFormElement(Object val, FormElement element, FormMap map, boolean deferExceptions) throws ValidationException;
181

182     /**
183      * @supplierCardinality 0..*
184      */

185     /*#FormValidator lnkFormValidator;*/
186
187     /**
188      * @supplierCardinality 0..*
189      */

190     /*#FormMap lnkFormMap;*/
191
192
193     // ilc_02212001 start
194
// added new method to check for nullness
195
/**
196      * Check if val passed is null in a consistant manner.
197      * Most validators should call isNull(val) first thing
198      * and return if that is the case. Leave null validation
199      * up to NotNullValidator.
200      *
201      * @param val the value to test for nullness
202      */

203     public boolean isNull(Object JavaDoc val, FormElement element);
204     // ilc_02212001 End
205

206 }
207
Popular Tags