velosurf.validation
Class Range

java.lang.Object
  extended by velosurf.validation.FieldConstraint
      extended by velosurf.validation.Range

public class Range
extends FieldConstraint

A type and range constraint on numbers. Syntax is:

    <column [type="integer"] [min="min"] [max="max"]/>
  

where you donnot need to specify both min and max.

Or:

     <integer|number [min="min-value"] [max="max-value"] [message="error-message"] />
 

Note: this constraint is not meant to replace an internal SQL constraint in the database, since it cannot be made sure that complex updates will respect this constraint.

Author:
Claude Brisson

Field Summary
private  boolean integer
          integer value expected.
private static java.util.regex.Pattern intPattern
          integer value pattern matcher.
private  java.lang.Number max
          maximum value.
private  java.lang.Number min
          minimum value.
 
Constructor Summary
Range()
          Constructor.
 
Method Summary
 void setInteger(boolean integer)
          Whether to expect an integer or not.
 void setMax(java.lang.Number max)
          Maximum value setter.
 void setMin(java.lang.Number min)
          Minimum value setter.
 java.lang.String toString()
          return a string representation for this constraint.
 boolean validate(java.lang.Object data)
          Validate data against this constraint.
 
Methods inherited from class velosurf.validation.FieldConstraint
getMessage, setMessage, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

min

private java.lang.Number min
minimum value.


max

private java.lang.Number max
maximum value.


integer

private boolean integer
integer value expected.


intPattern

private static java.util.regex.Pattern intPattern
integer value pattern matcher.

Constructor Detail

Range

public Range()
Constructor.

Method Detail

setInteger

public void setInteger(boolean integer)
Whether to expect an integer or not.

Parameters:
integer - a boolean

setMin

public void setMin(java.lang.Number min)
Minimum value setter.

Parameters:
min - minimum value

setMax

public void setMax(java.lang.Number max)
Maximum value setter.

Parameters:
max - maximum value

validate

public boolean validate(java.lang.Object data)
                 throws java.sql.SQLException
Validate data against this constraint.

Overrides:
validate in class FieldConstraint
Parameters:
data - the data to be validated
Returns:
true if data is in the expected range and type
Throws:
java.sql.SQLException

toString

public java.lang.String toString()
return a string representation for this constraint.

Overrides:
toString in class java.lang.Object
Returns:
string


~ooOoo~