Java 类org.springframework.validation.Validator 实例源码

项目:spring4-understanding    文件:DefaultMessageHandlerMethodFactoryTests.java   
@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
        public void validate(Object target, Errors errors) {
            String value = (String) target;
            if ("failure".equals(value)) {
                errors.reject("not a valid value");
            }
        }
    });
    instance.afterPropertiesSet();

    InvocableHandlerMethod invocableHandlerMethod =
            createInvocableHandlerMethod(instance, "payloadValidation", String.class);
    thrown.expect(MethodArgumentNotValidException.class);
    invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build());
}
项目:setra    文件:SendController.java   
@Autowired
public SendController(final MessageSenderService messageService,
                      final @Qualifier("mvcValidator") Validator validator,
                      final SecureTransferConfiguration config) {
    this.messageService = messageService;
    this.validator = validator;
    this.config = config;
}
项目:OperatieBRP    文件:WebConfiguratie.java   
/**
 * Registreer de specifieke validators.
 * @param validators validators
 */
public void setValidators(final Validator[] validators) {
    for (final Validator validator : validators) {
        if (!(validator instanceof GlobalValidator)) {
            this.validators.add(validator);
        }
    }
}
项目:OperatieBRP    文件:WebConfiguratie.java   
@Override
public boolean supports(final Class<?> clazz) {
    for (final Validator validator : validators) {
        if (validator.supports(clazz)) {
            return true;
        }
    }
    return false;
}
项目:OperatieBRP    文件:WebConfiguratie.java   
@Override
public void validate(final Object target, final Errors errors) {
    for (final Validator validator : validators) {
        if (validator.supports(target.getClass())) {
            validator.validate(target, errors);
        }
    }
}
项目:Webstore    文件:ProductValidator.java   
public void validate(Object target, Errors errors) {
    Set<ConstraintViolation<Object>> constraintViolations = beanValidator.validate(target);
    for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
        String propertyPath = constraintViolation.getPropertyPath().toString();
        String message = constraintViolation.getMessage();
        errors.rejectValue(propertyPath, "", message);
    }
    for(Validator validator: springValidators) {
        validator.validate(target, errors);
    }
}
项目:pathological-reports    文件:PathologicalReportsApplication.java   
@Override
public Validator getValidator() {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.setValidationMessageSource(messageSource);

    return validator;
}
项目:spring-boot-seed    文件:WebConfig.java   
@Override
public Validator getValidator() {
    LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
    localValidatorFactoryBean.setProviderClass(org.hibernate.validator.HibernateValidator.class);
    localValidatorFactoryBean.setValidationMessageSource(messageSource());
    return localValidatorFactoryBean;
}
项目:hockey-game    文件:HockeyGameApplication.java   
@Override
public Validator getValidator() {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.setValidationMessageSource(messageSource);

    return validator;
}
项目:oma-riista-web    文件:CommonControllerAdvice.java   
private Validator[] supportedValidatorsFor(Class<?> clazz) {
    final Set<Validator> supportedValidators = new HashSet<>();
    for (Validator validator : validators) {
        if (validator.supports(clazz)) {
            supportedValidators.add(validator);
        }
    }
    return supportedValidators.toArray(new Validator[supportedValidators.size()]);
}
项目:spring4-understanding    文件:MessageBrokerConfigurationTests.java   
@Test
public void simpValidatorCustom() {
    final Validator validator = mock(Validator.class);
    AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
        @Override
        public Validator getValidator() {
            return validator;
        }
    };

    assertSame(validator, config.simpValidator());
}
项目:spring4-understanding    文件:MessageBrokerConfigurationTests.java   
@Test
public void simpValidatorInjected() {
    SimpAnnotationMethodMessageHandler messageHandler =
            this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);

    assertThat(messageHandler.getValidator(), Matchers.notNullValue(Validator.class));
}
项目:spring4-understanding    文件:PayloadArgumentResolverTests.java   
private Validator testValidator() {
    return new Validator() {
        @Override
        public boolean supports(Class<?> clazz) {
            return String.class.isAssignableFrom(clazz);
        }
        @Override
        public void validate(Object target, Errors errors) {
            String value = (String) target;
            if ("invalidValue".equals(value)) {
                errors.reject("invalid value");
            }
        }
    };
}
项目:spring4-understanding    文件:MultiActionController.java   
/**
 * Bind request parameters onto the given command bean
 * @param request request from which parameters will be bound
 * @param command command object, that must be a JavaBean
 * @throws Exception in case of invalid state or arguments
 */
protected void bind(HttpServletRequest request, Object command) throws Exception {
    logger.debug("Binding request parameters onto MultiActionController command");
    ServletRequestDataBinder binder = createBinder(request, command);
    binder.bind(request);
    if (this.validators != null) {
        for (Validator validator : this.validators) {
            if (validator.supports(command.getClass())) {
                ValidationUtils.invokeValidator(validator, command, binder.getBindingResult());
            }
        }
    }
    binder.closeNoCatch();
}
项目:spring4-understanding    文件:WebMvcConfigurerComposite.java   
@Override
public Validator getValidator() {
    List<Validator> candidates = new ArrayList<Validator>();
    for (WebMvcConfigurer configurer : this.delegates) {
        Validator validator = configurer.getValidator();
        if (validator != null) {
            candidates.add(validator);
        }
    }
    return selectSingleInstance(candidates, Validator.class);
}
项目:spring4-understanding    文件:WebMvcConfigurationSupportExtensionTests.java   
@Override
public Validator getValidator() {
    return new Validator() {
        @Override
        public void validate(Object target, Errors errors) {
            errors.reject("invalid");
        }
        @Override
        public boolean supports(Class<?> clazz) {
            return true;
        }
    };
}
项目:spring4-understanding    文件:WebMvcConfigurationSupportTests.java   
@Test
public void requestMappingHandlerAdapter() throws Exception {
    ApplicationContext context = initContext(WebConfig.class);
    RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertEquals(9, converters.size());
    for(HttpMessageConverter<?> converter : converters) {
        if (converter instanceof AbstractJackson2HttpMessageConverter) {
            ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
            assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
            assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
            assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
            if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
                assertEquals(XmlMapper.class, objectMapper.getClass());
            }
        }
    }

    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    assertNotNull(initializer);

    ConversionService conversionService = initializer.getConversionService();
    assertNotNull(conversionService);
    assertTrue(conversionService instanceof FormattingConversionService);

    Validator validator = initializer.getValidator();
    assertNotNull(validator);
    assertTrue(validator instanceof LocalValidatorFactoryBean);

    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    @SuppressWarnings("unchecked")
    List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
    assertEquals(2, bodyAdvice.size());
    assertEquals(JsonViewRequestBodyAdvice.class, bodyAdvice.get(0).getClass());
    assertEquals(JsonViewResponseBodyAdvice.class, bodyAdvice.get(1).getClass());
}
项目:spring4-understanding    文件:MethodJmsListenerEndpointTests.java   
private Validator testValidator(final String invalidValue) {
    return new Validator() {
        @Override
        public boolean supports(Class<?> clazz) {
            return String.class.isAssignableFrom(clazz);
        }
        @Override
        public void validate(Object target, Errors errors) {
            String value = (String) target;
            if (invalidValue.equals(value)) {
                errors.reject("not a valid value");
            }
        }
    };
}
项目:bag-database    文件:WebMvcConfig.java   
@Override
public Validator getValidator() {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.setValidationMessageSource(messageSource());
    return validator;
}
项目:SMSC    文件:SpringDataRestValidationConfiguration.java   
@Override
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
    Validator validator = validator();

    //bean validation always before save and create
    validatingListener.addValidator("beforeCreate", validator);
    validatingListener.addValidator("beforeSave", validator);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigurationPropertiesBindingPostProcessor.java   
