public class ChainValidator extends Object implements Validator
A special Validator
implementation that allows combining multiple
primitive validators.
An instance of this class can be initialized with an arbitrary number of
child validators. In its implementation of the isValid()
method
the child validators are invoked one after the other. Configuration options
control whether validation should stop when the first validation error was
detected or whether in any case all child validators are to be invoked (in
the latter case really all error messages caused by validation errors can be
collected.)
In the TransformerContext
passed to this validator's
isValid()
method the PROP_SHORT_EVAL
property will be checked. If it is defined, it overrides the flag set using
the setShortEvaluation(boolean)
method.
Modifier and Type | Field and Description |
---|---|
static String |
PROP_SHORT_EVAL
Constant for the short evaluation property.
|
Constructor and Description |
---|
ChainValidator()
Creates a new instance of
ChainValidator . |
Modifier and Type | Method and Description |
---|---|
void |
addChildValidator(Validator child)
Adds a child validator to this chain validator.
|
void |
addChildValidator(Validator child,
Map<String,Object> props)
Adds a child validator to this chain validator and sets special
properties for the new child.
|
protected boolean |
doShortEvaluation(TransformerContext ctx)
Checks whether short evaluation should be performed by the
isValid() method. |
Validator |
getChildValidator(int index)
Returns the child validator at the given index.
|
protected TransformerContext |
getContextForChildValidator(int index,
TransformerContext ctx)
Returns the
TransformerContext to be used for the
specified child validator. |
boolean |
isShortEvaluation()
Returns the
shortEvaluation flag. |
ValidationResult |
isValid(Object o,
TransformerContext ctx)
Validates the passed in object.
|
void |
setShortEvaluation(boolean shortEvaluation)
Sets the
shortEvaluation flag. |
int |
size()
Returns the number of child validators.
|
public static final String PROP_SHORT_EVAL
public boolean isShortEvaluation()
shortEvaluation
flag.public void setShortEvaluation(boolean shortEvaluation)
shortEvaluation
flag. This flag controls the
behavior of the isValid()
method in case of validation
errors. If it is set, validation is aborted when the first child
validator detects an error. Otherwise all child validators will be
invoked and the results are collected.shortEvaluation
- the value of the flagpublic void addChildValidator(Validator child)
child
- the child validator to be added (must not be null)IllegalArgumentException
- if the validator to be added is nullpublic void addChildValidator(Validator child, Map<String,Object> props)
TransformerContext
passed to the
isValid()
method of the child.child
- the child validator to be added (must not be null)props
- a map with properties for the new child validatorIllegalArgumentException
- if the validator to be added is nullpublic int size()
public Validator getChildValidator(int index)
index
< size()
.index
- the index of the child validatorIndexOutOfBoundsException
- if the index is invalidpublic ValidationResult isValid(Object o, TransformerContext ctx)
protected TransformerContext getContextForChildValidator(int index, TransformerContext ctx)
TransformerContext
to be used for the
specified child validator. If the child was added with custom properties,
a specialized context will be created allowing access to these
properties. Otherwise the default context will be returned.index
- the index of the child validatorctx
- the original contextIndexOutOfBoundsException
- if the index is invalidprotected boolean doShortEvaluation(TransformerContext ctx)
isValid()
method. This implementation checks whether the
PROP_SHORT_EVAL
property is defined in the passed
in context. If not, isShortEvaluation()
will be called.ctx
- the current transformer contextCopyright © 2016 The JGUIraffe Team. All rights reserved.