|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.xwork2.validator.AnnotationActionValidatorManager
public class AnnotationActionValidatorManager
AnnotationActionValidatorManager is the entry point into XWork's annotations-based validator framework. Validation rules are specified as annotations within the source files.
Field Summary | |
---|---|
private static Logger |
LOG
|
protected static String |
VALIDATION_CONFIG_SUFFIX
The file suffix for any validation file. |
private Map<String,List<ValidatorConfig>> |
validatorCache
|
private ValidatorFactory |
validatorFactory
|
private Map<String,List<ValidatorConfig>> |
validatorFileCache
|
private ValidatorFileParser |
validatorFileParser
|
Constructor Summary | |
---|---|
AnnotationActionValidatorManager()
|
Method Summary | |
---|---|
private List<ValidatorConfig> |
buildAliasValidatorConfigs(Class aClass,
String context,
boolean checkFile)
|
protected List<ValidatorConfig> |
buildClassValidatorConfigs(Class aClass,
boolean checkFile)
|
private List<ValidatorConfig> |
buildValidatorConfigs(Class clazz,
String context,
boolean checkFile,
Set checked)
This method 'collects' all the validator configurations for a given action invocation. |
protected static String |
buildValidatorKey(Class clazz,
String context)
Builds a key for validators - used when caching validators. |
List<Validator> |
getValidators(Class clazz,
String context)
Returns a list of validators for the given class and context. |
List<Validator> |
getValidators(Class clazz,
String context,
String method)
Returns a list of validators for the given class, context, and method. |
private List<ValidatorConfig> |
loadFile(String fileName,
Class clazz,
boolean checkFile)
|
void |
setValidatorFactory(ValidatorFactory fac)
|
void |
setValidatorFileParser(ValidatorFileParser parser)
|
void |
validate(Object object,
String context)
Validates the given object using action and its context. |
void |
validate(Object object,
String context,
String method)
Validates the given object using an action, its context, and the name of the method being invoked on the action. |
void |
validate(Object object,
String context,
ValidatorContext validatorContext)
Validates an action give its context and a validation context. |
void |
validate(Object object,
String context,
ValidatorContext validatorContext,
String method)
Validates an action give its context and a validation context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String VALIDATION_CONFIG_SUFFIX
private final Map<String,List<ValidatorConfig>> validatorCache
private final Map<String,List<ValidatorConfig>> validatorFileCache
private static final Logger LOG
private ValidatorFactory validatorFactory
private ValidatorFileParser validatorFileParser
Constructor Detail |
---|
public AnnotationActionValidatorManager()
Method Detail |
---|
public void setValidatorFactory(ValidatorFactory fac)
public void setValidatorFileParser(ValidatorFileParser parser)
public List<Validator> getValidators(Class clazz, String context)
ActionValidatorManager
getValidators
in interface ActionValidatorManager
clazz
- the class to lookup.context
- the context of the action class - can be null.
public List<Validator> getValidators(Class clazz, String context, String method)
ActionValidatorManager
getValidators
in interface ActionValidatorManager
clazz
- the class to lookup.context
- the context of the action class - can be null.method
- the name of the method being invoked on the action - can be null.
public void validate(Object object, String context) throws ValidationException
ActionValidatorManager
validate
in interface ActionValidatorManager
object
- the action to validate.context
- the action's context.
ValidationException
- if an error happens when validating the action.public void validate(Object object, String context, String method) throws ValidationException
ActionValidatorManager
validate
in interface ActionValidatorManager
object
- the action to validate.context
- the action's context.method
- the name of the method being invoked on the action - can be null.
ValidationException
- if an error happens when validating the action.public void validate(Object object, String context, ValidatorContext validatorContext) throws ValidationException
ActionValidatorManager
validate
in interface ActionValidatorManager
object
- the action to validate.context
- the action's context.validatorContext
- the validation context to use
ValidationException
- if an error happens when validating the action.public void validate(Object object, String context, ValidatorContext validatorContext, String method) throws ValidationException
ActionValidatorManager
validate
in interface ActionValidatorManager
object
- the action to validate.context
- the action's context.validatorContext
- the validation context to usemethod
- the name of the method being invoked on the action - can be null.
ValidationException
- if an error happens when validating the action.protected static String buildValidatorKey(Class clazz, String context)
clazz
- the action.context
- the action's context.
private List<ValidatorConfig> buildAliasValidatorConfigs(Class aClass, String context, boolean checkFile)
protected List<ValidatorConfig> buildClassValidatorConfigs(Class aClass, boolean checkFile)
private List<ValidatorConfig> buildValidatorConfigs(Class clazz, String context, boolean checkFile, Set checked)
This method 'collects' all the validator configurations for a given action invocation.
It will traverse up the class hierarchy looking for validators for every super class and directly implemented interface of the current action, as well as adding validators for any alias of this invocation. Nifty!
Given the following class structure:
interface Thing; interface Animal extends Thing; interface Quadraped extends Animal; class AnimalImpl implements Animal; class QuadrapedImpl extends AnimalImpl implements Quadraped; class Dog extends QuadrapedImpl;
This method will look for the following config files for Dog:
Animal Animal-context AnimalImpl AnimalImpl-context Quadraped Quadraped-context QuadrapedImpl QuadrapedImpl-context Dog Dog-context
Note that the validation rules for Thing is never looked for because no class in the hierarchy directly implements Thing.
clazz
- the Class to look up validators for.context
- the context to use when looking up validators.checkFile
- true if the validation config file should be checked to see if it has been
updated.checked
- the set of previously checked class-contexts, null if none have been checked
private List<ValidatorConfig> loadFile(String fileName, Class clazz, boolean checkFile)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |