org.springframework.validation.beanvalidation
Class SpringValidatorAdapter

java.lang.Object
  extended by org.springframework.validation.beanvalidation.SpringValidatorAdapter
All Implemented Interfaces:
javax.validation.Validator
Direct Known Subclasses:
CustomValidatorBean, LocalValidatorFactoryBean

public class SpringValidatorAdapter
extends Object
implements Validator, javax.validation.Validator

Adapter that takes a JSR-303 javax.validator.Validator and exposes it as a Spring Validator while also exposing the original JSR-303 Validator interface itself.

Can be used as a programmatic wrapper. Also serves as base class for CustomValidatorBean and LocalValidatorFactoryBean.

Since:
3.0
Author:
Juergen Hoeller

Constructor Summary
SpringValidatorAdapter(javax.validation.Validator targetValidator)
          Create a new SpringValidatorAdapter for the given JSR-303 Validator.
 
Method Summary
 javax.validation.metadata.BeanDescriptor getConstraintsForClass(Class<?> clazz)
           
 boolean supports(Class<?> clazz)
          Can this Validator validate instances of the supplied clazz?
<T> T
unwrap(Class<T> type)
           
 void validate(Object target, Errors errors)
          Validate the supplied target object, which must be of a Class for which the Validator.supports(Class) method typically has (or would) return true.
<T> Set<javax.validation.ConstraintViolation<T>>
validate(T object, Class<?>... groups)
           
<T> Set<javax.validation.ConstraintViolation<T>>
validateProperty(T object, String propertyName, Class<?>... groups)
           
<T> Set<javax.validation.ConstraintViolation<T>>
validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringValidatorAdapter

public SpringValidatorAdapter(javax.validation.Validator targetValidator)
Create a new SpringValidatorAdapter for the given JSR-303 Validator.

Parameters:
targetValidator - the JSR-303 Validator to wrap
Method Detail

supports

public boolean supports(Class<?> clazz)
Description copied from interface: Validator
Can this Validator validate instances of the supplied clazz?

This method is typically implemented like so:

return Foo.class.isAssignableFrom(clazz);
(Where Foo is the class (or superclass) of the actual object instance that is to be validated.)

Parameters:
clazz - the Class that this Validator is being asked if it can validate
Returns:
true if this Validator can indeed validate instances of the supplied clazz

validate

public void validate(Object target,
                     Errors errors)
Description copied from interface: Validator
Validate the supplied target object, which must be of a Class for which the Validator.supports(Class) method typically has (or would) return true.

The supplied errors instance can be used to report any resulting validation errors.

Parameters:
target - the object that is to be validated (can be null)
errors - contextual state about the validation process (never null)
See Also:
ValidationUtils

validate

public <T> Set<javax.validation.ConstraintViolation<T>> validate(T object,
                                                                 Class<?>... groups)
Specified by:
validate in interface javax.validation.Validator

validateProperty

public <T> Set<javax.validation.ConstraintViolation<T>> validateProperty(T object,
                                                                         String propertyName,
                                                                         Class<?>... groups)
Specified by:
validateProperty in interface javax.validation.Validator

validateValue

public <T> Set<javax.validation.ConstraintViolation<T>> validateValue(Class<T> beanType,
                                                                      String propertyName,
                                                                      Object value,
                                                                      Class<?>... groups)
Specified by:
validateValue in interface javax.validation.Validator

getConstraintsForClass

public javax.validation.metadata.BeanDescriptor getConstraintsForClass(Class<?> clazz)
Specified by:
getConstraintsForClass in interface javax.validation.Validator

unwrap

public <T> T unwrap(Class<T> type)
Specified by:
unwrap in interface javax.validation.Validator