1 20 package org.enhydra.barracuda.core.forms; 21 22 import java.util.*; 23 24 import org.enhydra.barracuda.core.forms.*; 25 import org.enhydra.barracuda.plankton.*; 26 27 34 public class And extends AbstractFormValidator { 35 36 protected FormValidator _fv[]; 37 38 43 public And(List fv) { 44 this(fv, null); 45 } 46 47 53 public And(List fv, String ierrmsg) { 54 this((FormValidator[])fv.toArray(new FormValidator[1]), ierrmsg); 55 } 56 57 62 public And(FormValidator [] fv) { 63 this(fv, null); 64 } 65 66 67 73 public And(FormValidator [] fv, String ierrmsg) { 74 setErrorMessage(ierrmsg); 75 _fv = fv; 76 } 77 78 84 public And(FormValidator fv1, FormValidator fv2) { 85 this(new FormValidator[] {fv1, fv2}, null); 86 } 87 88 95 public And(FormValidator fv1, FormValidator fv2, String ierrmsg) { 96 this(new FormValidator[] {fv1, fv2}, ierrmsg); 97 } 98 99 106 public And(FormValidator fv1, FormValidator fv2, FormValidator fv3) { 107 this(new FormValidator[] {fv1, fv2, fv3}, null); 108 } 109 110 118 public And(FormValidator fv1, FormValidator fv2, FormValidator fv3, String ierrmsg) { 119 this(new FormValidator[] {fv1, fv2, fv3}, ierrmsg); 120 } 121 122 123 131 public And(FormValidator fv1, FormValidator fv2, FormValidator fv3, FormValidator fv4) { 132 this(new FormValidator[] {fv1, fv2, fv3, fv4}, null); 133 } 134 135 144 public And(FormValidator fv1, FormValidator fv2, FormValidator fv3, FormValidator fv4, String ierrmsg) { 145 this(new FormValidator[] {fv1, fv2, fv3, fv4}, ierrmsg); 146 } 147 148 149 150 151 152 161 public FormValidator[] getSubValidators() { 162 return _fv; 163 } 164 165 178 public void validate(FormElement element, FormMap map, boolean deferExceptions) throws ValidationException { 179 if (localLogger.isDebugEnabled()) { 180 localLogger.debug("Making sure validators" + _fv + " are valid"); 181 } 182 183 try { 184 for(int i = 0; i < _fv.length; i++) { 185 if (_fv[i]!=null) { 186 _fv[i].validate(element, map, deferExceptions); 187 } else { 188 throw this.generateException(element, deferExceptions, "A given Validator was null"); 189 } 190 } 191 } catch (ValidationException ve) { 192 ValidationException veNew = this.generateException(element, deferExceptions, "Validators were invalid"); 193 veNew.addSubException(ve); 194 throw veNew; 195 } 196 } 197 } 198 | Popular Tags |