| java.lang.Object org.millstone.base.data.validator.CompositeValidator
CompositeValidator | public class CompositeValidator implements Validator(Code) | | 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.
author: IT Mill Ltd. version: 3.1.1 since: 3.0 |
Field Summary | |
final public 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. | final public static int | MODE_DEFAULT | final public 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. |
MODE_AND | final public static int MODE_AND(Code) | | The validators are combined with AND clause: validity of the
composite implies validity of the all validators it is composed of
must be valid.
|
MODE_DEFAULT | final public static int MODE_DEFAULT(Code) | | The validators are combined with and clause: validity of the
composite implies validity of the all validators it is composed of
|
MODE_OR | final public static int MODE_OR(Code) | | The validators are combined with OR clause: validity of the
composite implies that some of validators it is composed of
must be valid.
|
CompositeValidator | public CompositeValidator()(Code) | | Construct composite validator in AND mode without error message
|
CompositeValidator | public CompositeValidator(int mode, String errorMessage)(Code) | | Construct composite validator in given mode
|
addValidator | public void addValidator(Validator validator)(Code) | | Add validator to the interface
|
getErrorMessage | public String getErrorMessage()(Code) | | Get the error message for the composite validator.
If the error message is null, original error messages of the
sub-validators are used instead.
|
getMode | final public int getMode()(Code) | | Get the mode of the validator.
Operation mode of the validator: MODE_AND or MODE_OR . |
getSubValidators | public Collection getSubValidators(Class validatorType)(Code) | | 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.
Collection of validators compatible with given type that must apply or null if none fould. |
isValid | public boolean isValid(Object value)(Code) | | Check the validity of the the given value.
The value is valid, if:
MODE_AND : All of the sub-validators are valid
MODE_OR : Any of the sub-validators are valid
|
removeValidator | public void removeValidator(Validator validator)(Code) | | Remove a validator from the composite
|
setErrorMessage | public void setErrorMessage(String errorMessage)(Code) | | Set the error message for the composite validator.
If the error message is null, original error messages of the
sub-validators are used instead.
|
setMode | public void setMode(int mode)(Code) | | Set the mode of the validator. The valid modes are:
MODE_AND (default)
MODE_OR
|
validate | public void validate(Object value) throws Validator.InvalidValueException(Code) | | Validate the the given value.
The value is valid, if:
MODE_AND : All of the sub-validators are valid
MODE_OR : Any of the sub-validators are valid
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.
|
|
|