CVS: plexus-components/formica/src/java/org/codehaus/plexus/formica FormValidationResult.java,NONE,1.1 DefaultForm.java,1.1.1.1,1.2 Form.java,1.1.1.1,1.2
Jason van Zyl <[email protected]> Wed, 23 Jul 2003 11:33:57 -0500
| Newsgroups | gmane.comp.java.plexus.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/plexus/plexus-components/formica/src/java/org/codehaus/plexus/formica In directory hogshead.codehaus.org:/tmp/cvs-serv17437/src/java/org/codehaus/plexus/formica Modified Files: DefaultForm.java Form.java Added Files: FormValidationResult.java Log Message: o Collecting the results of validation so that we can do something with them. --- NEW FILE: FormValidationResult.java --- package org.codehaus.plexus.formica; import java.util.Map; import java.util.HashMap; import java.util.Iterator; /** * * * @author <a href="mailto:[email protected]">Jason van Zyl</a> * * @version $Id: FormValidationResult.java,v 1.1 2003/07/23 16:33:54 jvanzyl Exp $ */ public class FormValidationResult { /** Form element validation results. */ private Map elementValidationResults; /** Group validation results. */ private Map groupValidationResults; // ---------------------------------------------------------------------- // Accessors // ---------------------------------------------------------------------- public void addElementValidationResult( String id, boolean result ) { getElementValidationResults().put( id, new Boolean( result ) ); } public Map getElementValidationResults() { if ( elementValidationResults == null ) { elementValidationResults = new HashMap(); } return elementValidationResults; } public void addGroupValidationResult( String id, boolean result ) { getGroupValidationResults().put( id, new Boolean( result ) ); } public Map getGroupValidationResults() { if ( groupValidationResults == null ) { groupValidationResults = new HashMap(); } return groupValidationResults; } public boolean isValid() { for ( Iterator i = getElementValidationResults().values().iterator(); i.hasNext(); ) { Boolean b = (Boolean) i.next(); if ( !b.booleanValue() ) { return false; } } for ( Iterator i = getGroupValidationResults().values().iterator(); i.hasNext(); ) { Boolean b = (Boolean) i.next(); if ( !b.booleanValue() ) { return false; } } return true; } } Index: DefaultForm.java =================================================================== RCS file: /cvsroot/plexus/plexus-components/formica/src/java/org/codehaus/plexus/formica/DefaultForm.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- DefaultForm.java 1 Jun 2003 19:12:18 -0000 1.1.1.1 +++ DefaultForm.java 23 Jul 2003 16:33:54 -0000 1.2 @@ -1,50 +1,3 @@ -/*-- - - Copyright (C) 2001-2003 Anthony Eden. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions, and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions, and the disclaimer that follows - these conditions in the documentation and/or other materials - provided with the distribution. - - 3. The id "FormProc" must not be used to endorse or promote products - derived from this software without prior written permission. For - written permission, please contact [email protected]. - - 4. Products derived from this software may not be called "FormProc", nor - may "FormProc" appear in their id, without prior written permission - from Anthony Eden ([email protected]). - - In addition, I request (but do not require) that you include in the - end-user documentation provided with the redistribution and/or in the - software itself an acknowledgement equivalent to the following: - "This product includes software developed by - Anthony Eden (http://www.anthonyeden.com/)." - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - For more information on FormProc, please see <http://www.formica.org/>. - - */ - package org.codehaus.plexus.formica; import org.codehaus.plexus.formica.validation.Validator; @@ -58,29 +11,27 @@ import java.util.HashSet; import java.util.Set; -/** A form represents a collection of fields which can be validated. Every form - has a id which corresponds to a form definition in the formica.xml file. - In addition every form has a target object. When a form is processed each - field is written to the target object either through a setxxx() method or - through a method defined in the form's XML configuration file. - - @author Anthony Eden - */ public class DefaultForm implements Form { + /** The id of the form. */ private String id; + /** The object to populate. */ private Object target; + /** Map of form elements formElementId -> value. */ private Map formElementMap; + /** List of form elements for ordering purposes. */ private List formElements; + /** Skip null values during form validation. */ private boolean skipNullValues; + /** Validate null values during form validation. */ private boolean validateNullValues; + /** Form group validators. */ private Map groupValidators; + /** Reference to the form manager. */ private FormManager formManager; - /** Construct a new form. */ - public DefaultForm( FormManager formManager ) { this.formManager = formManager; @@ -90,42 +41,21 @@ groupValidators = new HashMap(); } - /** Get the form id. - - @return The form id - */ - public String getId() { return id; } - /** Set the form id. The form id given here should match the - form id specified in the configuration file. - - @param id The form id - */ - public void setId( String id ) { this.id = id; } - /** Get the target object. - - @return The target object - */ - public Object getTarget() { return target; } - /** Set the target object. - - @param target The target object - */ - public void setTarget( Object target ) { this.target = target; @@ -135,14 +65,13 @@ // Validation // ---------------------------------------------------------------------- - // Things that we might want to get back - // - // - validation results - // - error messages - - public void process( Map formData ) + public FormValidationResult process( Map formData ) throws Exception { + FormValidationResult result = new FormValidationResult(); + + // Element Validation + for ( Iterator i = getFormElements().iterator(); i.hasNext(); ) { FormElement fe = (FormElement) i.next(); @@ -152,7 +81,7 @@ { String data = (String) formData.get( fe.getId() ); boolean b = validator.validate( data, fe.getValidatorParameters() ); - // Store this + result.addElementValidationResult( fe.getId(), b ); } } @@ -176,9 +105,12 @@ if ( groupValidator != null ) { boolean b = groupValidator.validate( data, null ); + result.addGroupValidationResult( groupValidatorId, b ); // Store this } } + + return result; } @@ -216,10 +148,6 @@ this.skipNullValues = skipNullValues; } - /** Return true to skip validation, conversion and storage of null - values. - @return True to skip null values - */ public boolean skipNullValues() { return skipNullValues; @@ -230,9 +158,6 @@ this.validateNullValues = validateNullValues; } - /** Return true to validate null values. - @return True to validate null values - */ public boolean validateNullValues() { return validateNullValues; Index: Form.java =================================================================== RCS file: /cvsroot/plexus/plexus-components/formica/src/java/org/codehaus/plexus/formica/Form.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Form.java 1 Jun 2003 19:12:17 -0000 1.1.1.1 +++ Form.java 23 Jul 2003 16:33:54 -0000 1.2 @@ -21,7 +21,7 @@ Map getFormElementMap(); - void process( Map formData ) + FormValidationResult process( Map formData ) throws Exception; public void setGroupValidator( String groupValidatorId, String elementId );