|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.validation.beanvalidation.SpringValidatorAdapter
org.springframework.validation.beanvalidation.CustomValidatorBean
org.springjutsu.validation.ValidationManager
public class ValidationManager
Registerable as a JSR-303 @link{CustomValidatorBean}, this ValidationManager class is instead responsible for reading XML-driven nested validation rules. However, it populates a standard Errors object as expected. Logic is divided into two main portions: First context rules are read from the <context-rules> defined for a given path. These rules are loaded based on the current path the user is accessing, with implementation handled by subclasses. Context rules are typically those rules which are specific to a given form: the fields which are required, and also conditional validation logic based on other fields or variables defined in EL or otherwise. These are the conditional per-form validation rules not handled by JSR-303 Second, model rules are read from the <model-rules> defined for a given class. These rules are loaded directly from the per-class definitions provided in the XML rules. Model rules are those rules which do not change for a given class and include type checking, length checks, and so on. These are the more typical JSR-303 type rules.
CustomValidatorBean| Field Summary | |
|---|---|
protected static org.apache.commons.logging.Log |
log
Validate a lot of requests. |
protected org.springframework.context.MessageSource |
messageSource
We'll load error message definitions from the spring message source. |
protected RuleExecutorContainer |
ruleExecutorContainer
Holds the implementations of the validation rule executors. |
protected ValidationRulesContainer |
rulesContainer
Holds the validation rules which have been parsed from the XML rule sets. |
| Constructor Summary | |
|---|---|
ValidationManager()
|
|
| Method Summary | |
|---|---|
protected String |
appendPath(String path,
String suffix)
Appends two subpath segments together and handles period replacement appropriately. |
protected String |
buildMessageKey(Class<?> parentType,
String fieldPath)
|
protected void |
callRules(Object model,
org.springframework.validation.Errors errors,
List<ValidationRule> modelRules,
boolean prelocalized)
Responsible for delegating each actual model rule to the appropriate @link{RuleExecutor}. |
protected Object |
getContextArgument(Object model,
String expression)
Responsible for determining the argument to be passed to the rule. |
protected Object |
getContextModel(Object model,
String expression)
Responsible for discovering the path-described model which is to be validated by the current rule. |
boolean |
getEnableSuperclassFieldLabelLookup()
|
String |
getErrorMessagePrefix()
|
String |
getFieldLabelPrefix()
|
protected String |
getMessageResolver(Object model,
String rulePath,
boolean resolveAsModel)
This method is responsible for getting the the String used to resolve the message that should be recorded as the error message. |
protected String |
getModelMessageKey(String rawRulePath,
Object rootModel)
If we're trying to resolve the message key for a path on the model, this method will unwrap that message key. |
protected String |
getMVCFormName()
Just cleans up a Servlet path URL for rule resolving by the rules container. |
protected String |
getWebflowFormName()
Gets a identifier of the current state that needs validating in order to determine what rules to load from the validation definition. |
protected boolean |
hasEL(String expression)
|
protected List<Object> |
inheritedCheckedModels(List<Object> checkedModels)
|
protected void |
logError(ValidationRule rule,
Object rootModel,
org.springframework.validation.Errors errors)
In the event that a validation rule fails, this method is responsible for recording an error message on the affected path of the Errors object. |
protected boolean |
passes(ValidationRule rule,
Object rootModel)
Determines if the validation rule passes by calling the rule executor. |
protected Object |
resolveSPEL(String elContaining,
Object model)
Responsible for resolving a SPEL expression. |
void |
setEnableSuperclassFieldLabelLookup(boolean enableSuperclassFieldLabelLookup)
|
void |
setErrorMessagePrefix(String errorMessagePrefix)
|
void |
setFieldLabelPrefix(String fieldLabelPrefix)
|
boolean |
supports(Class<?> clazz)
We delegate to rule container executor, in order to see if rules have been mapped for this class. |
org.springframework.validation.Errors |
validate(Object target)
Hook point to perform validation without a web request. |
void |
validate(Object model,
org.springframework.validation.Errors errors)
We perform actual validation in the order of context rules followed by model rules. |
void |
validate(Object target,
org.springframework.validation.Errors errors,
Object... validationHints)
|
protected void |
validateModel(Object model,
org.springframework.validation.Errors errors,
List<Object> checkedModels,
String currentForm)
Responsible for testing all XML-defined per-class rules. |
| Methods inherited from class org.springframework.validation.beanvalidation.CustomValidatorBean |
|---|
afterPropertiesSet, setMessageInterpolator, setTraversableResolver, setValidatorFactory |
| Methods inherited from class org.springframework.validation.beanvalidation.SpringValidatorAdapter |
|---|
getArgumentsForConstraint, getConstraintsForClass, processConstraintViolations, unwrap, validate, validateProperty, validateValue |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface javax.validation.Validator |
|---|
getConstraintsForClass, unwrap, validate, validateProperty, validateValue |
| Field Detail |
|---|
protected static org.apache.commons.logging.Log log
@Autowired protected ValidationRulesContainer rulesContainer
ValidationRulesContainer,
ValidationRule@Autowired protected RuleExecutorContainer ruleExecutorContainer
RuleExecutorContainer,
RuleExecutor@Autowired protected org.springframework.context.MessageSource messageSource
MessageSource| Constructor Detail |
|---|
public ValidationManager()
| Method Detail |
|---|
public boolean supports(Class<?> clazz)
supports in class org.springframework.validation.beanvalidation.SpringValidatorAdapter#RuleExecutorContainer.supportsClass(Class),
#javax.validation.Validator.supports(Class)public org.springframework.validation.Errors validate(Object target)
public void validate(Object model,
org.springframework.validation.Errors errors)
validate in class org.springframework.validation.beanvalidation.SpringValidatorAdapter
public void validate(Object target,
org.springframework.validation.Errors errors,
Object... validationHints)
validate in interface org.springframework.validation.SmartValidatorvalidate in class org.springframework.validation.beanvalidation.SpringValidatorAdapter
protected void validateModel(Object model,
org.springframework.validation.Errors errors,
List<Object> checkedModels,
String currentForm)
model - the model object to validate. May be a recursed sub bean.errors - standard Errors object to record validation errors to.checkedModels - A list of model objects we have already validated,
in order to prevent unneeded or infinite recursion
protected void callRules(Object model,
org.springframework.validation.Errors errors,
List<ValidationRule> modelRules,
boolean prelocalized)
model - The object being validatederrors - Standard errors object to record validation errors.modelRules - A list of ValidationRules parsed fromprelocalized - indicates if child rules are already localized to the base path of the errors object.
the <model-rules> section of the validation XML.protected String getMVCFormName()
protected String getWebflowFormName()
protected boolean passes(ValidationRule rule,
Object rootModel)
rule - The validation rule to runrootModel - The model to run the rule on.
protected Object getContextModel(Object model,
String expression)
model - Object to be validatedexpression - The string path expression for the model.
protected Object getContextArgument(Object model,
String expression)
model - Object to be validatedexpression - The string path expression for the model.
protected void logError(ValidationRule rule,
Object rootModel,
org.springframework.validation.Errors errors)
rule - the rule which failedrootModel - the root model (not failed bean)errors - standard Errors object to record error on.
protected String getMessageResolver(Object model,
String rulePath,
boolean resolveAsModel)
model - The root model on which the path describes the error location.rulePath - The path which was given to the rule. The path that was
validated using the rule and failed.resolveAsModel - if true, use the behavior to resolve the model.
Otherwise, use the behavior to resolve the argument.
protected String getModelMessageKey(String rawRulePath,
Object rootModel)
rulePath - Validation rule path to the failed field.rootModel - The root model owning the field that failed.
protected String buildMessageKey(Class<?> parentType,
String fieldPath)
protected boolean hasEL(String expression)
expression - A string expression
protected Object resolveSPEL(String elContaining,
Object model)
el - The EL expression to resolve.model - The model on which the EL-described field MAY lie.
protected String appendPath(String path,
String suffix)
path - A string path.suffix - A string path to add to the prior path.
public String getErrorMessagePrefix()
public void setErrorMessagePrefix(String errorMessagePrefix)
public String getFieldLabelPrefix()
public void setFieldLabelPrefix(String fieldLabelPrefix)
public boolean getEnableSuperclassFieldLabelLookup()
public void setEnableSuperclassFieldLabelLookup(boolean enableSuperclassFieldLabelLookup)
protected List<Object> inheritedCheckedModels(List<Object> checkedModels)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||