org.dhmp.util.xml.validator
Class NumberValidator

java.lang.Object
  extended byorg.dhmp.util.xml.validator.Validator
      extended byorg.dhmp.util.xml.validator.NumberValidator

public class NumberValidator
extends Validator

Validates several number related data types. Data types decimal and integer are converted to java BigDecimal. Data types double, float, long and int are converted to corresponding java objects. The conversion is locale sensitive and decimal and group separator interpretation depends on current SchemaCollection's locale.


Nested Class Summary
 
Nested classes inherited from class org.dhmp.util.xml.validator.Validator
Validator.ValidationFailed
 
Field Summary
static int DECIMAL
          Represents decimal data type.
static int DOUBLE
          Represents double data type.
static int FLOAT
          Represents float data type.
static int INT
          Represents int data type.
static int INTEGER
          Represents integer data type.
static int LONG
          Represents long data type.
static java.math.BigDecimal ONE
           
static java.lang.Integer ZERO
           
 
Fields inherited from class org.dhmp.util.xml.validator.Validator
FAIL
 
Constructor Summary
NumberValidator(java.util.Locale locale, int type)
          Creates a new instance of DecimalValidator
 
Method Summary
 int compareTo(java.lang.Object o1, java.lang.Object o2)
          Abstract method for comparing two valid objects used for boundry check.
 java.lang.Object newValue(java.lang.Object value)
          Creates a java instance of corresponding object depending on data type this Validator is written for.
 java.lang.Object validate(java.lang.String name, java.lang.Object value, HierarchicalMap constraints, Schema schema, HierarchicalMap messages, int replace)
          Returns true if the validation is successfull.
 
Methods inherited from class org.dhmp.util.xml.validator.Validator
appendMessage, checkBoundary, checkEnumeration, checkNillable, checkPattern, convert, hasFailed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DECIMAL

public static final int DECIMAL
Represents decimal data type.

See Also:
Constant Field Values

DOUBLE

public static final int DOUBLE
Represents double data type.

See Also:
Constant Field Values

FLOAT

public static final int FLOAT
Represents float data type.

See Also:
Constant Field Values

INT

public static final int INT
Represents int data type.

See Also:
Constant Field Values

INTEGER

public static final int INTEGER
Represents integer data type. This is actually a decimal data type with no fraction digits.

See Also:
Constant Field Values

LONG

public static final int LONG
Represents long data type.

See Also:
Constant Field Values

ZERO

public static final java.lang.Integer ZERO

ONE

public static final java.math.BigDecimal ONE
Constructor Detail

NumberValidator

public NumberValidator(java.util.Locale locale,
                       int type)
Creates a new instance of DecimalValidator

Parameters:
locale - SchemaCollection's locale.
type - number data type which this validator will represent.
Method Detail

validate

public java.lang.Object validate(java.lang.String name,
                                 java.lang.Object value,
                                 HierarchicalMap constraints,
                                 Schema schema,
                                 HierarchicalMap messages,
                                 int replace)
Description copied from class: Validator
Returns true if the validation is successfull. A concreate class can be extended to validate specific data type. It also can replace the value with java object for corresponding XSD data type.

Specified by:
validate in class Validator
Parameters:
name - name of schema component beeing validated.
value - value that is beeing validated.
constraints - HierarchicalMap containing constraints.
schema - reference to Schema which is validating the current value.
messages - StringBuffer where the error messages are appended.
replace - true if value should be replaced by corresponding java Object.
Returns:
true if value contains an valid data type.

compareTo

public int compareTo(java.lang.Object o1,
                     java.lang.Object o2)
Description copied from class: Validator
Abstract method for comparing two valid objects used for boundry check.

Specified by:
compareTo in class Validator
Parameters:
o1 - first object.
o2 - second object.
Returns:
0 - if two objects are equivalent; < 0 if o1 is less than o2; >0 if o1 is greater than o2.

newValue

public java.lang.Object newValue(java.lang.Object value)
Description copied from class: Validator
Creates a java instance of corresponding object depending on data type this Validator is written for.

Specified by:
newValue in class Validator
Parameters:
value - value to be converted to java object depending on data type.
Returns:
java object of corresponding data type.