org.springmodules.validation.bean.conf.loader.xml.handler
Class AbstractPropertyValidationElementHandler

java.lang.Object
  extended by org.springmodules.validation.bean.conf.loader.xml.handler.AbstractPropertyValidationElementHandler
All Implemented Interfaces:
PropertyValidationElementHandler, ConditionExpressionBased, FunctionExpressionBased
Direct Known Subclasses:
DateInFutureRuleElementHandler, DateInPastRuleElementHandler, EmailRuleElementHandler, ExpressionPropertyValidationElementHandler, InstantInFutureRuleElementHandler, InstantInPastRuleElementHandler, LengthRuleElementHandler, NotBlankRuleElementHandler, NotEmptyRuleElementHandler, NotNullRuleElementHandler, RangeRuleElementHandler, RegExpRuleElementHandler, SizeRuleElementHandler

public abstract class AbstractPropertyValidationElementHandler
extends java.lang.Object
implements PropertyValidationElementHandler, ConditionExpressionBased, FunctionExpressionBased

A base class for common PropertyValidationElementHandler implementations that represent validation rules. This base handler idetifies the supported elements by their tag names (qualified and local). In addition, it assumes the following common attributes:

Note: The apply-if attribute is being parsed by the ConditionExpressionParser that is associated with this handler. It uses ValangConditionExpressionParser by default.

Author:
Uri Boness

Constructor Summary
AbstractPropertyValidationElementHandler(java.lang.String elementName)
          Constructs a new AbstractPropertyValidationElementHandler with given supported element name.
AbstractPropertyValidationElementHandler(java.lang.String elementName, java.lang.String namespace)
          Constructs a new AbstractPropertyValidationElementHandler with given supported element name and namespace.
AbstractPropertyValidationElementHandler(java.lang.String elementName, java.lang.String namespace, ConditionExpressionParser conditionExpressionParser, FunctionExpressionParser functionExpressionParser)
          Constructs a new AbstractPropertyValidationElementHandler with given supported element name and namespace and a condition handler to parse the apply-if expressions.
 
Method Summary
protected abstract  AbstractValidationRule createValidationRule(org.w3c.dom.Element element)
          Creates the validation rule represented and initialized by and with the given element.
protected  Condition extractApplicabilityCondition(org.w3c.dom.Element element)
          Extracts the validation rule applicability condition from the given element.
protected  ErrorArgumentsResolver extractArgumentsResolver(org.w3c.dom.Element element)
          Extracts the validation rule error arguments from the given element.
protected  java.lang.String extractErrorCode(org.w3c.dom.Element element)
          Extracts the validation rule error code from the given element.
protected  java.lang.String extractMessage(org.w3c.dom.Element element)
          Extracts the validation rule error message from the given element.
protected  ConditionExpressionParser getConditionExpressionParser()
           
protected  FunctionExpressionParser getFunctionExpressionParser()
           
 void handle(org.w3c.dom.Element element, java.lang.String propertyName, MutableBeanValidationConfiguration configuration)
          Creates the appropriate ValidationRule based on the given element and adds it to the given configuration.
 boolean isConditionGloballyScoped(org.w3c.dom.Element element)
          By default the element handlers handle and produce rules that can be associated with both global and non-global contexts.
 void setConditionExpressionParser(ConditionExpressionParser conditionExpressionParser)
          Sets the condition expression parser to be used when parsing the condition expression.
 void setFunctionExpressionParser(FunctionExpressionParser functionExpressionParser)
          Sets the function expression parser to be used when parsing the function expressions.
 boolean supports(org.w3c.dom.Element element, java.lang.Class clazz, java.beans.PropertyDescriptor descriptor)
          Determines whether the given element is supported by this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPropertyValidationElementHandler

public AbstractPropertyValidationElementHandler(java.lang.String elementName)
Constructs a new AbstractPropertyValidationElementHandler with given supported element name.

Parameters:
elementName - The supported element name.

AbstractPropertyValidationElementHandler

public AbstractPropertyValidationElementHandler(java.lang.String elementName,
                                                java.lang.String namespace)
