edu.nrao.sss.validation
Class AbstractValidator<T>

java.lang.Object
  extended by edu.nrao.sss.validation.AbstractValidator<T>
All Implemented Interfaces:
Validator

public abstract class AbstractValidator<T>
extends Object
implements Validator

Partial implementation of a Validator.

Version Info:

$Revision: 1511 $
$Date: 2008-08-19 11:43:17 -0600 (Tue, 19 Aug 2008) $
$Author: dharland $

Since:
2007-02-05
Author:
David M. Harland

Field Summary
protected  boolean failFast
          When true, validate() stops running tests after first failure.
protected  List<ValidationFailure> failures
          List of all validation failures.
protected  ValidationManager manager
          The manager for which this validator is performing its duties.
protected  ValidationPurpose purpose
          The purpose for which this validator was most recently run.
protected  T target
          The object most recently subject to validation by this validator.
 
Constructor Summary
protected AbstractValidator(String validatorName, Class<? extends T> targetClass)
          Helps create a new instance.
 
Method Summary
 String getName()
          Returns the name of this validator.
 ValidationPurpose getPurpose()
          Returns the purpose for which this validator was most recently run.
 T getTarget()
          Returns the object most recently subject to validation by this validator.
protected abstract  List<Validation<T>> makeValidationList(ValidationPurpose purpose)
          Creates and returns a list of validations to be performed for the given purpose.
 void setManager(ValidationManager newManager)
          Sets the manager for which this validator is performing its duties.
 void stopTestingAfterFirstFailure(boolean stop)
          Tells this validator whether it should run all validations or stop after the first validation that fails.
protected  void validate()
          Runs each of the individual validations.
 List<ValidationFailure> validate(Object target, ValidationPurpose purpose)
          Validates target for use for the given purpose.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

target

protected T target
The object most recently subject to validation by this validator. This variable is initially null.


purpose

protected ValidationPurpose purpose
The purpose for which this validator was most recently run. This variable is initially ValidationPurpose.CERTIFY_READY_TO_USE.


failures

protected List<ValidationFailure> failures
List of all validation failures. This list is never null, but may be empty.


manager

protected ValidationManager manager
The manager for which this validator is performing its duties. This variable is initially null.


failFast

protected boolean failFast
When true, validate() stops running tests after first failure. This variable is initially false.

Constructor Detail

AbstractValidator

protected AbstractValidator(String validatorName,
                            Class<? extends T> targetClass)
Helps create a new instance.

Method Detail

getName

public String getName()
Description copied from interface: Validator
Returns the name of this validator. A common construct is for a validator to return its fully qualified class name.

Specified by:
getName in interface Validator
Returns:
the name of this validator.

getTarget

public T getTarget()
Description copied from interface: Validator
Returns the object most recently subject to validation by this validator.

Specified by:
getTarget in interface Validator
Returns:
the object most recently subject to validation by this validator. If this validator has not yet been used, the return value will be null.

getPurpose

public ValidationPurpose getPurpose()
Description copied from interface: Validator
Returns the purpose for which this validator was most recently run.

Specified by:
getPurpose in interface Validator
Returns:
the purpose for which this validator was most recently run.

setManager

public void setManager(ValidationManager newManager)
Description copied from interface: Validator
Sets the manager for which this validator is performing its duties. It is not necessary for this validator to work for any manager; therefore null is an acceptable value for newManager.

The main use made by this validator of its manager is to request validators for the component objects held by the target object of this validator.

Specified by:
setManager in interface Validator
Parameters:
newManager - the manager for which this validator is performing its duties.

stopTestingAfterFirstFailure

public void stopTestingAfterFirstFailure(boolean stop)
Tells this validator whether it should run all validations or stop after the first validation that fails. The concrete implementations of this abstract are free to override this default implementation, whic is to run all validations.

Specified by:
stopTestingAfterFirstFailure in interface Validator
Parameters:
stop - if true this validator will stop running its validations after the first one fails.

validate

public List<ValidationFailure> validate(Object target,
                                        ValidationPurpose purpose)
Description copied from interface: Validator
Validates target for use for the given purpose.

Specified by:
validate in interface Validator
Parameters:
target - the object to be validated.
purpose - the reason for the validation.
Returns:
a list of failures encountered during validation. If there were no failures, an empty list is returned.

validate

protected void validate()
Runs each of the individual validations.

Subclasses may use this default implementation or override it. Subclasses that contain collections of component objects will typically override this method, call super.validate(), and then invoke other validators on the elements of the collections.


makeValidationList

protected abstract List<Validation<T>> makeValidationList(ValidationPurpose purpose)
Creates and returns a list of validations to be performed for the given purpose.

Parameters:
purpose - the reason for which a validation is performed.
Returns:
a list of validations to be used for purpose.


Copyright © 2009. All Rights Reserved.