Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.validator
Class DefaultActionValidatorManager

    java.lang.Object
      com.opensymphony.xwork2.validator.DefaultActionValidatorManager

All Implemented Interfaces:
  ActionValidatorManager

    public class DefaultActionValidatorManager

extends Object
implements ActionValidatorManager

This is the entry point into XWork's rule-based validation framework. Validation rules are specified in XML configuration files named "className-contextName-validation.xml" where className is the name of the class the configuration is for and -contextName is optional (contextName is an arbitrary key that is used to look up additional validation rules for a specific context).

Author:
  Jason Carreira, Mark Woon, James House, Rainer Hermanns

Field Summary
`private static Log` | `LOG`
`protected static String` | `VALIDATION_CONFIG_SUFFIX` The file suffix for any validation file.
`private static Map` | `validatorCache`
`private static Map` | `validatorFileCache`

Constructor Summary
`DefaultActionValidatorManager()`

Method Summary
`private List` | `buildAliasValidatorConfigs(Class aClass, String context, boolean checkFile)`
`private List` | `buildClassValidatorConfigs(Class aClass, boolean checkFile)`
`private List` | `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` | `getValidators(Class clazz, String context)` Returns a list of validators for the given class and context.
`private List` | `loadFile(String fileName, Class clazz, boolean checkFile)`
`void` | `validate(Object object, String context)` Validates the given object using action and its context.
`void` | `validate(Object object, String context, ValidatorContext validatorContext)` 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

### VALIDATION_CONFIG_SUFFIX

    protected static final String VALIDATION_CONFIG_SUFFIX

  The file suffix for any validation file.

  See Also:
    Constant Field Values

### validatorCache

    private static final Map validatorCache

### validatorFileCache

    private static final Map validatorFileCache

### LOG

    private static final Log LOG

Constructor Detail

### DefaultActionValidatorManager

    public DefaultActionValidatorManager()

Method Detail

### getValidators

    public List getValidators(Class clazz,
                              String context)

  Returns a list of validators for the given class and context. This is the primary lookup method for validators.

  Specified by:
    `getValidators` in interface `ActionValidatorManager`
  Parameters:
    `clazz` - the class to lookup.
    `context` - the context of the action class - can be `null`.
  Returns:
    a list of all validators for the given class and context.

### validate

    public void validate(Object object,
                         String context)
                  throws ValidationException

  Validates the given object using action and its context.

  Specified by:
    `validate` in interface `ActionValidatorManager`
  Parameters:
    `object` - the action to validate.
    `context` - the action's context.
  Throws:
    `ValidationException` - if an error happens when validating the action.

### validate

    public void validate(Object object,
                         String context,
                         ValidatorContext validatorContext)
                  throws ValidationException

  Validates an action give its context and a validation context.

  Specified by:
    `validate` in interface `ActionValidatorManager`
  Parameters:
    `object` - the action to validate.
    `context` - the action's context.
    `validatorContext` -
  Throws:
    `ValidationException` - if an error happens when validating the action.

### buildValidatorKey

    protected static String buildValidatorKey(Class clazz,
                                              String context)

  Builds a key for validators - used when caching validators.

  Parameters:
    `clazz` - the action.
    `context` - the action's context.
  Returns:
    a validator key which is the class name plus context.

### buildAliasValidatorConfigs

    private List buildAliasValidatorConfigs(Class aClass,
                                            String context,
                                            boolean checkFile)

### buildClassValidatorConfigs

    private List buildClassValidatorConfigs(Class aClass,
                                            boolean checkFile)

### buildValidatorConfigs

    private List 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.

  Parameters:
    `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
  Returns:
    a list of validator configs for the given class and context.

### loadFile

    private List loadFile(String fileName,
                          Class clazz,
                          boolean checkFile)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2007 OpenSymphony. All Rights Reserved.