public class ClassValidator extends Object implements CascadingPropertyValidator
Modifier and Type | Class and Description |
---|---|
protected class |
ClassValidator.Jsr303ValidationCallback
Dispatches a call from
ClassValidator.Jsr303ValidationCallback.validate() to validateBeanNet(GroupValidationContext) with
the current context set. |
Modifier and Type | Field and Description |
---|---|
protected ApacheFactoryContext |
factoryContext
ApacheFactoryContext used |
protected GroupsComputer |
groupsComputer
GroupsComputer used |
Constructor and Description |
---|
ClassValidator(ApacheFactoryContext factoryContext)
Create a new ClassValidator instance.
|
ClassValidator(ApacheValidatorFactory factory)
Deprecated.
provided for backward compatibility
|
Modifier and Type | Method and Description |
---|---|
protected BeanDescriptorImpl |
createBeanDescriptor(MetaBean metaBean)
Create a
BeanDescriptorImpl |
protected <T> GroupValidationContext<T> |
createContext(MetaBean metaBean,
T object,
Class<T> objectClass,
Class<?>... groups)
Create a
GroupValidationContext . |
protected ValidationContextTraversal |
createValidationContextTraversal(GroupValidationContext<?> validationContext)
Create a
ValidationContextTraversal instance for this ClassValidator . |
javax.validation.metadata.BeanDescriptor |
getConstraintsForClass(Class<?> clazz)
Return the descriptor object describing bean constraints.
|
protected MetaBeanFinder |
getMetaBeanFinder()
Get the metabean finder associated with this validator.
|
boolean |
isTreatMapsLikeBeans()
Behavior configuration -
|
void |
setTreatMapsLikeBeans(boolean treatMapsLikeBeans)
Set whether maps are to be treated like beans.
|
protected static RuntimeException |
unrecoverableValidationError(RuntimeException ex,
Object object)
Generate an unrecoverable validation error
|
<T> T |
unwrap(Class<T> type)
Return an instance of the specified type allowing access to provider-specific APIs.
|
<T> Set<javax.validation.ConstraintViolation<T>> |
validate(T object,
Class<?>... groups)
Validates all constraints on
object . |
protected void |
validateBeanNet(GroupValidationContext<?> context)
Validates a bean and all its cascaded related beans for the currently defined group.
|
<T> Set<javax.validation.ConstraintViolation<T>> |
validateProperty(T object,
String propertyName,
boolean cascade,
Class<?>... groups)
Validates all constraints placed on
object 's
propertyName property, with optional validation cascading. |
<T> Set<javax.validation.ConstraintViolation<T>> |
validateProperty(T object,
String propertyName,
Class<?>... groups)
Validates all constraints placed on the property of
object named
propertyName . |
<T> Set<javax.validation.ConstraintViolation<T>> |
validateValue(Class<T> beanType,
String propertyName,
Object value,
boolean cascade,
Class<?>... groups)
Validates all constraints placed on
object 's
propertyName property, with optional validation cascading,
given a hypothetical property value . |
<T> Set<javax.validation.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() |
protected final ApacheFactoryContext factoryContext
ApacheFactoryContext
usedprotected final GroupsComputer groupsComputer
GroupsComputer
usedpublic ClassValidator(ApacheFactoryContext factoryContext)
factoryContext
- public ClassValidator(ApacheValidatorFactory factory)
factory
- protected MetaBeanFinder getMetaBeanFinder()
MetaBeanManagerFactory.getFinder()
public <T> Set<javax.validation.ConstraintViolation<T>> validate(T object, Class<?>... groups)
object
.validate
in interface javax.validation.Validator
object
- object to validategroups
- group or list of groups targeted for validation (default to
Default
)IllegalArgumentException
- if object is null or if null is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation
processpublic <T> Set<javax.validation.ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups)
object
named
propertyName
.validateProperty
in interface javax.validation.Validator
object
- object to validatepropertyName
- property to validate (ie field and getter constraints). Nested
properties may be referenced (e.g. prop[2].subpropA.subpropB)groups
- group or list of groups targeted for validation (default to
Default
)IllegalArgumentException
- if object
is null, if propertyName
null, empty or not a valid object property or if null is
passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation
processpublic <T> Set<javax.validation.ConstraintViolation<T>> validateProperty(T object, String propertyName, boolean cascade, Class<?>... groups)
object
's
propertyName
property, with optional validation cascading.validateProperty
in interface CascadingPropertyValidator
Set
of ConstraintViolation
s.public <T> Set<javax.validation.ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
propertyName
of the class
beanType
would the property value be value
ConstraintViolation
objects return null for ConstraintViolation.getRootBean()
and
ConstraintViolation.getLeafBean()
validateValue
in interface javax.validation.Validator
beanType
- the bean typepropertyName
- property to validatevalue
- property value to validategroups
- group or list of groups targeted for validation (default to
Default
)IllegalArgumentException
- if beanType
is null, if
propertyName
null, empty or not a valid object
property or if null is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation
processpublic <T> Set<javax.validation.ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, boolean cascade, Class<?>... groups)
object
's
propertyName
property, with optional validation cascading,
given a hypothetical property value
.validateValue
in interface CascadingPropertyValidator
Set
of ConstraintViolation
s.public javax.validation.metadata.BeanDescriptor getConstraintsForClass(Class<?> clazz)
ConstraintDescriptors) are immutable.
getConstraintsForClass
in interface javax.validation.Validator
clazz
- class or interface type evaluatedIllegalArgumentException
- if clazz is nulljavax.validation.ValidationException
- if a non recoverable error happens during the metadata
discovery or if some constraints are invalid.public <T> T unwrap(Class<T> type)
ValidationException
is
thrown.unwrap
in interface javax.validation.Validator
type
- the class of the object to be returned.javax.validation.ValidationException
- if the provider does not support the call.protected void validateBeanNet(GroupValidationContext<?> context)
Default
group.validationContext
- The current context of this validation call. Must have its
GroupValidationContext.getCurrentGroup()
field set.protected static RuntimeException unrecoverableValidationError(RuntimeException ex, Object object)
ex
- object
- RuntimeException
of the appropriate typeprotected <T> GroupValidationContext<T> createContext(MetaBean metaBean, T object, Class<T> objectClass, Class<?>... groups)
GroupValidationContext
.T
- metaBean
- object
- objectClass
- groups
- GroupValidationContext
instanceprotected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean)
BeanDescriptorImpl
metaBean
- BeanDescriptorImpl
instancepublic boolean isTreatMapsLikeBeans()
public void setTreatMapsLikeBeans(boolean treatMapsLikeBeans)
treatMapsLikeBeans
- - true (validate maps like beans, so that
you can use Maps to validate dynamic classes or
beans for which you have the MetaBean but no instances)
- false (default), validate maps like collections
(validating the values only)
protected ValidationContextTraversal createValidationContextTraversal(GroupValidationContext<?> validationContext)
ValidationContextTraversal
instance for this ClassValidator
.validationContext
- ValidationContextTraversal
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.