public boolean supports(Class clazz) {
return Pet.class.isAssignableFrom(clazz);
}
public void validate(Object obj, Errors errors) {
Pet pet = (Pet) obj;
String name = pet.getName();
if (!StringUtils.hasLength(name)) {
errors.rejectValue("name", "required", "required");
}
else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
errors.rejectValue("name", "duplicate", "already exists");
}
}