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
 ExecutableValidator forExecutables()
          Returns a delegate for validating parameters and return values of methods respectively constructors.
 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>>
validateProperty(T object, String propertyName, Class<?>... groups)
          Validates all constraints placed on the property of object named propertyName.
<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.
 

Method Detail

validate

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

Parameters:
object - object to validate
groups - The group or list of groups targeted for validation (defaults 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 (i.e. field and getter constraints)
groups - The group or list of groups targeted for validation (defaults to Default).
Returns:
constraint violations or an empty set if none
Throws:
IllegalArgumentException - if object is null, if propertyName is 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 - The group or list of groups targeted for validation (defaults to Default).
Returns:
constraint violations or an empty set if none
Throws:
IllegalArgumentException - if beanType is null, if propertyName is 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

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.

forExecutables

ExecutableValidator forExecutables()
Returns a delegate for validating parameters and return values of methods respectively constructors.

Returns:
A delegate for method and constructor validation.
Since:
1.1


Copyright © 2007-2013. All Rights Reserved.