// Loop through rules and create validators
Iterator iterator = vo.getConstraintRules().iterator();
while (iterator.hasNext())
{
ConstraintRule cr = (ConstraintRule) iterator.next();
String userName = ((SystemUserVO)vo).getUserName();
// an ugly switch for now.
switch (cr.getConstraintType())
{
case Constants.EMAIL:
{
if (cr.getValue() != null)
{
// Create validator
EmailValidator v = new EmailValidator(cr.getFieldName());
// Set properties
v.setObjectClass(vo.getConstraintRuleList().getEntityClass());
v.setRange(cr.getValidRange());
v.setIsRequired(cr.required);
v.setMustBeUnique(cr.unique);
v.setExcludeId(null);
v.setExcludeObject(userName);
// Do the limbo
v.validate((String) cr.getValue(), ceb);
// <todo>
// Note: the actual value validated should be extracted
// from the vo using the fieldname with reflection.
// </todo>
}
break;
}
case Constants.STRING:
{
if (cr.getValue() != null)
{
StringValidator v = new StringValidator(cr.getFieldName());
v.setObjectClass(vo.getConstraintRuleList().getEntityClass());
v.setRange(cr.getValidRange());
v.setIsRequired(cr.required);
v.setMustBeUnique(cr.unique);
v.setExcludeId(null);
v.setExcludeObject(userName);
v.validate((String) cr.getValue(), ceb);
}
break;
}
case Constants.FLOAT:
{