Class IntegerValidator

java.lang.Object
org.exolab.castor.xml.validators.PatternValidator
org.exolab.castor.xml.validators.IntegerValidator
All Implemented Interfaces:
TypeValidator

public class IntegerValidator extends PatternValidator implements TypeValidator
The Integer Validation class. This class handles validation for the primitive long and java.lang.Long types as well as all xsd:integer-derived types such as positive-integer and negative-integer
Version:
$Revision: 8617 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
Author:
Keith Visco
  • Field Summary

    Fields inherited from class PatternValidator

    resourceBundle
    Modifier and Type
    Field
    Description
    protected static ResourceBundle
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new IntegerValidator with no restrictions.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the fixed value for this IntegerValidator.
    void
    Clears the maximum value for this IntegerValidator.
    void
    Clears the minimum value for this IntegerValidator.
    Returns the configured fixed value for Integer validation.
    Returns the configured maximum value for xsd:integer validation.
    Returns the configured minimum value for xsd:integer validation.
    Returns the configured maximum number of digits (inclusive) for xsd:integer validation.
    boolean
    Returns true if a fixed value to validate against has been set.
    void
    setFixed(int fixedValue)
    Sets the fixed value that integers validated with this validated must be equal to.
    void
    setFixed(long fixedValue)
    Sets the fixed value that integers validated with this validated must be equal to.
    void
    setFixed(Long fixedValue)
    Sets the fixed value for xsd:Integer validation.
    void
    setMaxExclusive(int maxValue)
    Sets the maximum (exclusive) value for xsd:integer validation.
    void
    setMaxExclusive(long maxValue)
    Sets the maximum (exclusive) value for xsd:integer validation.
    void
    setMaxInclusive(int maxValue)
    Sets the maximum (inclusive) value for xsd:integer validation.
    void
    setMaxInclusive(long maxValue)
    Sets the maximum (inclusive) value for xsd:integer validation.
    void
    setMinExclusive(int minValue)
    Sets the minimum (exclusive) value for xsd:integer validation.
    void
    setMinExclusive(long minValue)
    Sets the minimum (exclusive) value for xsd:integer validation.
    void
    setMinInclusive(int minValue)
    Sets the minimum (inclusive) value for xsd:integer validation.
    void
    setMinInclusive(long minValue)
    Sets the minimum (inclusive) value for xsd:integer validation.
    void
    setTotalDigits(int totalDig)
    Sets the maximum number of digits for xsd:integer validation.
    void
    validate(long value, ValidationContext context)
    Validates the given Object.
    void
    validate(Object object)
    Validates the given Object.
    void
    validate(Object object, ValidationContext context)
    Validates the given Object.

    Methods inherited from class PatternValidator

    addPattern, clearPatterns, getPatterns, hasPattern, isNillable, setNillable, validate
    Modifier and Type
    Method
    Description
    void
    addPattern(String pattern)
    Sets the regular expression to validate against.
    void
    Clear all configured patterns.
    Returns the collection of regular expression patterns.
    boolean
    Returns true if a regular expression has been set for this PatternValidator.
    boolean
    Returns whether or not objects validated by this Validator are nillable (are allowed to be null).
    void
    setNillable(boolean nillable)
    Sets whether or not objects validated by this Validator are allowed to be null (nillable).
    void
    Validates the given String against the regular expression pattern of this PatternValidator.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IntegerValidator

      public IntegerValidator()
      Creates a new IntegerValidator with no restrictions.
  • Method Details

    • clearFixed

      public void clearFixed()
      Clears the fixed value for this IntegerValidator.
    • clearMax

      public void clearMax()
      Clears the maximum value for this IntegerValidator.
    • clearMin

      public void clearMin()
      Clears the minimum value for this IntegerValidator.
    • getFixed

      public Long getFixed()
      Returns the configured fixed value for Integer validation. Returns null if no fixed value has been configured.
      Returns:
      the fixed value to validate against.
    • getMaxInclusive

      public Long getMaxInclusive()
      Returns the configured maximum value for xsd:integer validation. Returns null if no maximum has been configured.
      Returns:
      the maximum (inclusive) value to validate against.
    • getMinInclusive

      public Long getMinInclusive()
      Returns the configured minimum value for xsd:integer validation. Returns null if no minimum has been configured.
      Returns:
      the minimum (inclusive) value to validate against.
    • getTotalDigits

      public Integer getTotalDigits()
      Returns the configured maximum number of digits (inclusive) for xsd:integer validation. Returns null if no maximum number of digits has been configured.
      Returns:
      the maximum number of digits to validate against.
    • hasFixed

      public boolean hasFixed()
      Returns true if a fixed value to validate against has been set.
      Returns:
      true if a fixed value has been set.
    • setFixed

      public void setFixed(long fixedValue)
      Sets the fixed value that integers validated with this validated must be equal to.

      NOTE: Using Fixed values takes preceedence over using max and mins, and is really the same as setting both max-inclusive and min-inclusive to the same value

      Parameters:
      fixedValue - the fixed value an integer validated with this validator must be equal to.
    • setFixed

      public void setFixed(int fixedValue)
      Sets the fixed value that integers validated with this validated must be equal to.

      NOTE: Using Fixed values takes preceedence over using max and mins, and is really the same as setting both max-inclusive and min-inclusive to the same value Added for backward compatibility with old <xs:integer> implementation.

      Parameters:
      fixedValue - the fixed value an integer validated with this validator must be equal to.
    • setFixed

      public void setFixed(Long fixedValue)
      Sets the fixed value for xsd:Integer validation.

      NOTE: If maximum and/or minimum values have been set and the fixed value is not within that max/min range, then no xsd:Integer will pass validation. This is as according to the XML Schema spec.

      Parameters:
      fixedValue - the fixed value that a xsd:Integer validated with this validator must be equal to.
    • setMinExclusive

      public void setMinExclusive(long minValue)
      Sets the minimum (exclusive) value for xsd:integer validation. To pass validation, an xsd:Integer must be greater than this value.
      Parameters:
      minValue - the minimum (exclusive) value for xsd:Integer validation.
    • setMinExclusive

      public void setMinExclusive(int minValue)
      Sets the minimum (exclusive) value for xsd:integer validation. To pass validation, an xsd:Integer must be greater than this value. Added for backward compatibility with old <xs:integer> implementation.
      Parameters:
      minValue - the minimum (exclusive) value for xsd:Integer validation.
    • setMinInclusive

      public void setMinInclusive(long minValue)
      Sets the minimum (inclusive) value for xsd:integer validation. To pass validation, an xsd:integer must be greater than or equal to this value.
      Parameters:
      minValue - the minimum (inclusive) value for xsd:integer validation.
    • setMinInclusive

      public void setMinInclusive(int minValue)
      Sets the minimum (inclusive) value for xsd:integer validation. To pass validation, an xsd:integer must be greater than or equal to this value. Added for backward compatibility with old <xs:integer> implementation.
      Parameters:
      minValue - the minimum (inclusive) value for xsd:integer validation.
    • setMaxExclusive

      public void setMaxExclusive(long maxValue)
      Sets the maximum (exclusive) value for xsd:integer validation. To pass validation, a xsd:integer must be less than this value.
      Parameters:
      maxValue - the maximum (exclusive) value for xsd:integer validation.
    • setMaxExclusive

      public void setMaxExclusive(int maxValue)
      Sets the maximum (exclusive) value for xsd:integer validation. To pass validation, a xsd:integer must be less than this value. Added for backward compatibility with old <xs:integer> implementation.
      Parameters:
      maxValue - the maximum (exclusive) value for xsd:integer validation.
    • setMaxInclusive

      public void setMaxInclusive(long maxValue)
      Sets the maximum (inclusive) value for xsd:integer validation. To pass validation, a xsd:integer must be less than or equal to this value.
      Parameters:
      maxValue - the maximum (inclusive) value for xsd:integer validation.
    • setMaxInclusive

      public void setMaxInclusive(int maxValue)
      Sets the maximum (inclusive) value for xsd:integer validation. To pass validation, a xsd:integer must be less than or equal to this value. Added for backward compatibility with old <xs:integer> implementation.
      Parameters:
      maxValue - the maximum (inclusive) value for xsd:integer validation.
    • setTotalDigits

      public void setTotalDigits(int totalDig)
      Sets the maximum number of digits for xsd:integer validation. To pass validation, a xsd:integer must have this many digits or fewer. Leading zeros are not counted.
      Parameters:
      totalDig - the maximum (inclusive) number of digits for xsd:integer validation. (must be > 0)
    • validate

      public void validate(long value, ValidationContext context) throws ValidationException
      Validates the given Object.
      Parameters:
      value - the long to validate
      context - the ValidationContext
      Throws:
      ValidationException - if the object fails validation.
    • validate

      public void validate(Object object) throws ValidationException
      Validates the given Object.
      Parameters:
      object - the Object to validate
      Throws:
      ValidationException - if the object fails validation.
    • validate

      public void validate(Object object, ValidationContext context) throws ValidationException
      Validates the given Object.
      Specified by:
      validate in interface TypeValidator
      Overrides:
      validate in class PatternValidator
      Parameters:
      object - the Object to validate
      context - the ValidationContext
      Throws:
      ValidationException - if the object fails validation.