javax.validation.Validator Maven / Gradle / Ivy
// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.validation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;
import javax.validation.metadata.BeanDescriptor;
/**
* Validates bean instances. Implementations of this interface must be thread-safe.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
* @author Gunnar Morling
*/
public interface Validator {
/**
* Validates all constraints on object
.
*
* @param object object to validate
* @param groups group or list of groups targeted for validation
* (default to {@link javax.validation.groups.Default})
*
* @return constraint violations or an empty Set if none
*
* @throws IllegalArgumentException if object is null
* or if null is passed to the varargs groups
* @throws ValidationException if a non recoverable error happens
* during the validation process
*/
Set> validate(T object, Class>... groups);
/**
* Validates all constraints placed on the property of object
* named propertyName
.
*
* @param object object to validate
* @param propertyName property to validate (ie field and getter constraints)
* @param groups group or list of groups targeted for validation
* (default to {@link javax.validation.groups.Default})
*
* @return 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
* @throws ValidationException if a non recoverable error happens
* during the validation process
*/
Set> validateProperty(T object,
String propertyName,
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
* {@link ConstraintViolation#getRootBean()} and {@link ConstraintViolation#getLeafBean()}
*
* @param beanType the bean type
* @param propertyName property to validate
* @param value property value to validate
* @param groups group or list of groups targeted for validation
* (default to {@link javax.validation.groups.Default})
*
* @return 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
* @throws ValidationException if a non recoverable error happens
* during the validation process
*/
Set> validateValue(Class beanType,
String propertyName,
Object value,
Class>... groups);
/**
* Validates all constraints placed on the parameters of the given method.
*
* @param 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
*/
Set> validateParameters(T object, Method method, Object[] parameterValues, Class>... groups);
/**
* Validates all return value constraints of the given method.
*
* @param 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
*/
Set> validateReturnValue(T object, Method method, Object returnValue, Class>... groups);
/**
* Validates all constraints placed on the parameters of the given constructor.
*
* @param 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
*/
Set> validateConstructorParameters(Constructor constructor, Object[] parameterValues, Class>... groups);
/**
* Validates all return value constraints of the given constructor.
*
* @param 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
*/
Set> validateConstructorReturnValue(Constructor constructor, T createdObject, Class>... groups);
/**
* Return the descriptor object describing bean constraints.
* The returned object (and associated objects including
* ConstraintDescriptors) are immutable.
*
* @param clazz class or interface type evaluated
*
* @return the bean descriptor for the specified class.
*
* @throws IllegalArgumentException if clazz is null
* @throws ValidationException if a non recoverable error happens
* during the metadata discovery or if some
* constraints are invalid.
*/
BeanDescriptor getConstraintsForClass(Class> clazz);
/**
* 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.
*
* @param type the class of the object to be returned.
*
* @return an instance of the specified class
*
* @throws ValidationException if the provider does not support the call.
*/
public T unwrap(Class type);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy