|
Spring Framework | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.validation.beanvalidation.SpringValidatorAdapter
public class SpringValidatorAdapter
Adapter that takes a JSR-303 javax.validator.Validator
and exposes it as a Spring Validator
while also exposing the original JSR-303 Validator interface itself.
Can be used as a programmatic wrapper. Also serves as base class for
CustomValidatorBean
and LocalValidatorFactoryBean
.
Constructor Summary | |
---|---|
SpringValidatorAdapter(javax.validation.Validator targetValidator)
Create a new SpringValidatorAdapter for the given JSR-303 Validator. |
Method Summary | ||
---|---|---|
protected java.lang.Object[] |
getArgumentsForConstraint(java.lang.String objectName,
java.lang.String field,
javax.validation.metadata.ConstraintDescriptor<?> descriptor)
Return FieldError arguments for a validation error on the given field. |
|
javax.validation.metadata.BeanDescriptor |
getConstraintsForClass(java.lang.Class<?> clazz)
|
|
protected void |
processConstraintViolations(java.util.Set<javax.validation.ConstraintViolation<java.lang.Object>> violations,
Errors errors)
Process the given JSR-303 ConstraintViolations, adding corresponding errors to the provided Spring Errors object. |
|
boolean |
supports(java.lang.Class<?> clazz)
Can this Validator validate
instances of the supplied clazz ? |
|
|
unwrap(java.lang.Class<T> type)
|
|
void |
validate(java.lang.Object target,
Errors errors)
Validate the supplied target object, which must be
of a Class for which the Validator.supports(Class) method
typically has (or would) return true . |
|
void |
validate(java.lang.Object target,
Errors errors,
java.lang.Object... validationHints)
Validate the supplied target object, which must be of a type of Class
for which the Validator.supports(Class) method typically returns true . |
|
|
validate(T object,
java.lang.Class<?>... groups)
|
|
|
validateProperty(T object,
java.lang.String propertyName,
java.lang.Class<?>... groups)
|
|
|
validateValue(java.lang.Class<T> beanType,
java.lang.String propertyName,
java.lang.Object value,
java.lang.Class<?>... groups)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SpringValidatorAdapter(javax.validation.Validator targetValidator)
targetValidator
- the JSR-303 Validator to wrapMethod Detail |
---|
public boolean supports(java.lang.Class<?> clazz)
Validator
Validator
validate
instances of the supplied clazz
?
This method is typically implemented like so:
return Foo.class.isAssignableFrom(clazz);(Where
Foo
is the class (or superclass) of the actual
object instance that is to be validated
.)
clazz
- the Class
that this Validator
is
being asked if it can validate
true
if this Validator
can indeed
validate
instances of the
supplied clazz
public void validate(java.lang.Object target, Errors errors)
Validator
target
object, which must be
of a Class
for which the Validator.supports(Class)
method
typically has (or would) return true
.
The supplied errors
instance can be used to report
any resulting validation errors.
target
- the object that is to be validated (can be null
)errors
- contextual state about the validation process (never null
)ValidationUtils
public void validate(java.lang.Object target, Errors errors, java.lang.Object... validationHints)
SmartValidator
target
object, which must be of a type of Class
for which the Validator.supports(Class)
method typically returns true
.
The supplied errors
instance can be used to report any
resulting validation errors.
This variant of validate()
supports validation hints, such as
validation groups against a JSR-303 provider (in which case, the provided hint
objects need to be annotation arguments of type Class
).
Note: Validation hints may get ignored by the actual target Validator
,
in which case this method should behave just like its regular
Validator.validate(Object, Errors)
sibling.
validate
in interface SmartValidator
target
- the object that is to be validated (can be null
)errors
- contextual state about the validation process (never null
)validationHints
- one or more hint objects to be passed to the validation engineValidationUtils
protected void processConstraintViolations(java.util.Set<javax.validation.ConstraintViolation<java.lang.Object>> violations, Errors errors)
Errors
object.
violations
- the JSR-303 ConstraintViolation resultserrors
- the Spring errors object to register toprotected java.lang.Object[] getArgumentsForConstraint(java.lang.String objectName, java.lang.String field, javax.validation.metadata.ConstraintDescriptor<?> descriptor)
The default implementation returns a first argument indicating the field name (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes). Afterwards, it adds all actual constraint annotation attributes (i.e. excluding "message", "groups" and "payload") in alphabetical order of their attribute names.
Can be overridden to e.g. add further attributes from the constraint descriptor.
objectName
- the name of the target objectfield
- the field that caused the binding errordescriptor
- the JSR-303 constraint descriptor
DefaultMessageSourceResolvable.getArguments()
,
DefaultMessageSourceResolvable
,
DefaultBindingErrorProcessor.getArgumentsForBindError(java.lang.String, java.lang.String)
public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validate(T object, java.lang.Class<?>... groups)
validate
in interface javax.validation.Validator
public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateProperty(T object, java.lang.String propertyName, java.lang.Class<?>... groups)
validateProperty
in interface javax.validation.Validator
public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?>... groups)
validateValue
in interface javax.validation.Validator
public javax.validation.metadata.BeanDescriptor getConstraintsForClass(java.lang.Class<?> clazz)
getConstraintsForClass
in interface javax.validation.Validator
public <T> T unwrap(java.lang.Class<T> type)
unwrap
in interface javax.validation.Validator
|
Spring Framework | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |