org.dhmp.util.xml.validator
Class Validator

java.lang.Object
  extended byorg.dhmp.util.xml.validator.Validator
Direct Known Subclasses:
BooleanValidator, DateTimeValidator, GroupValidator, NumberValidator, ObjectValidator, ReferenceValidator, SimpleObjectValidator, StringValidator

public abstract class Validator
extends java.lang.Object

Abstract class for Validators. During the XML Schema Document parsing, a validator is designated for each data type.

Author:
hideyuki

Nested Class Summary
static class Validator.ValidationFailed
          Class returned when validation error occurs.
 
Field Summary
static Validator.ValidationFailed FAIL
           
 
Constructor Summary
Validator()
           
 
Method Summary
static void appendMessage(java.lang.String name, java.lang.String key, HierarchicalMap constraint, Schema schema, HierarchicalMap messages, java.lang.String defaultMessageComplement)
          Appends an error message retrieving the error message from XML Schema Document, ResourceBundle or providing a default error message.
 boolean checkBoundary(java.lang.String name, java.lang.Object value, HierarchicalMap constraint, Schema schema, HierarchicalMap messages)
          Checks if the value does not exceed minimun and maximun boundries.
 boolean checkEnumeration(java.lang.String name, java.lang.Object value, HierarchicalMap constraint, Schema schema, HierarchicalMap messages)
          Checks if the value appear in the enumeration list inside constraints.
 boolean checkNillable(java.lang.String name, java.lang.Object value, HierarchicalMap constraint, Schema schema, HierarchicalMap messages)
          Checks if the value is null and if so, check if it is nillable.
 boolean checkPattern(java.lang.String name, java.lang.Object value, HierarchicalMap constraint, Schema schema, HierarchicalMap messages)
          Checks if the value matches one of the pattern listed inside constraints.
abstract  int compareTo(java.lang.Object o1, java.lang.Object o2)
          Abstract method for comparing two valid objects used for boundry check.
 java.lang.Object convert(java.lang.String name, java.lang.Object value, HierarchicalMap constraint, Schema schema, HierarchicalMap messages, int replace)
          Coverts a value to corresponding object depending on data type this Validator is written for.
static boolean hasFailed(java.lang.Object o)
          Checks if the object returned during validation resulted from not succeeded validation.
abstract  java.lang.Object newValue(java.lang.Object value)
          Creates a java instance of corresponding object depending on data type this Validator is written for.
abstract  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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FAIL

public static final Validator.ValidationFailed FAIL
Constructor Detail

Validator

public Validator()
Method Detail

validate

public abstract 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. 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.

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.

hasFailed

public static boolean hasFailed(java.lang.Object o)
Checks if the object returned during validation resulted from not succeeded validation.

Parameters:
o - object returned by validation method.
Returns:
true if the validation has failed.

appendMessage

public static void appendMessage(java.lang.String name,
                                 java.lang.String key,
                                 HierarchicalMap constraint,
                                 Schema schema,
                                 HierarchicalMap messages,
                                 java.lang.String defaultMessageComplement)
Appends an error message retrieving the error message from XML Schema Document, ResourceBundle or providing a default error message. It first checks for tag "text" inside constraint and try to retrieve as error message. If it has not succeeded, it checks for tag "reference" and try to load the corresponding error message from ResourceBundle. If still has not succeeded, it will provide a default error message if "useDefaultMessage" is set to true for the Schema.

Parameters:
name - name of schema component beeing validated.
key - value domain beeing checked. e.g. minInclusive
constraint - HierarchicalMap containing constraints.
schema - reference to Schema which is validating the current value.
messages - StringBuffer where the error messages are appended.
defaultMessageComplement - complement for error message.

checkNillable

public boolean checkNillable(java.lang.String name,
                             java.lang.Object value,
                             HierarchicalMap constraint,
                             Schema schema,
                             HierarchicalMap messages)
Checks if the value is null and if so, check if it is nillable. Empty Strings "" is also considered as null if the data type is not a String. The default value is used if defined.

Parameters:
name - name of schema component beeing validated.
value - value that is beeing validated.
constraint - HierarchicalMap containing constraints.
schema - reference to Schema which is validating the current value.
messages - StringBuffer where the error messages are appended.
Returns:
true if the value does not exceed boundaries.

checkBoundary

public boolean checkBoundary(java.lang.String name,
                             java.lang.Object value,
                             HierarchicalMap constraint,
                             Schema schema,
                             HierarchicalMap messages)
Checks if the value does not exceed minimun and maximun boundries.

Parameters:
name - name of schema component beeing validated.
value - value that is beeing validated.
constraint - HierarchicalMap containing constraints.
schema - reference to Schema which is validating the current value.
messages - StringBuffer where the error messages are appended.
Returns:
true if the value does not exceed boundaries.

checkEnumeration

public boolean checkEnumeration(java.lang.String name,
                                java.lang.Object value,
                                HierarchicalMap constraint,
                                Schema schema,
                                HierarchicalMap messages)
Checks if the value appear in the enumeration list inside constraints.

Parameters:
name - name of schema component beeing validated.
value - value that is beeing validated.
constraint - HierarchicalMap containing constraints.
schema - reference to Schema which is validating the current value.
messages - StringBuffer where the error messages are appended.
Returns:
true if value is a valid value in the enumerartion list.

checkPattern

public boolean checkPattern(java.lang.String name,
                            java.lang.Object value,
                            HierarchicalMap constraint,
                            Schema schema,
                            HierarchicalMap messages)
Checks if the value matches one of the pattern listed inside constraints.

Parameters:
name - name of schema component beeing validated.
value - value that is beeing validated.
constraint - HierarchicalMap containing constraints.
schema - reference to Schema which is validating the current value.
messages - StringBuffer where the error messages are appended.
Returns:
true if value is a valid value in the enumerartion list.

convert

public java.lang.Object convert(java.lang.String name,
                                java.lang.Object value,
                                HierarchicalMap constraint,
                                Schema schema,
                                HierarchicalMap messages,
                                int replace)
Coverts a value to corresponding object depending on data type this Validator is written for.

Parameters:
value - value to be converted to java object depending on data type.
constraint - HierarchicalMap containing constraints.
replace - replace method used for convertion.
Returns:
java object of corresponding data type.

compareTo

public abstract int compareTo(java.lang.Object o1,
                              java.lang.Object o2)
Abstract method for comparing two valid objects used for boundry check.

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 abstract java.lang.Object newValue(java.lang.Object value)
Creates a java instance of corresponding object depending on data type this Validator is written for.

Parameters:
value - value to be converted to java object depending on data type.
Returns:
java object of corresponding data type.