javax.validation
Interface Validator


public interface Validator

Validates bean instances. Implementations of this interface must be thread-safe.

Author:
Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling

Method Summary
 BeanDescriptor getConstraintsForClass(Class<?> clazz)
          Return the descriptor object describing bean constraints.
<T> T
unwrap(Class<T> type)
          Return an instance of the specified type allowing access to provider-specific APIs.
<T> Set<ConstraintViolation<T>>
validate(T object, Class<?>... groups)
          Validates all constraints on object.
<T> Set<ConstraintViolation<T>>
validateConstructorParameters(Constructor<T> constructor, Object[] parameterValues, Class<?>... groups)
          Validates all constraints placed on the parameters of the given constructor.
<T> Set<ConstraintViolation<T>>
validateConstructorReturnValue(Constructor<T> constructor, T createdObject, Class<?>... groups)
          Validates all return value constraints of the given constructor.
<T> Set<ConstraintViolation<T>>
validateParameters(T object, Method method, Object[] parameterValues, Class<?>... groups)
          Validates all constraints placed on the parameters of the given method.
<T> Set<ConstraintViolation<T>>
validateProperty(T object, String propertyName, Class<?>... groups)
          Validates all constraints placed on the property of object named propertyName.
<T> Set<ConstraintViolation<T>>
validateReturnValue(T object, Method method, Object returnValue, Class<?>... groups)
          Validates all return value constraints of the given method.
<T> Set<ConstraintViolation<T>>
validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
          Validates all constraints placed on the property named propertyName of the class beanType would the property value be value

ConstraintViolation objects return null for ConstraintViolation.getRootBean() and ConstraintViolation.getLeafBean()

 

Method Detail

validate

<T> Set<ConstraintViolation<T>> validate(T object,
                                         Class<?>... groups)
Validates all constraints on object.

Parameters:
object - object to validate
groups - group or list of groups targeted for validation (default to Default)
Returns:
constraint violations or an empty Set if none
Throws:
IllegalArgumentException - if object is null or if null is passed to the varargs groups
ValidationException - if a non recoverable error happens during the validation process

validateProperty

<T> Set<ConstraintViolation<T>> validateProperty(T object,
                                                 String propertyName,
                                                 Class<?>... groups)
Validates all constraints placed on the property of object named propertyName.

Parameters:
object - object to validate
propertyName - property to validate (ie field and getter constraints)
groups - group or list of groups targeted for validation (default to Default)
Returns:
constraint violations or an empty Set if none
Throws:
IllegalArgumentException - if object is null, if propertyName null, empty or not a valid object property or if null is passed to the varargs groups
ValidationException - if a non recoverable error happens during the validation process

validateValue

<T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType,
                                              String propertyName,
                                              Object value,
                                              Class<?>... groups)
Validates all constraints placed on the property named propertyName of the class beanType would the property value be value

ConstraintViolation objects return null for ConstraintViolation.getRootBean() and ConstraintViolation.getLeafBean()

Parameters:
beanType - the bean type
propertyName - property to validate
value - property value to validate
groups - group or list of groups targeted for validation (default to Default)
Returns:
constraint violations or an empty Set if none
Throws:
IllegalArgumentException - if beanType is null, if propertyName null, empty or not a valid object property or if null is passed to the varargs groups
ValidationException - if a non recoverable error happens during the validation process

validateParameters

<T> Set<ConstraintViolation<T>> validateParameters(T object,
                                                   Method method,
                                                   Object[] parameterValues,
                                                   Class<?>... groups)
Validates all constraints placed on the parameters of the given method.

Type Parameters:
T - The type hosting the method to validate.
Parameters:
object - The object on which the method to validate was invoked.
method - The method for which the parameter constraints shall be validated.
parameterValues - The values provided by the caller for the given method's parameters.
groups - group or list of groups targeted for validation (default to Default)
Returns:
A set with the constraint violations caused by this validation. Will be empty, if no error occurs, but never null.
Throws:
ValidationException - if a non recoverable error happens during the validation process

validateReturnValue

<T> Set<ConstraintViolation<T>> validateReturnValue(T object,
                                                    Method method,
                                                    Object returnValue,
                                                    Class<?>... groups)
Validates all return value constraints of the given method.

Type Parameters:
T - The type hosting the method to validate.
Parameters:
object - The object on which the method to validate was invoked.
method - The method for which the return value constraints shall be validated.
returnValue - The value returned by the given method.
groups - group or list of groups targeted for validation (default to Default)
Returns:
A set with the constraint violations caused by this validation. Will be empty, if no error occurs, but never null.
Throws:
ValidationException - if a non recoverable error happens during the validation process

validateConstructorParameters

<T> Set<ConstraintViolation<T>> validateConstructorParameters(Constructor<T> constructor,
                                                              Object[] parameterValues,
                                                              Class<?>... groups)
Validates all constraints placed on the parameters of the given constructor.

Type Parameters:
T - The type hosting the constructor to validate.
Parameters:
constructor - The constructor for which the parameter constraints shall be validated.
parameterValues - The values provided by the caller for the given constructor's parameters.
groups - group or list of groups targeted for validation (default to Default)
Returns:
A set with the constraint violations caused by this validation. Will be empty, if no error occurs, but never null.
Throws:
ValidationException - if a non recoverable error happens during the validation process

validateConstructorReturnValue

<T> Set<ConstraintViolation<T>> validateConstructorReturnValue(Constructor<T> constructor,
                                                               T createdObject,
                                                               Class<?>... groups)
Validates all return value constraints of the given constructor.

Type Parameters:
T - The type hosting the constructor to validate.
Parameters:
constructor - The constructor for which the return value constraints shall be validated.
createdObject - The object instantiated by the given method.
groups - group or list of groups targeted for validation (default to Default)
Returns:
A set with the constraint violations caused by this validation. Will be empty, if no error occurs, but never null.
Throws:
ValidationException - if a non recoverable error happens during the validation process

getConstraintsForClass

BeanDescriptor getConstraintsForClass(Class<?> clazz)
Return the descriptor object describing bean constraints. The returned object (and associated objects including ConstraintDescriptors) are immutable.

Parameters:
clazz - class or interface type evaluated
Returns:
the bean descriptor for the specified class.
Throws:
IllegalArgumentException - if clazz is null
ValidationException - if a non recoverable error happens during the metadata discovery or if some constraints are invalid.

unwrap

<T> T unwrap(Class<T> type)
Return an instance of the specified type allowing access to provider-specific APIs. If the Bean Validation provider implementation does not support the specified class, ValidationException is thrown.

Parameters:
type - the class of the object to be returned.
Returns:
an instance of the specified class
Throws:
ValidationException - if the provider does not support the call.


Copyright © 2007-2012. All Rights Reserved.