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

java.lang.Object
  extended by org.springmodules.validation.bean.conf.loader.xml.handler.AbstractClassValidationElementHandler
All Implemented Interfaces:
ClassValidationElementHandler, ConditionExpressionBased, FunctionExpressionBased
Direct Known Subclasses:
ExpressionClassValidationElementHandler

public abstract class AbstractClassValidationElementHandler
extends java.lang.Object
implements ClassValidationElementHandler, 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
AbstractClassValidationElementHandler(java.lang.String elementName)
          Constructs a new AbstractPropertyValidationElementHandler with given supported element name.
AbstractClassValidationElementHandler(java.lang.String elementName, java.lang.String namespace)
          Constructs a new AbstractPropertyValidationElementHandler with given supported element name and namespace.
AbstractClassValidationElementHandler(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()
          Returns the condition expression parser associated with this handler.
protected  FunctionExpressionParser getFunctionExpressionParser()
          Returns the FunctionExpressionParser used by this handler to parse the error argument expressions.
 void handle(org.w3c.dom.Element element, MutableBeanValidationConfiguration configuration)
          Creates the appropriate ValidationRule based on the given element and adds it to the given configuration.
 boolean isConditionGloballyScoped()
          By default the element handlers handle and produce rules that can be associated with both global and non-global contexts.
protected  boolean isNullSupported()
          Indicates whether the validation rule supports null values.
 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)
          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

AbstractClassValidationElementHandler

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

Parameters:
elementName - The supported element name.

AbstractClassValidationElementHandler

public AbstractClassValidationElementHandler(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.

AbstractClassValidationElementHandler

public AbstractClassValidationElementHandler(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)
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 ClassValidationElementHandler
Parameters:
element - The element to be handled.
clazz - The validated class.
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,
                   MutableBeanValidationConfiguration configuration)
Creates the appropriate ValidationRule based on the given element and adds it to the given configuration.

Specified by:
handle in interface ClassValidationElementHandler
Parameters:
element - The element to be handled.
configuration - The configuration to be manipulated.
See Also:
handle(org.w3c.dom.Element, org.springmodules.validation.bean.conf.MutableBeanValidationConfiguration)

isConditionGloballyScoped

public boolean isConditionGloballyScoped()
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 null 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 null.

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, returns null.

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()
Returns the condition expression parser associated with this handler.

Returns:
The condition expression parser associated with this handler.

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()
Returns the FunctionExpressionParser used by this handler to parse the error argument expressions.

Returns:
The FunctionExpressionParser used by this handler to parse the error argument expressions.

isNullSupported

protected boolean isNullSupported()
Indicates whether the validation rule supports null values. Null values support means such values will be passed to the rule condition during validation. If the rule doesn't support null values, such value will not be evaluated by the rule condition and the validation will treat them as valid values.

Returns:
true if the validation rule support null values, false otherwise.

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.