Package org.springframework.validation

Examples of org.springframework.validation.Validator


    assertEquals("invalidValue", this.resolver.resolveArgument(this.paramValidatedNotAnnotated, message));
  }

  private Validator testValidator() {

    return new Validator() {
      @Override
      public boolean supports(Class<?> clazz) {
        return String.class.isAssignableFrom(clazz);
      }
      @Override
View Full Code Here


  }

  @Test
  public void customValidation() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    instance.setValidator(new Validator() {
      @Override
      public boolean supports(Class<?> clazz) {
        return String.class.isAssignableFrom(clazz);
      }
      @Override
View Full Code Here

    // Search all Validators for those that support the class
    Set<String> candidateValidatorNames = new HashSet<String>();
    Iterator<String> iter = beans.keySet().iterator();
    while (iter.hasNext()) {
      String beanName = iter.next();
      Validator validator = beans.get(beanName);
      if (validator.supports(domainClass)) {
        candidateValidatorNames.add(beanName);
      }
    }
   
    if (candidateValidatorNames.size() == 0) {
View Full Code Here

                // Call bindSupport() if this class wishes
                BindBeforeValidationUtils.bindIfRequired(currentDomainObject);

                Errors errors = new BindException(currentDomainObject,
                        clazz.getName());
                Validator v = findValidator(clazz);

                // Perform validation
                v.validate(currentDomainObject, errors);

                // Handle validation outcome
                if (errors.getErrorCount() == 0) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Validated '" + clazz + "' successfully using '"
              + v.getClass() + "'");
                    }
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Validated '" + clazz + "' using '" + v.getClass()
                            + "' but errors detected");
                    }

                    throw (BindException) errors;
                }
View Full Code Here

    private Validator findValidator(Class clazz)
        throws ValidatorNotFoundException {
        Assert.notNull(clazz, "Class cannot be null");

        Validator validator = this.validationRegistryManager.findValidator(clazz);

        if (validator == null) {
            throw new ValidatorNotFoundException(
                "No Validator found for class '" + clazz + "'");
        }
View Full Code Here

    // Uri components contributor
    CompositeUriComponentsContributor mvcUriComponentsContributor = mvcUriComponentsContributor();
    mvcUriComponentsContributor.setContributors( adapter.getArgumentResolvers() );

    // Set the validator
    Validator validator = getValidator( webMvcConfigurers );
    setValidator( validator );

    // Set the message codes resolver
    MessageCodesResolver resolver = getMessageCodesResolver( webMvcConfigurers );
View Full Code Here

  }

  public Validator getValidator( Collection<WebMvcConfigurer> delegates ) {
    List<Validator> candidates = new ArrayList<Validator>();
    for ( WebMvcConfigurer configurer : delegates ) {
      Validator validator = configurer.getValidator();
      if ( validator != null ) {
        candidates.add( validator );
      }
    }
    return selectSingleInstance( candidates, Validator.class );
View Full Code Here

  public Validator mvcValidator() {
    return validatorDelegate;
  }

  private void setValidator( Validator implementation ) {
    Validator validator = implementation;
    if ( validator == null ) {
      if ( ClassUtils.isPresent( "javax.validation.Validator", getClass().getClassLoader() ) ) {
        Class<?> clazz;
        try {
          String className = "org.springframework.validation.beanvalidation.LocalValidatorFactoryBean";
          clazz = ClassUtils.forName( className, WebMvcConfigurationSupport.class.getClassLoader() );
        }
        catch ( ClassNotFoundException e ) {
          throw new BeanInitializationException( "Could not find default validator", e );
        }
        catch ( LinkageError e ) {
          throw new BeanInitializationException( "Could not find default validator", e );
        }
        validator = (Validator) BeanUtils.instantiate( clazz );
      }
      else {
        validator = new Validator()
        {
          public boolean supports( Class<?> clazz ) {
            return false;
          }
View Full Code Here

    factory.setBeanFactory(new StaticListableBeanFactory());
    factory.afterPropertiesSet();
  }

  private Validator testValidator(final String invalidValue) {
    return new Validator() {
      @Override
      public boolean supports(Class<?> clazz) {
        return String.class.isAssignableFrom(clazz);
      }
View Full Code Here

TOP

Related Classes of org.springframework.validation.Validator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.