|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.bval.jsr303.ClassValidator
public class ClassValidator
Objects of this class are able to validate bean instances (and the associated object graphs).
Implementation is thread-safe. API class
| Nested Class Summary | |
|---|---|
protected class |
ClassValidator.Jsr303ValidationCallback
Dispatches a call from ClassValidator.Jsr303ValidationCallback.validate() to validateBeanNet(GroupValidationContext) with
the current context set. |
| Field Summary | |
|---|---|
protected ApacheFactoryContext |
factoryContext
ApacheFactoryContext used |
protected GroupsComputer |
groupsComputer
GroupsComputer used |
| Constructor Summary | |
|---|---|
ClassValidator(ApacheFactoryContext factoryContext)
Create a new ClassValidator instance. |
|
ClassValidator(ApacheValidatorFactory factory)
Deprecated. provided for backward compatibility |
|
| Method Summary | ||
|---|---|---|
protected BeanDescriptorImpl |
createBeanDescriptor(MetaBean metaBean)
Create a BeanDescriptorImpl |
|
protected
|
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. |
|
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 |
|
|
unwrap(Class<T> type)
Return an instance of the specified type allowing access to provider-specific APIs. |
|
|
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. |
|
|
validateProperty(T object,
String propertyName,
boolean cascade,
Class<?>... groups)
Validates all constraints placed on object's
propertyName property, with optional validation cascading. |
|
|
validateProperty(T object,
String propertyName,
Class<?>... groups)
Validates all constraints placed on the property of object named
propertyName. |
|
|
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. |
|
|
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() |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final ApacheFactoryContext factoryContext
ApacheFactoryContext used
protected final GroupsComputer groupsComputer
GroupsComputer used
| Constructor Detail |
|---|
public ClassValidator(ApacheFactoryContext factoryContext)
factoryContext - public ClassValidator(ApacheValidatorFactory factory)
factory - | Method Detail |
|---|
protected MetaBeanFinder getMetaBeanFinder()
MetaBeanManagerFactory.getFinder()
public <T> Set<ConstraintViolation<T>> validate(T object,
Class<?>... groups)
object.
validate in interface Validatorobject - 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 groups
ValidationException - if a non recoverable error happens during the validation
process
public <T> Set<ConstraintViolation<T>> validateProperty(T object,
String propertyName,
Class<?>... groups)
object named
propertyName.
validateProperty in interface Validatorobject - 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 groups
ValidationException - if a non recoverable error happens during the validation
process
public <T> Set<ConstraintViolation<T>> validateProperty(T object,
String propertyName,
boolean cascade,
Class<?>... groups)
object's
propertyName property, with optional validation cascading.
validateProperty in interface CascadingPropertyValidatorSet of ConstraintViolations.
public <T> Set<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 ValidatorbeanType - 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 groups
ValidationException - if a non recoverable error happens during the validation
process
public <T> Set<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 CascadingPropertyValidatorSet of ConstraintViolations.public BeanDescriptor getConstraintsForClass(Class<?> clazz)
ConstraintDescriptors) are immutable.
- Specified by:
getConstraintsForClass in interface Validator
- Parameters:
clazz - class or interface type evaluated
- Returns:
- the bean descriptor for the specified class.
- Throws:
IllegalArgumentException - if clazz is null
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 Validatortype - the class of the object to be returned.
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 type
protected <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
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||