V
- is the generic type of the value to validate
.public class ValidatorJsr303<V> extends AbstractValidator<V>
ValueValidator
that adapts to
javax.validation
(JSR 303).Modifier and Type | Field and Description |
---|---|
private Class<?>[] |
groups |
private boolean |
mandatory |
private Class<?> |
pojoType |
private String |
property |
private Class<?> |
propertyType |
private javax.validation.Validator |
validator |
PROPERTY_MANDATORY, PROPERTY_MAXIMUM, PROPERTY_MINIMUM
Constructor and Description |
---|
ValidatorJsr303(javax.validation.Validator validator,
Class<?> pojoType,
String property)
The constructor.
|
ValidatorJsr303(javax.validation.Validator validator,
Class<?> pojoType,
String property,
Class<?> propertyType)
The constructor.
|
ValidatorJsr303(javax.validation.Validator validator,
Class<?> pojoType,
String property,
Class<?> propertyType,
Class<?>... groups)
The constructor.
|
ValidatorJsr303(javax.validation.Validator validator,
Class<V> pojoType)
The constructor.
|
ValidatorJsr303(javax.validation.Validator validator,
Class<V> pojoType,
Class<?>... groups)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
calculateMandatoryFlag() |
protected ValidationFailure |
createValidationFailure(javax.validation.ConstraintViolation<?> violation,
Object valueSource)
Creates a
ValidationFailure for the given ConstraintViolation . |
boolean |
equals(Object obj) |
protected String |
getCode()
This is the default implementation to retrieve the
code of this
ValueValidator . |
Class<?> |
getPojoType() |
String |
getProperty() |
<P> P |
getProperty(TypedProperty<P> typedProperty)
Gets the value of a property.
|
Class<?> |
getPropertyType() |
int |
hashCode() |
ValidationFailure |
validate(V value,
Object valueSource)
This method validates the given
value . |
private Set<javax.validation.ConstraintViolation<?>> |
validateJsr303(V value)
Validates the given
value . |
append, contains, createBundle, isDynamic, isMandatory, validate
private final javax.validation.Validator validator
validate(Object, Object)
private final Class<?> pojoType
validate(Object, Object)
private final String property
validate(Object, Object)
private final Class<?> propertyType
validate(Object, Object)
private final Class<?>[] groups
validate(Object, Object)
private final boolean mandatory
public ValidatorJsr303(javax.validation.Validator validator, Class<V> pojoType)
validator
- is the Validator
instance.pojoType
- is the type of the Pojo
to validate.public ValidatorJsr303(javax.validation.Validator validator, Class<V> pojoType, Class<?>... groups)
validator
- is the Validator
instance.pojoType
- is the type of the Pojo
to validate.groups
- are the groups to use for validation
.public ValidatorJsr303(javax.validation.Validator validator, Class<?> pojoType, String property)
validator
- is the Validator
instance.pojoType
- is the type of the Pojo
to validate.property
- is the property to validate or null
to validate the entire object.public ValidatorJsr303(javax.validation.Validator validator, Class<?> pojoType, String property, Class<?> propertyType)
validator
- is the Validator
instance.pojoType
- is the type of the Pojo
to validate.property
- is the property to validate or null
to validate the entire object.propertyType
- is the property type
.public ValidatorJsr303(javax.validation.Validator validator, Class<?> pojoType, String property, Class<?> propertyType, Class<?>... groups)
validator
- is the Validator
instance.pojoType
- is the type of the Pojo
to validate.property
- is the property to validate or null
to validate the entire object.propertyType
- is the property type
.groups
- are the groups to use for validation
.public <P> P getProperty(TypedProperty<P> typedProperty)
AbstractValidator
getProperty
in class AbstractValidator<V>
P
- the generic type of the requested property.typedProperty
- the TypedProperty
.null
if undefined.private boolean calculateMandatoryFlag()
AbstractValidator.isMandatory()
.public ValidationFailure validate(V value, Object valueSource)
ValueValidator
value
.value
- is the value to validate.valueSource
- is the source
describing the origin of the given
value
. This may be the filename where the value was read from, an XPath where the value was located
in an XML document, the label of a widget of the UI containing the value, etc. This will help to find the
problem easier. The source needs to have a reasonable string-representation
as
this may be displayed to the end-user to locate the source of the failure. In most cases it is suitable to
directly pass a String
.ValidationFailure
or null
if the given value
is valid according to this
ValueValidator
.private Set<javax.validation.ConstraintViolation<?>> validateJsr303(V value)
value
.value
- is the value to validate.Set
of ConstraintViolation
s. Will be empty if the given value
is valid.protected ValidationFailure createValidationFailure(javax.validation.ConstraintViolation<?> violation, Object valueSource)
ValidationFailure
for the given ConstraintViolation
.violation
- is the ConstraintViolation
.valueSource
- is the source of the value. May be null
.ValidationFailure
.protected String getCode()
AbstractValidator
code
of this
ValueValidator
. classname
of the actual
ValueValidator
implementation. This strategy is chosen for simplicity when implementing a new validator. To
ensure stable codes override this method and return a string constant. This shall at least be done when the name of
the class is changed.getCode
in class AbstractValidator<V>
code
.public String getProperty()
null
to validate the entire POJO
.public Class<?> getPropertyType()
Class
reflecting the type of the property
to validate or null
if
undefined. May be used for additional support currently missing in JSR 303 such as primitive types that are
implicitly mandatory but implementations of JSR 303 cause NullPointerException
or similar effects
on property validation.public int hashCode()
hashCode
in class AbstractValidator<V>
public boolean equals(Object obj)
equals
in class AbstractValidator<V>
Copyright © 2001–2016 mmm-Team. All rights reserved.