private void freeLocalValidator() {
    try {
        Validator validator = this.localValidator;
        this.localValidator = null;
        if (validator != null) {
            ((DisposableBean) validator).destroy();
        }
    }
    catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigurationPropertiesBindingPostProcessor.java   
private Validator determineValidator(Object bean) {
    Validator validator = getValidator();
    boolean supportsBean = (validator != null && validator.supports(bean.getClass()));
    if (ClassUtils.isAssignable(Validator.class, bean.getClass())) {
        if (supportsBean) {
            return new ChainingValidator(validator, (Validator) bean);
        }
        return (Validator) bean;
    }
    return (supportsBean ? validator : null);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigurationPropertiesBindingPostProcessor.java   
private Validator getValidator() {
    if (this.validator != null) {
        return this.validator;
    }
    if (this.localValidator == null && isJsr303Present()) {
        this.localValidator = new LocalValidatorFactory()
                .run(this.applicationContext);
    }
    return this.localValidator;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigurationPropertiesBindingPostProcessor.java   
@Override
public boolean supports(Class<?> clazz) {
    for (Validator validator : this.validators) {
        if (validator.supports(clazz)) {
            return true;
        }
    }
    return false;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigurationPropertiesBindingPostProcessor.java   
@Override
public void validate(Object target, Errors errors) {
    for (Validator validator : this.validators) {
        if (validator.supports(target.getClass())) {
            validator.validate(target, errors);
        }
    }
}
项目:subs    文件:ListValidationUtils.java   
/**
 * Use a validator on a list of objects, correctly handling changes to the nestedPath
 *
 * @param path
 * @param validator
 * @param list
 * @param errors
 */
public static void invokeValidatorOnList(String path, Validator validator, List<?> list, Errors errors) {

    int i = 0;

    for (Object target : list) {
        try {
            errors.pushNestedPath(path + "[" + i + "]");
            ValidationUtils.invokeValidator(validator, target, errors);
        } finally {
            errors.popNestedPath();
            i++;
        }
    }
}
项目:subs    文件:ValidatorConfig.java   
@Override
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener eventListener) {

    Stream<Validator> stdValidators = Stream.of(
            analysisValidator,
            assayValidator,
            assayDataValidator,
            egaDacValidator,
            egaDacPolicyValidator,
            egaDatasetValidator,
            projectValidator,
            protocolValidator,
            sampleValidator,
            sampleGroupValidator,
            studyValidator,

            submissionValidator

    );

    stdValidators.forEach(validator -> {
        eventListener.addValidator(BEFORE_CREATE, validator);
        eventListener.addValidator(BEFORE_SAVE, validator);
    });

    eventListener.addValidator(BEFORE_SAVE, submissionStatusValidator);

    eventListener.addValidator(BEFORE_DELETE, submissionDeleteValidator);

    eventListener.addValidator(BEFORE_DELETE, submittableDeleteValidator);
}
项目:gvnix1    文件:DataBinderMappingJackson2HttpMessageConverter.java   
/**
 * Default constructor
 * 
 * @param cs
 * @param validator
 */
public DataBinderMappingJackson2HttpMessageConverter(ConversionService cs,
        Validator validator) {
    super();
    this.conversionService = cs;
    this.validator = validator;
}
项目:gvnix1    文件:Jackson2RequestMappingHandlerAdapter.java   
/**
 * Default constructor.
 */
@Autowired
public Jackson2RequestMappingHandlerAdapter(
        ConversionService conversionService, Validator validator) {
    super();
    this.conversionService = conversionService;
    this.validator = validator;
}
项目:gvnix1    文件:ConversionServiceObjectMapper.java   
/**
 * Register custom serialization and deserialization modules.
 * 
 * @param conversionService
 * @param validator
 */
@Autowired
public ConversionServiceObjectMapper(
        final ConversionService conversionService, final Validator validator) {

    // Register a module to add provider for custom bean deserializer
    registerModule(new ConversionServiceModule(conversionService));

    // Register a module to add provider for custom bean serializer
    registerModule(new DataBinderModule());
}
项目:easyrec_major    文件:ConfigurationHelper.java   
private void checkForValidator() {
    PluginConfigurationValidator validatorAnnotation = this.configuration.getClass()
            .getAnnotation(PluginConfigurationValidator.class);
    if (validatorAnnotation != null) {
        Validator validator;
        try {
            validator = validatorAnnotation.validatorClass().getConstructor().newInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException("could not create validator for configuration", e);
        }
        this.dataBinder.setValidator(validator);
        this.validator = validator;
    }
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
@Override
public void afterPropertiesSet() throws Exception {
    if (this.propertySources == null) {
        this.propertySources = deducePropertySources();
    }
    if (this.validator == null) {
        this.validator = getOptionalBean(VALIDATOR_BEAN_NAME, Validator.class);
    }
    if (this.conversionService == null) {
        this.conversionService = getOptionalBean(
                ConfigurableApplicationContext.CONVERSION_SERVICE_BEAN_NAME,
                ConversionService.class);
    }
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
private void freeLocalValidator() {
    try {
        Validator validator = this.localValidator;
        this.localValidator = null;
        if (validator != null) {
            ((DisposableBean) validator).destroy();
        }
    }
    catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
private Validator determineValidator(Object bean) {
    Validator validator = getValidator();
    boolean supportsBean = (validator != null && validator.supports(bean.getClass()));
    if (ClassUtils.isAssignable(Validator.class, bean.getClass())) {
        if (supportsBean) {
            return new ChainingValidator(validator, (Validator) bean);
        }
        return (Validator) bean;
    }
    return (supportsBean ? validator : null);
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
private Validator getValidator() {
    if (this.validator != null) {
        return this.validator;
    }
    if (this.localValidator == null && isJsr303Present()) {
        this.localValidator = new LocalValidatorFactory()
                .run(this.applicationContext);
    }
    return this.localValidator;
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
@Override
public boolean supports(Class<?> clazz) {
    for (Validator validator : this.validators) {
        if (validator.supports(clazz)) {
            return true;
        }
    }
    return false;
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
@Override
public void validate(Object target, Errors errors) {
    for (Validator validator : this.validators) {
        if (validator.supports(target.getClass())) {
            validator.validate(target, errors);
        }
    }
}
项目:lams    文件:ConfigurableWebBindingInitializer.java   
/**
 * Set the Validator to apply after each binding step.
 */
public final void setValidator(Validator validator) {
    this.validator = validator;
}
项目:lams    文件:ConfigurableWebBindingInitializer.java   
/**
 * Return the Validator to apply after each binding step, if any.
 */
public final Validator getValidator() {
    return this.validator;
}
项目:miaohu    文件:WebConfig.java   
@Override
public Validator getValidator() {
    return null;
}