org.springmodules.validation.bean.conf.loader.xml
Class DefaultXmlBeanValidationConfigurationLoader

java.lang.Object
  extended by org.springmodules.validation.bean.conf.loader.xml.AbstractResourceBasedBeanValidationConfigurationLoader
      extended by org.springmodules.validation.bean.conf.loader.xml.AbstractXmlBeanValidationConfigurationLoader
          extended by org.springmodules.validation.bean.conf.loader.xml.DefaultXmlBeanValidationConfigurationLoader
All Implemented Interfaces:
InitializingBean, ApplicationContextAware, BeanValidationConfigurationLoader, ConditionExpressionBased, FunctionExpressionBased

public class DefaultXmlBeanValidationConfigurationLoader
extends AbstractXmlBeanValidationConfigurationLoader
implements ConditionExpressionBased, FunctionExpressionBased, ApplicationContextAware

The default xml bean validation configuration loader. This loader expects the following xml format:

 <validation [package="org.springmodules.validation.sample"]>
      <class name="Person">
          <global>
              <any/>...
          </global>
          <property name="firstName" [valid="true|false"]>
              <any/>...
          </property>
      </class>
 </validation>
 

Please note the following:

The validation rule element (sub-elements of <global> and <property>) are resolved using validation rule element handlers. This class holds a registry for such handlers, where new handlers can be registered as well. The default registry is DefaultValidationRuleElementHandlerRegistry.

Author:
Uri Boness

Field Summary
static String DEFAULT_NAMESPACE_URL
           
 
Constructor Summary
DefaultXmlBeanValidationConfigurationLoader()
          Constructs a new DefaultXmlBeanValidationConfigurationLoader with the default validation rule element handler registry.
DefaultXmlBeanValidationConfigurationLoader(ValidationRuleElementHandlerRegistry handlerRegistry)
          Constructs a new DefaultXmlBeanValidationConfigurationLoader with the given validation rule element handler registry.
DefaultXmlBeanValidationConfigurationLoader(ValidationRuleElementHandlerRegistry handlerRegistry, ConditionExpressionParser conditionExpressionParser, FunctionExpressionParser functionExpressionParser)
          Constructs a new DefaultXmlBeanValidationConfigurationLoader with the given validation rule element handler registry.
 
Method Summary
 void afterPropertiesSet()
           
protected  ErrorArgumentsResolver buildErrorArgumentsResolver(String argsString)
           
protected  Validator constructValidator(String className)
           
protected  ValidationMethodValidationRule createMethodValidationRule(Class clazz, String methodName, String errorCode, String message, String argsString, String contextsString, String applyIfString)
           
protected  PropertyValidationRule createPropertyRule(String propertyName, ValidationRule rule)
           
protected  void findConditionExpressionParserInApplicationContext()
           
protected  void findFunctionExpressionParserInApplicationContext()
           
 ValidationRuleElementHandlerRegistry getElementHandlerRegistry()
          Returns the element handler registry used by this loader.
 BeanValidationConfiguration handleClassDefinition(Class clazz, Element element)
          Creates and builds a bean validation configuration based for the given class, based on the given <class> element.
protected  void handleGlobalDefinition(Element globalDefinition, Class clazz, MutableBeanValidationConfiguration configuration)
          Handles the <global> element and updates the given configuration with the global validation rules.
protected  void handleMethodDefinition(Element methodDefinition, Class clazz, MutableBeanValidationConfiguration configuration)
           
protected  void handlePropertyDefinition(Element propertyDefinition, Class clazz, MutableBeanValidationConfiguration configuration)
          Handles the given <property> element and updates the given bean validation configuration with the property validation rules.
protected  void handleValidatorBeanDefinition(Element definition, Class clazz, MutableBeanValidationConfiguration configuration)
           
protected  void handleValidatorDefinition(Element validatorDefinition, Class clazz, MutableBeanValidationConfiguration configuration)
           
protected  void initContext(Object object)
           
protected  Map loadConfigurations(Document document, String resourceName)
          Loads the validation configuration from the given document that was created from the given resource.
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setConditionExpressionParser(ConditionExpressionParser conditionExpressionParser)
          Sets the condition expression parser to be used when parsing the condition expression.
 void setElementHandlerRegistry(ValidationRuleElementHandlerRegistry registry)
          Sets the element handler registry this loader will use to fetch the handlers while loading validation configuration.
 void setFunctionExpressionParser(FunctionExpressionParser functionExpressionParser)
          Sets the function expression parser to be used when parsing the function expressions.
protected  void validatePropertyExists(Class clazz, String property)
           
 
Methods inherited from class org.springmodules.validation.bean.conf.loader.xml.AbstractXmlBeanValidationConfigurationLoader
loadConfigurations
 
Methods inherited from class org.springmodules.validation.bean.conf.loader.xml.AbstractResourceBasedBeanValidationConfigurationLoader
createDefaultConfigurationFileName, getResource, getResources, loadConfiguration, loadDefaultConfiguration, setResource, setResources, supports
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAMESPACE_URL

public static final String DEFAULT_NAMESPACE_URL
See Also:
Constant Field Values
Constructor Detail

DefaultXmlBeanValidationConfigurationLoader

public DefaultXmlBeanValidationConfigurationLoader()
Constructs a new DefaultXmlBeanValidationConfigurationLoader with the default validation rule element handler registry.


DefaultXmlBeanValidationConfigurationLoader

