org.springmodules.validation.validator
Class ConditionalValidator

java.lang.Object
  extended by org.springmodules.validation.validator.ConditionalValidator
All Implemented Interfaces:
Validator

public class ConditionalValidator
extends Object
implements Validator

A validator that is associated with a condition that determines whether it should be applied on a given object or not.

Author:
Uri Boness

Constructor Summary
ConditionalValidator()
           
ConditionalValidator(Validator validator, Condition condition)
          Constructs a new ConditionalValidator with a given underlying validator and the condition.
 
Method Summary
 Condition getCondition()
          Returns the condition associated with this conditional validator.
 Validator getValidator()
          Returns the underlying validator.
 void setCondition(Condition condition)
          Sets the condition of this conditional validator.
 void setValidator(Validator validator)
          Sets the underlying validator.
 boolean supports(Class clazz)
          Returns whether this validation supports the given class.
 void validate(Object obj, Errors errors)
          Validates the given objects only if the given object adheres to the associated condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConditionalValidator

public ConditionalValidator()

ConditionalValidator

public ConditionalValidator(Validator validator,
                            Condition condition)
Constructs a new ConditionalValidator with a given underlying validator and the condition.

Parameters:
validator - The underlying validator.
condition - The condition.
Method Detail

supports

public boolean supports(Class clazz)
Returns whether this validation supports the given class. The call is practically being deligated to the unerlying validator.

Specified by:
supports in interface Validator
Parameters:
clazz - The class to be validated.
Returns:
True if this validator supports the given class, false otherwise.

validate

public void validate(Object obj,
                     Errors errors)
Validates the given objects only if the given object adheres to the associated condition.

Specified by:
validate in interface Validator
Parameters:
obj - The validated object.
errors - The registery where validation error codes will be registered.

setCondition

public void setCondition(Condition condition)
Sets the condition of this conditional validator.

Parameters:
condition - The condition of this conditional validator.

getCondition

public Condition getCondition()
Returns the condition associated with this conditional validator.

Returns:
The condition associated with this conditional validator.

setValidator

public void setValidator(Validator validator)
Sets the underlying validator.

Parameters:
validator - The underlying validator.

getValidator

public Validator getValidator()
Returns the underlying validator.

Returns:
The underlying validator.


Copyright © 2009. All Rights Reserved.