org.apache.bval.jsr303.extensions
Class MethodValidatorImpl

java.lang.Object
  extended by org.apache.bval.jsr303.ClassValidator
      extended by org.apache.bval.jsr303.extensions.MethodValidatorImpl
All Implemented Interfaces:
Validator, CascadingPropertyValidator, MethodValidator

 class MethodValidatorImpl
extends ClassValidator
implements MethodValidator

Description: experimental implementation of method-level-validation


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.bval.jsr303.ClassValidator
ClassValidator.Jsr303ValidationCallback
 
Field Summary
 
Fields inherited from class org.apache.bval.jsr303.ClassValidator
factoryContext, groupsComputer
 
Constructor Summary
MethodValidatorImpl(ApacheFactoryContext factoryContext)
          Create a new MethodValidatorImpl instance.
 
Method Summary
protected  BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean)
          Create a BeanDescriptorImpl
<T> Set<ConstraintViolation<T>>
validateParameter(Class<T> clazz, Constructor<T> constructor, Object parameter, int parameterIndex, Class<?>... groupArray)
          Validate the parameter value based on the constraints described on the parameterIndex-th parameter of constructor.
<T> Set<ConstraintViolation<T>>
validateParameter(Class<T> clazz, Method method, Object parameter, int parameterIndex, Class<?>... groupArray)
          Validate the parameter value based on the constraints described on the parameterIndex-th parameter of method.
<T> Set<ConstraintViolation<T>>
validateParameters(Class<T> clazz, Constructor<T> constructor, Object[] parameters, Class<?>... groupArray)
          Validate each parameter value based on the constraints described on the parameters of constructor.
<T> Set<ConstraintViolation<T>>
validateParameters(Class<T> clazz, Method method, Object[] parameters, Class<?>... groupArray)
          Validate each parameter value based on the constraints described on the parameters of method.
<T> Set<ConstraintViolation<T>>
validateReturnedValue(Class<T> clazz, Method method, Object returnedValue, Class<?>... groupArray)
          Validate each parameter value based on the constraints described on method.
 
Methods inherited from class org.apache.bval.jsr303.ClassValidator
createContext, createValidationContextTraversal, getConstraintsForClass, getMetaBeanFinder, isTreatMapsLikeBeans, setTreatMapsLikeBeans, unrecoverableValidationError, unwrap, validate, validateBeanNet, validateProperty, validateProperty, validateValue, validateValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.validation.Validator
getConstraintsForClass, unwrap, validate, validateProperty, validateValue
 

Constructor Detail

MethodValidatorImpl

public MethodValidatorImpl(ApacheFactoryContext factoryContext)
Create a new MethodValidatorImpl instance.

Parameters:
factoryContext -
Method Detail

createBeanDescriptor

protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean)
Create a BeanDescriptorImpl

Overrides:
createBeanDescriptor in class ClassValidator
Returns:
BeanDescriptorImpl instance

validateParameters

public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz,
                                                          Method method,
                                                          Object[] parameters,
                                                          Class<?>... groupArray)
Validate each parameter value based on the constraints described on the parameters of method. enhancement: method-level-validation not yet completly implemented
 example:
 
 public @NotNull String saveItem(@Valid @NotNull Item item, @Max(23) BigDecimal
 
 
spec: The constraints declarations evaluated are the constraints hosted on the parameters of the method or constructor. If @Valid is placed on a parameter, constraints declared on the object itself are considered.

Specified by:
validateParameters in interface MethodValidator
Parameters:
clazz - class hosting the method
method - the method whose parameters are currectly validated
parameters - the parameter values passed to the method for invocation
groupArray - groups targeted for validation
Returns:
set of constraint violations
Throws:
IllegalArgumentException - enhancement: if the method does not belong to T or if the Object[] does not match the method signature

validateParameter

public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz,
                                                         Method method,
                                                         Object parameter,
                                                         int parameterIndex,
                                                         Class<?>... groupArray)
Validate the parameter value based on the constraints described on the parameterIndex-th parameter of method.

Specified by:
validateParameter in interface MethodValidator
Parameters:
clazz - class hosting the method
method - the method whose parameters are currectly validated
parameter - the parameter value passed to the parameterIndex-t parameter of method
parameterIndex - parameter index of the parameter validated in method
groupArray - groups targeted for validation
Returns:
set of constraint violations

validateParameters

public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz,
                                                          Constructor<T> constructor,
                                                          Object[] parameters,
                                                          Class<?>... groupArray)
Validate each parameter value based on the constraints described on the parameters of constructor.

Specified by:
validateParameters in interface MethodValidator
Parameters:
clazz - class hosting the constructor
constructor - the constructor whose parameters are correctly validated
parameters - the parameter values passed to the constructor for invocation
groupArray - groups targeted for validation
Returns:
set of constraint violations

validateParameter

public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz,
                                                         Constructor<T> constructor,
                                                         Object parameter,
                                                         int parameterIndex,
                                                         Class<?>... groupArray)
Validate the parameter value based on the constraints described on the parameterIndex-th parameter of constructor.

Specified by:
validateParameter in interface MethodValidator
Parameters:
clazz - class hosting the constructor
constructor - the method whose parameters are correctly validated
parameter - the parameter value passed to the parameterIndex-th parameter of constructor
parameterIndex - parameter index of the parameter validated in constructor
groupArray - groups targeted for validation
Returns:
set of constraint violations

validateReturnedValue

public <T> Set<ConstraintViolation<T>> validateReturnedValue(Class<T> clazz,
                                                             Method method,
                                                             Object returnedValue,
                                                             Class<?>... groupArray)
Validate each parameter value based on the constraints described on method. If @Valid is placed on the method, the constraints declared on the object itself are considered.

Specified by:
validateReturnedValue in interface MethodValidator
Parameters:
clazz - class hosting the method
method - the method whose result is validated
returnedValue - the value returned by the method invocation
groupArray - groups targeted for validation
Returns:
set of constraint violations


Copyright © 2010-2014 The Apache Software Foundation. All Rights Reserved.