org.millstone.base.data.validator
Class CompositeValidator

java.lang.Object
  |
  +--org.millstone.base.data.validator.CompositeValidator
All Implemented Interfaces:
Validator

public class CompositeValidator
extends java.lang.Object
implements Validator

Composite validator. This validator allows you to chain (compose) many validators to validate one field. The contained validators may be required to all validate the value to validate or it may be enough that one contained validator validates the value. This behaviour is controlled by the modes AND and OR.

Since:
3.0
Version:
3.0.3
Author:
IT Mill Ltd.

Nested Class Summary
 
Nested classes inherited from class org.millstone.base.data.Validator
Validator.InvalidValueException, Validator.Suggestive
 
Field Summary
static int MODE_AND
          The validators are combined with AND clause: validity of the composite implies validity of the all validators it is composed of must be valid.
static int MODE_DEFAULT
          The validators are combined with and clause: validity of the composite implies validity of the all validators it is composed of
static int MODE_OR
          The validators are combined with OR clause: validity of the composite implies that some of validators it is composed of must be valid.
 
Constructor Summary
CompositeValidator()
          Construct composite validator in AND mode without error message
CompositeValidator(int mode, java.lang.String errorMessage)
          Construct composite validator in given mode
 
Method Summary
 void addValidator(Validator validator)
          Add validator to the interface
 java.lang.String getErrorMessage()
          Get the error message for the composite validator.
 int getMode()
          Get the mode of the validator.
 java.util.Collection getSubValidators(java.lang.Class validatorType)
          Get sub-validators by class.
 boolean isValid(java.lang.Object value)
          Check the validity of the the given value.
 void removeValidator(Validator validator)
          Remove a validator from the composite
 void setErrorMessage(java.lang.String errorMessage)
          Set the error message for the composite validator.
 void setMode(int mode)
          Set the mode of the validator.
 void validate(java.lang.Object value)
          Validate the the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_AND

public static final int MODE_AND
The validators are combined with AND clause: validity of the composite implies validity of the all validators it is composed of must be valid.

See Also:
Constant Field Values

MODE_OR

public static final int MODE_OR
The validators are combined with OR clause: validity of the composite implies that some of validators it is composed of must be valid.

See Also:
Constant Field Values

MODE_DEFAULT

public static final int MODE_DEFAULT
The validators are combined with and clause: validity of the composite implies validity of the all validators it is composed of

See Also:
Constant Field Values
Constructor Detail

CompositeValidator

public CompositeValidator()
Construct composite validator in AND mode without error message


CompositeValidator

public CompositeValidator(int mode,
                          java.lang.String errorMessage)
Construct composite validator in given mode

Method Detail

validate

public void validate(java.lang.Object value)
              throws Validator.InvalidValueException
Validate the the given value. The value is valid, if: If the value is invalid, validation error is thrown. If the error message is set (non-null), it is used. If the error message has not been set, the first error occurred is thrown.

Specified by:
validate in interface Validator
Parameters:
value - the value to check
Throws:
Validator.InvalidValueException - if the value is not valid

isValid

public boolean isValid(java.lang.Object value)
Check the validity of the the given value. The value is valid, if:

Specified by:
isValid in interface Validator
Parameters:
value - the value to check

getMode

public final int getMode()
Get the mode of the validator.

Returns:
Operation mode of the validator: MODE_AND or MODE_OR.

setMode

public void setMode(int mode)
Set the mode of the validator. The valid modes are:


getErrorMessage

public java.lang.String getErrorMessage()
Get the error message for the composite validator. If the error message is null, original error messages of the sub-validators are used instead.


setErrorMessage

public void setErrorMessage(java.lang.String errorMessage)
Set the error message for the composite validator. If the error message is null, original error messages of the sub-validators are used instead.


addValidator

public void addValidator(Validator validator)
Add validator to the interface


removeValidator

public void removeValidator(Validator validator)
Remove a validator from the composite


getSubValidators

public java.util.Collection getSubValidators(java.lang.Class validatorType)
Get sub-validators by class.

If the component contains directly or recursively (it contains another composite containing the validator) validators compatible with given type they are returned. This only applies to AND mode composite validators.

If the validator is in OR mode or does not contain any validators of given type null is returned.

Returns:
Collection of validators compatible with given type that must apply or null if none fould.


Copyright © 2000,2001,2002 IT Mill Ltd. All Rights Reserved.