net.sf.mmm.value.validator.base
Class AbstractCompositeValueValidator

java.lang.Object
  extended by net.sf.mmm.value.validator.base.AbstractCompositeValueValidator
All Implemented Interfaces:
Serializable, ValueValidator
Direct Known Subclasses:
ValueAndValidator, ValueOrValidator

public abstract class AbstractCompositeValueValidator
extends Object
implements ValueValidator

This is an abstract base implementation of a composite ValueValidatorIF.

Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.mmm.value.validator.api.ValueValidator
XML_ATR_VALIDATOR_TYPE, XML_TAG_VALIDATOR
 
Constructor Summary
AbstractCompositeValueValidator()
          The constructor.
 
Method Summary
 void add(ValueValidator child)
          This method adds a child validator to this composite validator.
 ValueValidator getChild(int index)
          This method gets the child validator at the given position.
 int getChildCount()
          This method gets the number of child validators.
protected  int getMaximumRequiredValidChildren()
          This method gets the maximum number of child validators that must succeed until no further child validators are evaluated.
protected abstract  ValidationResult getResult(ValidationResult[] details, int detailCount, int succeedCount)
          This method is called after the child validators are evaluated and creates the validation result of the collected information.
protected  ValidationResult getResultIfEmpty()
          This method gets the validation result if this composite validator has no children.
 ValidationResult validate(Object value)
          This method validates the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCompositeValueValidator

public AbstractCompositeValueValidator()
The constructor.

Method Detail

getChildCount

public int getChildCount()
This method gets the number of child validators.

Returns:
the number of child validators.

getChild

public ValueValidator getChild(int index)
This method gets the child validator at the given position.

Parameters:
index - is the position of the requested child validator.
Returns:
the child validator at the given index.

add

public void add(ValueValidator child)
This method adds a child validator to this composite validator.

Parameters:
child - is the new child validator to add.

getResultIfEmpty

protected ValidationResult getResultIfEmpty()
This method gets the validation result if this composite validator has no children.

Returns:
the result if empty.

getResult

protected abstract ValidationResult getResult(ValidationResult[] details,
                                              int detailCount,
                                              int succeedCount)
This method is called after the child validators are evaluated and creates the validation result of the collected information.

Parameters:
details - is the array containing the invalid results of the child validtors.
detailCount - is the number of invalid results in the array (may be less than the array length).
succeedCount - is the number of child validators that succeeded.
Returns:
the final validation result.

getMaximumRequiredValidChildren

protected int getMaximumRequiredValidChildren()
This method gets the maximum number of child validators that must succeed until no further child validators are evaluated.
E.g. if you want to create a composite validator with OR logic you can override this method and return 1. Then the getResult(ValidationResult[], int, int) method will be called after the first validator suceeded.
The default value is Integer.MAX_VALUE so all child validators are always performed.

Returns:
the maximum number of child validators that need to succeed until the validation result can be generated.

validate

public ValidationResult validate(Object value)
This method validates the given value. The implementation decides what is valid and invalid.

Specified by:
validate in interface ValueValidator
Parameters:
value - the value to validate. It may be null but its not allowed to throw a NullPointerException for this reason.
Returns:
the result of the validation.


Copyright © 2001-2008 mmm-Team. All Rights Reserved.