@Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;

    // Gets all of the Validator beans from the application Context.
    Map<String, Validator> beanValidators = applicationContext.getBeansOfType(Validator.class);
    String[] mnbDaoBeans = applicationContext.getBeanNamesForType(BaseDao.class);

    for (int i = 0; i < mnbDaoBeans.length; i++) {

      // Gets the Class type that the Dao handles
      BaseDao type = (BaseDao) applicationContext.getBean(mnbDaoBeans[i]);

      Iterator<String> itr = beanValidators.keySet().iterator();
      List<Validator> validators = new ArrayList<Validator>();
      while (itr.hasNext()) {
        String key = itr.next();
        Validator validator = beanValidators.get(key);

        if (validator.supports(type.getEntityClass())) {
          validators.add(validator);
        }
      }

      if (validators.size() > 0) {
        this.cachedValidatorsMap.put(type.getEntityClass(), validators);
      }
    }

    logger.info("Validation Framework is bootstrapped and ready to roll");
  }
 /**
  * Applies the custom validator of the given configuration (if one exists) on the given object.
  *
  * @param configuration The configuration from which the custom validator will be taken from.
  * @param obj The object to be validated.
  * @param errors The {@link Errors} instance where all validation errors will be registered.
  */
 protected void applyCustomValidator(
     BeanValidationConfiguration configuration, Object obj, Errors errors) {
   Validator validator = configuration.getCustomValidator();
   if (validator != null) {
     if (validator.supports(obj.getClass())) {
       validator.validate(obj, errors);
     }
   }
 }
 public MemberFormValidator(Validator telephoneFormValidator) {
   if (telephoneFormValidator == null) {
     throw new IllegalArgumentException(
         "The supplied [Validator] is " + "required and must not be null.");
   }
   if (!telephoneFormValidator.supports(TelephoneForm.class)) {
     throw new IllegalArgumentException(
         "The supplied [Validator] must "
             + "support the validation of [TelephoneForm] instances.");
   }
   this.telephoneFormValidator = telephoneFormValidator;
 }
  public Object getValue(ProgressListener subListener) throws Exception {
    Object value = delegate.getValue(subListener);
    Errors errors = new BeanPropertyBindingResult(value, getInputId());
    for (Validator v : validators) {
      if (v.supports(value.getClass())) {
        v.validate(value, errors);
      }
    }

    if (errors.hasErrors()) {
      throw new ValidationException(errors, getInputId());
    }

    return value;
  }
 private Errors validate(String event, Object o) {
   Errors errors = null;
   if (null != o) {
     Class<?> domainType = o.getClass();
     errors =
         new ValidationErrors(
             domainType.getSimpleName(), o, repositoryMetadataFor(domainType).entityMetadata());
     Collection<Validator> validators = this.validators.get(event);
     if (null != validators) {
       for (Validator v : validators) {
         if (v.supports(o.getClass())) {
           LOG.debug(event + ": " + o + " with " + v);
           ValidationUtils.invokeValidator(v, o, errors);
         }
       }
     }
     if (errors.getErrorCount() > 0) {
       throw new RepositoryConstraintViolationException(errors);
     }
   }
   return errors;
 }
  public void validate(Object command) {
    if (logger.isDebugEnabled()) {
      logger.debug("validate(Object) - start");
    }

    Validator[] validators = getValidators();
    if (validators != null) {
      for (int index = 0; index < validators.length; index++) {
        Validator validator = validators[index];
        if (validator instanceof VolunteerValidator) {
          if (((VolunteerValidator) validator).supports(command.getClass())) {
            ValidationUtils.invokeValidator(validators[index], command, errors);
          }
        } else if (validator.supports(command.getClass())) {
          ValidationUtils.invokeValidator(validators[index], command, errors);
        }
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug("validate(Object) - end");
    }
  }
 @Override
 public boolean supports(Class<?> clazz) {
   return validator.supports(clazz);
 }