public DefaultXmlBeanValidationConfigurationLoader(ValidationRuleElementHandlerRegistry handlerRegistry)
Constructs a new DefaultXmlBeanValidationConfigurationLoader with the given validation rule element handler registry.

Parameters:
handlerRegistry - The validation rule element handler registry that will be used by this loader.

DefaultXmlBeanValidationConfigurationLoader

public DefaultXmlBeanValidationConfigurationLoader(ValidationRuleElementHandlerRegistry handlerRegistry,
                                                   ConditionExpressionParser conditionExpressionParser,
                                                   FunctionExpressionParser functionExpressionParser)
Constructs a new DefaultXmlBeanValidationConfigurationLoader with the given validation rule element handler registry.

Parameters:
handlerRegistry - The validation rule element handler registry that will be used by this loader.
conditionExpressionParser - The condition parser this loader should use to parse the cascade validation conditions.
functionExpressionParser - The function parser this loader should use to parse the error arguments.
Method Detail

loadConfigurations

protected Map loadConfigurations(Document document,
                                 String resourceName)
Loads the validation configuration from the given document that was created from the given resource.

Specified by:
loadConfigurations in class AbstractXmlBeanValidationConfigurationLoader
See Also:
AbstractXmlBeanValidationConfigurationLoader.loadConfigurations(org.w3c.dom.Document, String)

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractResourceBasedBeanValidationConfigurationLoader
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

setElementHandlerRegistry

public void setElementHandlerRegistry(ValidationRuleElementHandlerRegistry registry)
Sets the element handler registry this loader will use to fetch the handlers while loading validation configuration.

Parameters:
registry - The element handler registry to be used by this loader.

getElementHandlerRegistry

public ValidationRuleElementHandlerRegistry getElementHandlerRegistry()
Returns the element handler registry used by this loader.

Returns:
The element handler registry used by this loader.

setConditionExpressionParser

public void setConditionExpressionParser(ConditionExpressionParser conditionExpressionParser)
Description copied from interface: ConditionExpressionBased
Sets the condition expression parser to be used when parsing the condition expression.

Specified by:
setConditionExpressionParser in interface ConditionExpressionBased
Parameters:
conditionExpressionParser - The condition expression parser to be used.
See Also:
ConditionExpressionBased.setConditionExpressionParser(org.springmodules.validation.util.cel.ConditionExpressionParser)

setFunctionExpressionParser

public void setFunctionExpressionParser(FunctionExpressionParser functionExpressionParser)
Description copied from interface: FunctionExpressionBased
Sets the function expression parser to be used when parsing the function expressions.

Specified by:
setFunctionExpressionParser in interface FunctionExpressionBased
Parameters:
functionExpressionParser - The function expression parser to be used.
See Also:
FunctionExpressionBased.setFunctionExpressionParser(org.springmodules.validation.util.fel.FunctionExpressionParser)

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface ApplicationContextAware
See Also:
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

initContext

protected void initContext(Object object)
                    throws Exception
Throws:
Exception

handleClassDefinition

public BeanValidationConfiguration handleClassDefinition(Class clazz,
                                                         Element element)
Creates and builds a bean validation configuration based for the given class, based on the given <class> element.

Parameters:
element - The <class> element.
clazz - The class for which the validation configuration is being loaded.
Returns:
The created bean validation configuration.

handleValidatorDefinition

protected void handleValidatorDefinition(Element validatorDefinition,
                                         Class clazz,
                                         MutableBeanValidationConfiguration configuration)

handleValidatorBeanDefinition

protected void handleValidatorBeanDefinition(Element definition,
                                             Class clazz,
                                             MutableBeanValidationConfiguration configuration)

handleGlobalDefinition

protected void handleGlobalDefinition(Element globalDefinition,
                                      Class clazz,
                                      MutableBeanValidationConfiguration configuration)
Handles the <global> element and updates the given configuration with the global validation rules.

Parameters:
globalDefinition - The <global> element.
clazz - The validated class.
configuration - The bean validation configuration to update.

handleMethodDefinition

protected void handleMethodDefinition(Element methodDefinition,
                                      Class clazz,
                                      MutableBeanValidationConfiguration configuration)

createMethodValidationRule

protected ValidationMethodValidationRule createMethodValidationRule(Class clazz,
                                                                    String methodName,
                                                                    String errorCode,
                                                                    String message,
                                                                    String argsString,
                                                                    String contextsString,
                                                                    String applyIfString)

buildErrorArgumentsResolver

protected ErrorArgumentsResolver buildErrorArgumentsResolver(String argsString)

handlePropertyDefinition

protected void handlePropertyDefinition(Element propertyDefinition,
                                        Class clazz,
                                        MutableBeanValidationConfiguration configuration)
Handles the given <property> element and updates the given bean validation configuration with the property validation rules.

Parameters:
propertyDefinition - The <property> element.
clazz - The validated class.
configuration - The bean validation configuration to update.

createPropertyRule

protected PropertyValidationRule createPropertyRule(String propertyName,
                                                    ValidationRule rule)

constructValidator

protected Validator constructValidator(String className)

findConditionExpressionParserInApplicationContext

protected void findConditionExpressionParserInApplicationContext()

findFunctionExpressionParserInApplicationContext

protected void findFunctionExpressionParserInApplicationContext()

validatePropertyExists

protected void validatePropertyExists(Class clazz,
                                      String property)


Copyright © 2009. All Rights Reserved.