1 23 24 package org.infoglue.cms.entities.kernel; 25 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 import org.infoglue.cms.util.ConstraintExceptionBuffer; 30 import org.infoglue.cms.util.validators.Constants; 31 import org.infoglue.cms.util.validators.ConstraintRule; 32 import org.infoglue.cms.util.validators.ConstraintRuleList; 33 import org.infoglue.cms.util.validators.EmailValidator; 34 import org.infoglue.cms.util.validators.StringValidator; 35 36 48 49 51 public abstract class ValidatableEntityVO implements BaseEntityVO 52 { 53 57 60 protected ConstraintRuleList rules = new ConstraintRuleList();; 61 62 public ConstraintRule getRule(String fieldName) 63 { 64 return rules.getRule(fieldName); 65 } 66 67 68 73 public Collection getConstraintRules() 74 { 75 return rules.getRules(); 76 } 77 78 82 public ConstraintRuleList getConstraintRuleList() 83 { 84 return rules; 85 } 86 87 public abstract void PrepareValidation(); 88 89 92 public ConstraintExceptionBuffer validate() 93 { 94 return validate(this); 95 } 96 97 public ConstraintExceptionBuffer validate(ValidatableEntityVO vo) 98 { 99 105 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 106 107 vo.PrepareValidation(); 109 110 Iterator iterator = vo.getConstraintRules().iterator(); 112 while (iterator.hasNext()) 113 { 114 ConstraintRule cr = (ConstraintRule) iterator.next(); 115 Integer intId = vo.getId(); 116 117 switch (cr.getConstraintType()) 119 { 120 case Constants.EMAIL: 121 { 122 if (cr.getValue() != null) 123 { 124 EmailValidator v = new EmailValidator(cr.getFieldName()); 126 127 v.setObjectClass(vo.getConstraintRuleList().getEntityClass()); 129 v.setRange(cr.getValidRange()); 130 v.setIsRequired(cr.required); 131 v.setMustBeUnique(cr.unique); 132 v.setExcludeId(intId); 133 134 v.validate((String ) cr.getValue(), ceb); 136 137 142 } 143 break; 144 } 145 case Constants.STRING: 146 { 147 if (cr.getValue() != null) 148 { 149 StringValidator v = new StringValidator(cr.getFieldName()); 150 v.setObjectClass(vo.getConstraintRuleList().getEntityClass()); 151 v.setRange(cr.getValidRange()); 152 v.setIsRequired(cr.required); 153 v.setMustBeUnique(cr.unique); 154 v.setExcludeId(intId); 155 156 v.validate((String ) cr.getValue(), ceb); 157 } 158 break; 159 } 160 case Constants.FLOAT: 161 { 162 break; 163 } 164 case Constants.INTEGER: 165 { 166 break; 167 } 168 case Constants.PROPERNOUN: 169 { 170 break; 171 } 172 173 } 175 } 177 return ceb; 178 } 179 180 181 } 182 | Popular Tags |