org.springmodules.validation.bean.rule
Class PropertyValidationRule

java.lang.Object
  extended by org.springmodules.validation.bean.rule.PropertyValidationRule
All Implemented Interfaces:
ValidationRule

public class PropertyValidationRule
extends Object
implements ValidationRule

A ValidationRule implementation that wraps another validation rule and is associated with a specific property name. This validation rule is applicable on an object only if the object has the associated property and if wrapped rule is applicable on the value of that property. The condition of the rule is condition of the wrapped rule applied on the value of the associated property of the object.

Author:
Uri Boness

Nested Class Summary
protected static class PropertyValidationRule.DefaultApplicabilityCondition
           
 
Constructor Summary
PropertyValidationRule()
          Constructs a new PropertyValidationRule (javabean support).
PropertyValidationRule(String propertyName, ValidationRule rule)
          Constructs a new PropertyValidationRule with a given property and a wrapped validation rule.
 
Method Summary
protected static boolean checkContext(String[] tokens)
           
 Condition getCondition()
          Returns the conditoin of this validation rule.
 String getDefaultErrorMessage()
          Returns the default error message of this validation rule.
 Object[] getErrorArguments(Object obj)
          Returns the arguments for the error of this validation rule.
 String getErrorCode()
          Returns the error code of this condition.
 boolean isApplicable(Object obj)
          Determines whether this rule is applicable on the given object.
 void setApplicabilityCondition(Condition applicabilityCondition)
           
 void setContextTokens(String[] contextTokens)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyValidationRule

public PropertyValidationRule()
Constructs a new PropertyValidationRule (javabean support).


PropertyValidationRule

public PropertyValidationRule(String propertyName,
                              ValidationRule rule)
Constructs a new PropertyValidationRule with a given property and a wrapped validation rule.

Parameters:
propertyName - The name of the associated property.
rule - The validation rule to be wrapped.
Method Detail

isApplicable

public boolean isApplicable(Object obj)
Determines whether this rule is applicable on the given object. In practice, this validation rule is applicable only if the given object a property that match the property associated with this rule and if the wrapped rule is applicable on the value of that property.

Specified by:
isApplicable in interface ValidationRule
Parameters:
obj - The object to be validated.
Returns:
true if this rule is applicable on the given object, false otherwise.
See Also:
ValidationRule.isApplicable(Object)

getCondition

public Condition getCondition()
Returns the conditoin of this validation rule. In practice, applying this condition means applying the condition of the wrapped rule on the value of the associated property of the validated object.

Specified by:
getCondition in interface ValidationRule
Returns:
The condition of this validation rule.
See Also:
ValidationRule.getCondition()

getErrorCode

public String getErrorCode()
Returns the error code of this condition. This error code is the same as the error code of the wrapped rule.

Specified by:
getErrorCode in interface ValidationRule
Returns:
The error code of this condition.

getErrorArguments

public Object[] getErrorArguments(Object obj)
Returns the arguments for the error of this validation rule. These arguments are the same as the ones of the wrapped rule.

Specified by:
getErrorArguments in interface ValidationRule
Parameters:
obj - The validated object.
Returns:
The arguments for the error of this validation rule.

getDefaultErrorMessage

public String getDefaultErrorMessage()
Returns the default error message of this validation rule. This error message is the same as the error message of the wrapped rule.

Specified by:
getDefaultErrorMessage in interface ValidationRule
Returns:
The default error message of this validation rule.

setApplicabilityCondition

public void setApplicabilityCondition(Condition applicabilityCondition)

setContextTokens

public void setContextTokens(String[] contextTokens)

checkContext

protected static boolean checkContext(String[] tokens)


Copyright © 2009. All Rights Reserved.