1 20 package org.enhydra.barracuda.core.forms; 21 22 import java.util.*; 23 24 import org.enhydra.barracuda.plankton.*; 25 import org.apache.log4j.*; 26 27 60 public class DefaultFormValidator extends AbstractFormValidator { 61 62 protected static final Logger localLogger = Logger.getLogger(AbstractFormValidator.class.getName()); 63 64 protected List validators = new ArrayList(); 65 66 69 public DefaultFormValidator() { 70 this(null); 71 } 72 73 80 public DefaultFormValidator(String ierrorMessage) { 81 setErrorMessage(ierrorMessage); 82 } 83 84 89 public void addValidator(FormValidator validator) { 90 validators.add(validator); 91 } 92 93 98 public void removeValidator(FormValidator validator) { 99 validators.remove(validator); 100 } 101 102 107 public List getValidators() { 108 return new ArrayList(validators); 109 } 110 111 124 public void validate(FormElement element, FormMap map, boolean deferExceptions) throws ValidationException { 125 ValidationException ve = null; 126 if (localLogger.isInfoEnabled()) localLogger.info("Validating form"); 127 128 try { 130 if (element!=null) { 133 if (localLogger.isDebugEnabled()) localLogger.debug("Validating local form elements:"+element); 134 Object val = element.getOrigVal(); 138 140 validateFormElement(val, element, deferExceptions); 141 validateFormElement(val, element, map, deferExceptions); 142 143 } 144 145 if (element==null) { 148 if (localLogger.isDebugEnabled()) localLogger.debug("Validating form:"+map); 149 validateForm(map, deferExceptions); 150 } 151 } catch (DeferredValidationException dve) { 152 if (localLogger.isDebugEnabled()) localLogger.debug("Deferring Validation Exception", dve); 153 if (ve==null) ve = new DeferredValidationException(); 154 ve.addSubException(dve); 155 } 156 157 Iterator it = validators.iterator(); 159 while (it.hasNext()) { 160 FormValidator fv = (FormValidator) it.next(); 161 if (localLogger.isDebugEnabled()) localLogger.debug("Validating child:"+fv); 162 try {fv.validate(element, map, deferExceptions);} 163 catch (DeferredValidationException dve) { 164 if (localLogger.isDebugEnabled()) localLogger.debug("Deferring Child Validation Exception:", dve); 165 if (ve==null) ve = new DeferredValidationException(); 166 ve.addSubException(dve); 167 } 168 } 169 170 if (ve!=null) throw ve; 173 } 174 175 192 public void validateForm(FormMap map, boolean deferExceptions) throws ValidationException { 193 } 195 196 215 public void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException { 216 } 218 219 240 public void validateFormElement(Object val, FormElement element, FormMap map, boolean deferExceptions) throws ValidationException { 241 } 243 244 245 } 246 | Popular Tags |