com.tzavellas.validation
Class PropertyValidator<T>

java.lang.Object
  extended by com.tzavellas.validation.PropertyValidator<T>
Type Parameters:
T - the type (or a parent type) of the property
Direct Known Subclasses:
LinkedValidatorBuilder

public class PropertyValidator<T>
extends Object

A class used to validate a JavaBean property.

Author:
Spiros Tzavellas

Nested Class Summary
static class PropertyValidator.Builder<T>
          A builder used to create a PropertyValidator
 
Field Summary
protected  String property
           
 
Constructor Summary
PropertyValidator(String property)
          This is for the LinkedValidatorBuilder and subclasses.
PropertyValidator(String property, com.tzavellas.validation.validators.Validator<T> validator, ValidationError errorMessage)
          Construct a PropertyValidator
 
Method Summary
 String getProperty()
          Get the name of the property this validator will validate.
 boolean isValid(T value)
          Test if the specified property value is valid
 void setDefaultErrorMessage(String message)
          Modify the default message of the ValidationError this validator returns.
 void setErrorCode(String errorCode)
          Modify the error code of the ValidationError this validator returns.
 ValidationError validate(T value)
          Test if the specified property value is valid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

property

protected String property
Constructor Detail

PropertyValidator

public PropertyValidator(String property)
This is for the LinkedValidatorBuilder and subclasses. If you want to construct a PropertyValidator use the other constructor or use/subclass LinkedValidatorBuilder.


PropertyValidator

public PropertyValidator(String property,
                         com.tzavellas.validation.validators.Validator<T> validator,
                         ValidationError errorMessage)
Construct a PropertyValidator

Parameters:
property - the name of the property
validator - the validator that will validate the property's value
errorMessage - the error that will be returned if the validation fails
Method Detail

getProperty

public String getProperty()
Get the name of the property this validator will validate.


isValid

public boolean isValid(T value)
Test if the specified property value is valid

Parameters:
value - the value of the property.
Returns:
true if valid else false.

validate

public ValidationError validate(T value)
Test if the specified property value is valid

Parameters:
value - the value of the property.
Returns:
null if valid else a ValdationError.

setErrorCode

public void setErrorCode(String errorCode)
Modify the error code of the ValidationError this validator returns.

Parameters:
errorCode - the new error code

setDefaultErrorMessage

public void setDefaultErrorMessage(String message)
Modify the default message of the ValidationError this validator returns.

Parameters:
message - the new default message


Copyright © 2007-2009 spiros.blog(). All Rights Reserved.