|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springmodules.validation.bean.RuleBasedValidator org.springmodules.validation.bean.BeanValidator
public class BeanValidator
An AbstractTypeSpecificValidator
implementation that applies all validation rules
on a bean of a specific type, based on an appropriate BeanValidationConfiguration
. The validation
configuration is loaded per bean type by the configured BeanValidationConfigurationLoader
.
Constructor Summary | |
---|---|
BeanValidator()
Constructs a new BeanValidator. |
|
BeanValidator(BeanValidationConfigurationLoader configurationLoader)
Constructs a new BeanValidator for the given bean class using the given validation configuration loader. |
Method Summary | |
---|---|
protected void |
applyBeanValidation(BeanValidationConfiguration configuration,
Object obj,
Errors errors)
Applying the validation rules listed in the given validation configuration on the given object, and registering all validation errors with the given Errors object. |
protected void |
applyCustomValidator(BeanValidationConfiguration configuration,
Object obj,
Errors errors)
Applies the custom validator of the given configuration (if one exists) on the given object. |
protected void |
applyGlobalValidationRules(BeanValidationConfiguration configuration,
Object obj,
Errors errors)
Applies the global validation rules as listed in the given validation configuration on the given object, and registering all global validation errors with the given Errors . |
protected void |
applyPropertiesValidationRules(BeanValidationConfiguration configuration,
Object obj,
Errors errors)
Applies the property validation rules as listed in the given validation configuration on the given object, and registering all property validation errors with the given Errors . |
void |
setConfigurationLoader(BeanValidationConfigurationLoader configurationLoader)
Sets the bean validation configuration loader this validator will use to load the bean validation configurations. |
void |
setErrorCodeConverter(ErrorCodeConverter errorCodeConverter)
Sets the error code converter this validator will use to resolve the error codes to be registered with the Errors object. |
void |
setShortCircuitFieldValidation(boolean shortCircuitFieldValidation)
Determines whether field validation will be short-ciruite, that is, if multiple validation rules are defined on a field, the first rule to fail will stop the validation process for that field. |
boolean |
supports(Class clazz)
This validator supports only those classes that are supported by the validation configuration loader it uses. |
void |
validate(Object obj,
Errors errors)
Applies all validation rules as defined in the BeanValidationConfiguration retrieved for the given
bean from the configured BeanValidationConfigurationLoader . |
protected void |
validateAndShortCircuitRules(ValidationRule[] rules,
String propertyName,
Object obj,
Errors errors)
Applying the given validation rules on the given property of the given object. |
protected void |
validateArrayProperty(Object root,
Object array,
String propertyName,
Errors errors,
Set validatedObjects)
Validates the elements of the given array property. |
protected void |
validatedSubBean(Object root,
Object subBean,
String propertyName,
Errors errors,
Set validatedObjects)
Validates the given nested property bean (sub-bean). |
protected void |
validateListOrSetProperty(Object root,
Collection collection,
String propertyName,
Errors errors,
Set validatedObjects)
Validates the elements of the given list or set property. |
protected void |
validateMapProperty(Object root,
Map map,
String propertyName,
Errors errors,
Set validatedObjects)
Validates the elements within the given map property. |
protected void |
validateObjectGraphConstraints(Object root,
Object obj,
Errors errors,
Set validatedObjects)
The heart of this validator. |
protected BeanWrapper |
wrapBean(Object bean)
Wraps the given bean in a BeanWrapper . |
Methods inherited from class org.springmodules.validation.bean.RuleBasedValidator |
---|
addGlobalRule, addGlobalRule, addGlobalRule, addGlobalRule, addGlobalRule, addPropertyGlobalRule, addPropertyRule, addPropertyRule, addPropertyRule, addPropertyRule, setExtraGlobalVadlidationRules, setExtraPropertyValidationRules |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanValidator()
SimpleBeanValidationConfigurationLoader
is
used as the bean validation configuration loader.
public BeanValidator(BeanValidationConfigurationLoader configurationLoader)
configurationLoader
- The BeanValidationConfigurationLoader
that is used to load the bean validation
configuration.Method Detail |
---|
public boolean supports(Class clazz)
supports
in interface Validator
supports
in class RuleBasedValidator
RuleBasedValidator.supports(Class)
,
BeanValidationConfigurationLoader.supports(Class)
public void validate(Object obj, Errors errors)
BeanValidationConfiguration
retrieved for the given
bean from the configured BeanValidationConfigurationLoader
.
validate
in interface Validator
validate
in class RuleBasedValidator
Validator.validate(Object, org.springframework.validation.Errors)
public void setErrorCodeConverter(ErrorCodeConverter errorCodeConverter)
Errors
object.
errorCodeConverter
- The error code converter this validator will use to resolve the error
different error codes.public void setConfigurationLoader(BeanValidationConfigurationLoader configurationLoader)
configurationLoader
- The loader this validator will use to load the bean validation configurations.public void setShortCircuitFieldValidation(boolean shortCircuitFieldValidation)
shortCircuitFieldValidation
- protected void validateObjectGraphConstraints(Object root, Object obj, Errors errors, Set validatedObjects)
BeanValidationConfigurationLoader
. All errors are registered with the given Errors
object under the context of the object graph root.
root
- The root of the object graph.obj
- The object to be validatederrors
- The Errors
instance where the validation errors will be registered.validatedObjects
- keeps track of all the validated objects (to prevent revalidating the same objects when
a circular relationship exists).protected BeanWrapper wrapBean(Object bean)
BeanWrapper
.
bean
- The bean to be wraped.
protected void validateArrayProperty(Object root, Object array, String propertyName, Errors errors, Set validatedObjects)
root
- The root of the object graph that is being validated.array
- The given array.propertyName
- The name of the array property.errors
- The Errors
instance where all validation errors will be registered.validatedObjects
- A registry of all objects that were already validated.protected void validateListOrSetProperty(Object root, Collection collection, String propertyName, Errors errors, Set validatedObjects)
root
- The root of the object graph that is being validated.collection
- The given list or set.propertyName
- The name of the array property.errors
- The Errors
instance where all validation errors will be registered.validatedObjects
- A registry of all objects that were already validated.protected void validateMapProperty(Object root, Map map, String propertyName, Errors errors, Set validatedObjects)
root
- The root of the object graph that is being validated.map
- The given map or set.propertyName
- The name of the array property.errors
- The Errors
instance where all validation errors will be registered.validatedObjects
- A registry of all objects that were already validated.protected void validatedSubBean(Object root, Object subBean, String propertyName, Errors errors, Set validatedObjects)
root
- The root of the object graph that is being validated.subBean
- The given nested property value (the sub-bean).propertyName
- The name of the array property.errors
- The Errors
instance where all validation errors will be registered.validatedObjects
- A registry of all objects that were already validated.protected void applyBeanValidation(BeanValidationConfiguration configuration, Object obj, Errors errors)
Errors
object.
configuration
- The bean validation configuration that define the validation rules to be applied.obj
- The validated object.errors
- The Errors
instance where the validation error will be registered.protected void applyGlobalValidationRules(BeanValidationConfiguration configuration, Object obj, Errors errors)
Errors
.
configuration
- The bean validation configuration that holds all the global validation rules.obj
- The validated object.errors
- The Errors
instance where all global validation errors will be registered.protected void applyPropertiesValidationRules(BeanValidationConfiguration configuration, Object obj, Errors errors)
Errors
.
configuration
- The bean validation configuration that holds all the property validation rules.obj
- The validated object.errors
- The Errors
instance where all property validation errors will be registered
(see Errors.rejectValue(String, String)
).protected void validateAndShortCircuitRules(ValidationRule[] rules, String propertyName, Object obj, Errors errors)
rules
- The validation rules that should be applied on the given property of the given object.propertyName
- The name of the property to be validated.obj
- The validated object.errors
- The Errors
instance where the validation errors will be registered.protected void applyCustomValidator(BeanValidationConfiguration configuration, Object obj, Errors errors)
configuration
- The configuration from which the custom validator will be taken from.obj
- The object to be validated.errors
- The Errors
instance where all validation errors will be registered.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |