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 Or extends AbstractFormValidator { 35 36 protected FormValidator _fv[]; 37 38 43 public Or(List fv) { 44 this(fv, null); 45 } 46 47 53 public Or(List fv, String ierrmsg) { 54 this((FormValidator[])fv.toArray(new FormValidator[1]), ierrmsg); 55 } 56 57 62 public Or(FormValidator [] fv) { 63 this(fv, null); 64 } 65 66 67 73 public Or(FormValidator [] fv, String ierrmsg) { 74 setErrorMessage(ierrmsg); 75 _fv = fv; 76 } 77 78 84 public Or(FormValidator fv1, FormValidator fv2) { 85 this(new FormValidator[] {fv1, fv2}, null); 86 } 87 88 95 public Or(FormValidator fv1, FormValidator fv2, String ierrmsg) { 96 this(new FormValidator[] {fv1, fv2}, ierrmsg); 97 } 98 99 106 public Or(FormValidator fv1, FormValidator fv2, FormValidator fv3) { 107 this(new FormValidator[] {fv1, fv2, fv3}, null); 108 } 109 110 118 public Or(FormValidator fv1, FormValidator fv2, FormValidator fv3, String ierrmsg) { 119 this(new FormValidator[] {fv1, fv2, fv3}, ierrmsg); 120 } 121 122 123 131 public Or(FormValidator fv1, FormValidator fv2, FormValidator fv3, FormValidator fv4) { 132 this(new FormValidator[] {fv1, fv2, fv3, fv4}, null); 133 } 134 135 144 public Or(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 160 public FormValidator[] getSubValidators() { 161 return _fv; 162 } 163 164 177 public void validate(FormElement element, FormMap map, boolean deferExceptions) throws ValidationException { 178 if (localLogger.isDebugEnabled()) { 179 localLogger.debug("Making sure validators" + _fv + " are valid"); 180 } 181 182 ValidationException veNew = null; 183 int exCount = 0; 184 for(int i = 0; i < _fv.length; i++) { 185 try { 186 if (_fv[i]!=null) { 187 _fv[i].validate(element, map, deferExceptions); 188 break; 190 } else { 191 veNew = this.generateException(element, deferExceptions, "A given Validator was null"); 192 exCount = _fv.length; 193 break; 194 } 195 } catch (ValidationException ve) { 196 if (veNew==null) { 197 veNew = this.generateException(element, deferExceptions, "Validators were invalid"); 198 } 199 veNew.addSubException(ve); 200 exCount++; 201 } 202 } 203 if (exCount==_fv.length) { 205 throw veNew; 206 } 207 } 208 } 209 | Popular Tags |