Constructs a new AbstractPropertyValidationElementHandler with given supported element name and namespace.

Parameters:
elementName - The supported element name.
namespace - The supported namespace.

AbstractPropertyValidationElementHandler

public AbstractPropertyValidationElementHandler(java.lang.String elementName,
                                                java.lang.String namespace,
                                                ConditionExpressionParser conditionExpressionParser,
                                                FunctionExpressionParser functionExpressionParser)
Constructs a new AbstractPropertyValidationElementHandler with given supported element name and namespace and a condition handler to parse the apply-if expressions.

Parameters:
elementName - The supported element name.
namespace - The supported namespace.
conditionExpressionParser - The condition expression parser to be used to parse the various condition expressions.
functionExpressionParser - The function expression parser to be used to parse the error arguments expressions.
Method Detail

supports

public boolean supports(org.w3c.dom.Element element,
                        java.lang.Class clazz,
                        java.beans.PropertyDescriptor descriptor)
Determines whether the given element is supported by this handler. The check is done by comparing the element tag name and namespace with the ones that are configured with this handler.

Specified by:
supports in interface PropertyValidationElementHandler
Parameters:
element - The element to be handled.
clazz - The validated clazz.
descriptor - The property descriptor of the validated property.
Returns:
true if this handler can handle the given element, false otherwise.
See Also:
PropertyValidationElementHandler.supports(org.w3c.dom.Element, Class, java.beans.PropertyDescriptor)

handle

public void handle(org.w3c.dom.Element element,
                   java.lang.String propertyName,
                   MutableBeanValidationConfiguration configuration)
Creates the appropriate ValidationRule based on the given element and adds it to the given configuration.

Specified by:
handle in interface PropertyValidationElementHandler
Parameters:
element - The element to be handled.
propertyName - The name of the validated property.
configuration - The configuration to be manipulated.
See Also:
handle(org.w3c.dom.Element, String, org.springmodules.validation.bean.conf.MutableBeanValidationConfiguration)

isConditionGloballyScoped

public boolean isConditionGloballyScoped(org.w3c.dom.Element element)
By default the element handlers handle and produce rules that can be associated with both global and non-global contexts.


extractErrorCode

protected java.lang.String extractErrorCode(org.w3c.dom.Element element)
Extracts the validation rule error code from the given element. Expects a "code" attribute to indicate the error code. If no such attribute exisits, returns null.

Parameters:
element - The element that represents the validation rule.
Returns:
The validation rule error code.

extractMessage

protected java.lang.String extractMessage(org.w3c.dom.Element element)
Extracts the validation rule error message from the given element. Expects a "message" attribute to indicate the error message. If no such attribute exisits, returns extractErrorCode(org.w3c.dom.Element) instead.

Parameters:
element - The element that represents the validation rule.
Returns:
The validation rule error message.

extractArgumentsResolver

protected ErrorArgumentsResolver extractArgumentsResolver(org.w3c.dom.Element element)
Extracts the validation rule error arguments from the given element. Expects an "args" attribute to indicate the error arguments. If no such attribute exisits, returns an empty array.

Parameters:
element - The element that represents the validation rule.
Returns:
The validation rule error arguments.

extractApplicabilityCondition

protected Condition extractApplicabilityCondition(org.w3c.dom.Element element)
Extracts the validation rule applicability condition from the given element. Expects an "apply-if" attribute to indicate the condition expression. If no such attribute exisits, an AlwaysTrueCondition is returned. The configured ConditionExpressionParser is used to parse the found expression to a condition.

Parameters:
element - The element that represents the validation rule.
Returns:
The validation rule applicability condition.

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)

getConditionExpressionParser

protected ConditionExpressionParser getConditionExpressionParser()

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)

getFunctionExpressionParser

protected FunctionExpressionParser getFunctionExpressionParser()

createValidationRule

protected abstract AbstractValidationRule createValidationRule(org.w3c.dom.Element element)
Creates the validation rule represented and initialized by and with the given element.

Parameters:
element - The element that represents the validation rule.
Returns:
The newly created validation rule.


Copyright © 2005. All Rights Reserved.