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

项目:spring4-understanding    文件:PayloadArgumentResolver.java   
/**
 * Validate the payload if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param message the currently processed message
 * @param parameter the method parameter
 * @param target the target payload object
 * @throws MethodArgumentNotValidException in case of binding errors
 */
protected void validate(Message<?> message, MethodParameter parameter, Object target) {
    if (this.validator == null) {
        return;
    }
    for (Annotation ann : parameter.getParameterAnnotations()) {
        Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
        if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
            Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
            Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
            BeanPropertyBindingResult bindingResult =
                    new BeanPropertyBindingResult(target, getParameterName(parameter));
            if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator) {
                ((SmartValidator) this.validator).validate(target, bindingResult, validationHints);
            }
            else {
                this.validator.validate(target, bindingResult);
            }
            if (bindingResult.hasErrors()) {
                throw new MethodArgumentNotValidException(message, parameter, bindingResult);
            }
            break;
        }
    }
}
项目:wampspring    文件:PayloadArgumentResolver.java   
protected void validate(Message<?> message, MethodParameter parameter,
        Object target) {
    if (this.validator == null) {
        return;
    }
    for (Annotation ann : parameter.getParameterAnnotations()) {
        Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
        if (validatedAnn != null
                || ann.annotationType().getSimpleName().startsWith("Valid")) {
            Object hints = validatedAnn != null ? validatedAnn.value()
                    : AnnotationUtils.getValue(ann);
            Object[] validationHints = hints instanceof Object[] ? (Object[]) hints
                    : new Object[] { hints };
            BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(
                    target, getParameterName(parameter));
            if (!ObjectUtils.isEmpty(validationHints)
                    && this.validator instanceof SmartValidator) {
                ((SmartValidator) this.validator).validate(target, bindingResult,
                        validationHints);
            }
            else {
                this.validator.validate(target, bindingResult);
            }
            if (bindingResult.hasErrors()) {
                throw new MethodArgumentNotValidException(message, parameter,
                        bindingResult);
            }
            break;
        }
    }
}
项目:kansalaisaloite    文件:InitiativeServiceImpl.java   
public InitiativeServiceImpl(InitiativeDao initiativeDao, ReviewHistoryDao reviewHistoryDao, UserService userService,
                             EmailService emailService, EncryptionService encryptionService, 
                             SmartValidator validator,
                             InitiativeSettings initiativeSettings,
                             HashCreator hashCreator) {
    this.initiativeDao = initiativeDao;
    this.reviewHistoryDao = reviewHistoryDao;
    this.userService = userService;
    this.emailService = emailService;
    this.encryptionService = encryptionService;
    this.validator = validator;
    this.initiativeSettings = initiativeSettings;
    this.hashCreator = hashCreator;
}
项目:springfield    文件:AbstractEntityValidator.java   
public SmartValidator getSmartValidator() {
    return smartValidator;
}
项目:springfield    文件:EntityValidatorImpl.java   
protected EntityValidatorImpl(SmartValidator smartValidator){
    this.smartValidator = smartValidator;
}