Skip to content

Commit

Permalink
BVAL-310: Extracting method validation methods to separate delegate i…
Browse files Browse the repository at this point in the history
…nterface
  • Loading branch information
gunnarmorling committed Oct 17, 2012
1 parent d0bd272 commit 87b6a8f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 78 deletions.
88 changes: 88 additions & 0 deletions src/main/java/javax/validation/MethodValidator.java
@@ -0,0 +1,88 @@
package javax.validation;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;
import javax.validation.groups.Default;

/**
* Validates parameters and return values of methods respectively constructors.
* Implementations of this interface must be thread-safe.
*
* @author Gunnar Morling
* @since 1.1
*/
public interface MethodValidator {

/**
* Validates all constraints placed on the parameters of the given method.
*
* @param <T> The type hosting the method to validate.
* @param object The object on which the method to validate was invoked.
* @param method The method for which the parameter constraints shall be validated.
* @param parameterValues The values provided by the caller for the given method's
* parameters.
* @param groups The group or list of groups targeted for validation (defaults to
* {@link Default}).
*
* @return A set with the constraint violations caused by this validation.
* Will be empty, if no error occurs, but never {@code null}.
*
* @throws ValidationException if a non recoverable error happens during the
* validation process
*/
<T> Set<ConstraintViolation<T>> validateParameters(T object, Method method, Object[] parameterValues, Class<?>... groups);

/**
* Validates all return value constraints of the given method.
*
* @param <T> The type hosting the method to validate.
* @param object The object on which the method to validate was invoked.
* @param method The method for which the return value constraints shall be validated.
* @param returnValue The value returned by the given method.
* @param groups The group or list of groups targeted for validation (defaults to
* {@link Default}).
*
* @return A set with the constraint violations caused by this validation.
* Will be empty, if no error occurs, but never {@code null}.
*
* @throws ValidationException if a non recoverable error happens during the
* validation process
*/
<T> Set<ConstraintViolation<T>> validateReturnValue(T object, Method method, Object returnValue, Class<?>... groups);

/**
* Validates all constraints placed on the parameters of the given constructor.
*
* @param <T> The type hosting the constructor to validate.
* @param constructor The constructor for which the parameter constraints shall be validated.
* @param parameterValues The values provided by the caller for the given constructor's
* parameters.
* @param groups The group or list of groups targeted for validation (defaults to
* {@link Default}).
*
* @return A set with the constraint violations caused by this validation.
* Will be empty, if no error occurs, but never {@code null}.
*
* @throws ValidationException if a non recoverable error happens during the
* validation process
*/
<T> Set<ConstraintViolation<T>> validateConstructorParameters(Constructor<T> constructor, Object[] parameterValues, Class<?>... groups);

/**
* Validates all return value constraints of the given constructor.
*
* @param <T> The type hosting the constructor to validate.
* @param constructor The constructor for which the return value constraints shall be validated.
* @param createdObject The object instantiated by the given method.
* @param groups The group or list of groups targeted for validation (defaults to
* {@link Default}).
*
* @return A set with the constraint violations caused by this validation.
* Will be empty, if no error occurs, but never {@code null}.
*
* @throws ValidationException if a non recoverable error happens during the
* validation process
*/
<T> Set<ConstraintViolation<T>> validateConstructorReturnValue(Constructor<T> constructor, T createdObject, Class<?>... groups);
}
88 changes: 10 additions & 78 deletions src/main/java/javax/validation/Validator.java
Expand Up @@ -16,8 +16,6 @@
*/
package javax.validation;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;
import javax.validation.metadata.BeanDescriptor;

Expand Down Expand Up @@ -93,82 +91,6 @@ <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType,
Object value,
Class<?>... groups);

/**
* Validates all constraints placed on the parameters of the given method.
*
* @param <T> The type hosting the method to validate.
* @param object The object on which the method to validate was invoked.
* @param method The method for which the parameter constraints shall be validated.
* @param parameterValues The values provided by the caller for the given method's
* parameters.
* @param groups group or list of groups targeted for validation (default to
* {@link javax.validation.groups.Default})
*
* @return 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
* @since 1.1
*/
<T> Set<ConstraintViolation<T>> validateParameters(T object, Method method, Object[] parameterValues, Class<?>... groups);

/**
* Validates all return value constraints of the given method.
*
* @param <T> The type hosting the method to validate.
* @param object The object on which the method to validate was invoked.
* @param method The method for which the return value constraints shall be validated.
* @param returnValue The value returned by the given method.
* @param groups group or list of groups targeted for validation (default to
* {@link javax.validation.groups.Default})
*
* @return 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
* @since 1.1
*/
<T> Set<ConstraintViolation<T>> validateReturnValue(T object, Method method, Object returnValue, Class<?>... groups);

/**
* Validates all constraints placed on the parameters of the given constructor.
*
* @param <T> The type hosting the constructor to validate.
* @param constructor The constructor for which the parameter constraints shall be validated.
* @param parameterValues The values provided by the caller for the given constructor's
* parameters.
* @param groups group or list of groups targeted for validation (default to
* {@link javax.validation.groups.Default})
*
* @return 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
* @since 1.1
*/
<T> Set<ConstraintViolation<T>> validateConstructorParameters(Constructor<T> constructor, Object[] parameterValues, Class<?>... groups);

/**
* Validates all return value constraints of the given constructor.
*
* @param <T> The type hosting the constructor to validate.
* @param constructor The constructor for which the return value constraints shall be validated.
* @param createdObject The object instantiated by the given method.
* @param groups group or list of groups targeted for validation (default to
* {@link javax.validation.groups.Default})
*
* @return 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
* @since 1.1
*/
<T> Set<ConstraintViolation<T>> validateConstructorReturnValue(Constructor<T> constructor, T createdObject, Class<?>... groups);

/**
* Return the descriptor object describing bean constraints.
* The returned object (and associated objects including
Expand Down Expand Up @@ -198,4 +120,14 @@ <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType,
* @throws ValidationException if the provider does not support the call.
*/
public <T> T unwrap(Class<T> type);

/**
* Returns a delegate for validation parameters and return values of methods
* respectively constructors.
*
* @return A delegate for method validation.
*
* @since 1.1
*/
MethodValidator forMethods();
}

0 comments on commit 87b6a8f

Please sign in to comment.