javax.validation
Interface Validator


public interface Validator

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

Author:
Emmanuel Bernard, Hardy Ferentschik

Method Summary
 BeanDescriptor getConstraintsForClass(java.lang.Class<?> clazz)
          Return the descriptor object describing bean constraints The returned object (and associated objects including ConstraintDescriptors) are immutable.
<T> java.util.Set<ConstraintViolation<T>>
validate(T object, java.lang.Class<?>... groups)
          Validates all constraints on object.
<T> java.util.Set<ConstraintViolation<T>>
validateProperty(T object, java.lang.String propertyName, java.lang.Class<?>... groups)
          Validates all constraints placed on the property named <code>propertyName</code> of object
<T> java.util.Set<ConstraintViolation<T>>
validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?>... groups)
          Validates all constraints placed on the property named propertyName would the property value be value

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

 

Method Detail

validate

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

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

validateProperty

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

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

validateValue

<T> java.util.Set<ConstraintViolation<T>> validateValue(java.lang.Class<T> beanType,
                                                        java.lang.String propertyName,
                                                        java.lang.Object value,
                                                        java.lang.Class<?>... groups)
Validates all constraints placed on the property named propertyName 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 - groups targeted for validation (default to Default)
Returns:
constraint violations or an empty Set if none
Throws:
java.lang.IllegalArgumentException - if object is null, if propertyName null, empty or not a valid object property
ValidationException - if a non recoverable error happens during the validation process

getConstraintsForClass

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

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


Copyright © 2007-2009. All Rights Reserved.