|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.millstone.base.data.validator.CompositeValidator
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.
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 |
public static final int MODE_AND
public static final int MODE_OR
public static final int MODE_DEFAULT
Constructor Detail |
public CompositeValidator()
public CompositeValidator(int mode, java.lang.String errorMessage)
Method Detail |
public void validate(java.lang.Object value) throws Validator.InvalidValueException
MODE_AND
: All of the sub-validators are valid
MODE_OR
: Any of the sub-validators are valid
validate
in interface Validator
value
- the value to check
Validator.InvalidValueException
- if the value is not validpublic boolean isValid(java.lang.Object value)
MODE_AND
: All of the sub-validators are valid
MODE_OR
: Any of the sub-validators are valid
isValid
in interface Validator
value
- the value to checkpublic final int getMode()
MODE_AND
or MODE_OR
.public void setMode(int mode)
MODE_AND
(default)
MODE_OR
public java.lang.String getErrorMessage()
public void setErrorMessage(java.lang.String errorMessage)
public void addValidator(Validator validator)
public void removeValidator(Validator validator)
public java.util.Collection getSubValidators(java.lang.Class validatorType)
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |