org.beanfabrics.validation
Class Validator

java.lang.Object
  extended by org.beanfabrics.AbstractBean
      extended by org.beanfabrics.validation.Validator
All Implemented Interfaces:
java.lang.Iterable<ValidationRule>, java.util.Collection<ValidationRule>, Bean, ValidationRule

public class Validator
extends AbstractBean
implements java.util.Collection<ValidationRule>, ValidationRule

The Validator is responsible for creating a ValidationState by evaluating a list of ValidationRule instances. It is a composite of validation rules. Rules can be added and removed via the collection interface. A call to the validate() method is delegated to each validation rule in the order they have been added, until the first not-null ValidationState is returned.

See Also:
ValidationRule

Constructor Summary
Validator()
           
 
Method Summary
 void add(int index, ValidationRule o)
          Inserts the specified rule at the specified position in this validator.
 boolean add(ValidationRule o)
          
 boolean addAll(java.util.Collection<? extends ValidationRule> c)
          
 void clear()
          
 boolean contains(java.lang.Object o)
          
 boolean containsAll(java.util.Collection<?> c)
          
 ValidationRule get(int index)
          Returns the rule at the specified position in this Validator .
 boolean isEmpty()
          
 java.util.Iterator<ValidationRule> iterator()
          
 ValidationRule remove(int index)
          Removes the rule at the specified position in this Validator .
 boolean remove(java.lang.Object o)
          
 boolean removeAll(java.util.Collection<?> c)
          
 boolean retainAll(java.util.Collection<?> c)
          
 int size()
          
 java.lang.Object[] toArray()
          
<T> T[]
toArray(T[] a)
          
 ValidationState validate()
          Validates the current context.
 
Methods inherited from class org.beanfabrics.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, equals, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

Validator

public Validator()
Method Detail

validate

public ValidationState validate()
Validates the current context. That context is invalid when at least one validation rule detects an invalid state. Produces a ValidationState by delegating this call to the validation rules in the same order they have been added, until a not-null value is returned.

Specified by:
validate in interface ValidationRule
Returns:
the fresh validation result of this rule.

add

public boolean add(ValidationRule o)

Specified by:
add in interface java.util.Collection<ValidationRule>

add

public void add(int index,
                ValidationRule o)
Inserts the specified rule at the specified position in this validator.

Parameters:
index -
o -

addAll

public boolean addAll(java.util.Collection<? extends ValidationRule> c)

Specified by:
addAll in interface java.util.Collection<ValidationRule>

clear

public void clear()

Specified by:
clear in interface java.util.Collection<ValidationRule>

contains

public boolean contains(java.lang.Object o)

Specified by:
contains in interface java.util.Collection<ValidationRule>

containsAll

public boolean containsAll(java.util.Collection<?> c)

Specified by:
containsAll in interface java.util.Collection<ValidationRule>

get

public ValidationRule get(int index)
Returns the rule at the specified position in this Validator .

Parameters:
index - index of the rule to return
Returns:
rule at the given index

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Collection<ValidationRule>

iterator

public java.util.Iterator<ValidationRule> iterator()

Specified by:
iterator in interface java.lang.Iterable<ValidationRule>
Specified by:
iterator in interface java.util.Collection<ValidationRule>

remove

public boolean remove(java.lang.Object o)

Specified by:
remove in interface java.util.Collection<ValidationRule>

remove

public ValidationRule remove(int index)
Removes the rule at the specified position in this Validator .

Parameters:
index - index of the rule to remove
Returns:
removed rule from the given index

removeAll

public boolean removeAll(java.util.Collection<?> c)

Specified by:
removeAll in interface java.util.Collection<ValidationRule>

retainAll

public boolean retainAll(java.util.Collection<?> c)

Specified by:
retainAll in interface java.util.Collection<ValidationRule>

size

public int size()

Specified by:
size in interface java.util.Collection<ValidationRule>

toArray

public java.lang.Object[] toArray()

Specified by:
toArray in interface java.util.Collection<ValidationRule>

toArray

public <T> T[] toArray(T[] a)

Specified by:
toArray in interface java.util.Collection<ValidationRule>