com.sun.msv.datatype.xsd
Class XSDatatypeImpl

java.lang.Object
  |
  +--com.sun.msv.datatype.xsd.XSDatatypeImpl
All Implemented Interfaces:
DatabindableDatatype, Datatype, Serializable, XSDatatype
Direct Known Subclasses:
ConcreteType, DataTypeWithFacet, FinalComponent

public abstract class XSDatatypeImpl
extends Object
implements XSDatatype

base implementaion for XSDatatype interface.

This class should be considered as the implementation-detail, and applications should not access this class.

Author:
Kohsuke KAWAGUCHI
See Also:
Serialized Form

Field Summary
static String ERR_DUPLICATE_FACET
           
static String ERR_EMPTY_UNION
           
static String ERR_ENUMERATION
           
static String ERR_ENUMERATION_WITH_ARG
           
static String ERR_FACET_MUST_BE_NON_NEGATIVE_INTEGER
           
static String ERR_FACET_MUST_BE_POSITIVE_INTEGER
           
static String ERR_INAPPROPRIATE_FOR_TYPE
           
static String ERR_INCONSISTENT_FACETS_1
           
static String ERR_INCONSISTENT_FACETS_2
           
static String ERR_INVALID_BASE_TYPE
           
static String ERR_INVALID_ITEMTYPE
           
static String ERR_INVALID_MEMBER_TYPE
           
static String ERR_INVALID_VALUE_FOR_THIS_TYPE
           
static String ERR_INVALID_WHITESPACE_VALUE
           
static String ERR_LENGTH
           
static String ERR_LOOSENED_FACET
           
static String ERR_MAXLENGTH
           
static String ERR_MINLENGTH
           
static String ERR_NOT_APPLICABLE_FACET
           
static String ERR_OUT_OF_RANGE
           
static String ERR_OVERRIDING_FIXED_FACET
           
static String ERR_PARSE_ERROR
           
static String ERR_PATTERN_1
           
static String ERR_PATTERN_MANY
           
static String ERR_SCALE_IS_GREATER_THAN_PRECISION
           
static String ERR_TOO_MUCH_PRECISION
           
static String ERR_TOO_MUCH_SCALE
           
static String ERR_X_AND_Y_ARE_EXCLUSIVE
           
 WhiteSpaceProcessor whiteSpace
          this field characterizes how this datatype treats white space.
 
Fields inherited from interface com.sun.msv.datatype.xsd.XSDatatype
APPLICABLE, DERIVATION_BY_LIST, DERIVATION_BY_RESTRICTION, DERIVATION_BY_UNION, FACET_ENUMERATION, FACET_FRACTIONDIGITS, FACET_LENGTH, FACET_MAXEXCLUSIVE, FACET_MAXINCLUSIVE, FACET_MAXLENGTH, FACET_MINEXCLUSIVE, FACET_MININCLUSIVE, FACET_MINLENGTH, FACET_PATTERN, FACET_TOTALDIGITS, FACET_WHITESPACE, FIXED, NOT_ALLOWED, VARIETY_ATOMIC, VARIETY_LIST, VARIETY_UNION
 
Method Summary
 void checkValid(String content, ValidationContext context)
          Similar to the isValid method but throws an exception with diagnosis in case of errors.
 Object createJavaObject(String literal, ValidationContext context)
          converts lexcial value to a corresponding Java-friendly object by using the given context information.
 DatatypeStreamingValidator createStreamingValidator(ValidationContext context)
          Creates an instance of the streaming validator for this type.
 Object createValue(String lexicalValue, ValidationContext context)
          Converts lexcial value and the current context to the corresponding value object.
abstract  ConcreteType getConcreteType()
          gets the concrete type object of the restriction chain.
 DataTypeWithFacet getFacetObject(String facetName)
          gets the facet object that restricts the specified facet
 String getName()
          gets the local name of the type.
 boolean isDerivedTypeOf(XSDatatype baseType, boolean restrictionAllowed)
          tests if this type is a derived type of the specified type.
static boolean isDerivedTypeOf(XSDatatype base, XSDatatype derived, boolean restrictionAllowed)
          an implementation of "Type Derivation OK (Simple)" of the spec.
 boolean isValid(String literal, ValidationContext context)
          Checks if the specified 'literal' matchs this Datatype under the current context.
static String localize(String prop)
           
static String localize(String prop, Object arg1)
           
static String localize(String prop, Object[] args)
           
static String localize(String prop, Object arg1, Object arg2)
           
static String localize(String prop, Object arg1, Object arg2, Object arg3)
           
 boolean sameValue(Object o1, Object o2)
          Tests the equality of two value objects which was originally created by the createValue method of this object.
 int valueHashCode(Object o)
          computes the hash code for a value object, which is consistent with the sameValue method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.msv.datatype.xsd.XSDatatype
convertToLexicalValue, displayName, getBaseType, getVariety, isFacetApplicable, isFinal
 
Methods inherited from interface com.sun.msv.datatype.DatabindableDatatype
getJavaObjectType, serializeJavaObject
 

Field Detail

whiteSpace

public final WhiteSpaceProcessor whiteSpace
this field characterizes how this datatype treats white space.

ERR_INAPPROPRIATE_FOR_TYPE

public static final String ERR_INAPPROPRIATE_FOR_TYPE

ERR_TOO_MUCH_PRECISION

public static final String ERR_TOO_MUCH_PRECISION

ERR_TOO_MUCH_SCALE

public static final String ERR_TOO_MUCH_SCALE

ERR_ENUMERATION

public static final String ERR_ENUMERATION

ERR_ENUMERATION_WITH_ARG

public static final String ERR_ENUMERATION_WITH_ARG

ERR_OUT_OF_RANGE

public static final String ERR_OUT_OF_RANGE

ERR_LENGTH

public static final String ERR_LENGTH

ERR_MINLENGTH

public static final String ERR_MINLENGTH

ERR_MAXLENGTH

public static final String ERR_MAXLENGTH

ERR_PATTERN_1

public static final String ERR_PATTERN_1

ERR_PATTERN_MANY

public static final String ERR_PATTERN_MANY

ERR_INVALID_ITEMTYPE

public static final String ERR_INVALID_ITEMTYPE

ERR_INVALID_MEMBER_TYPE

public static final String ERR_INVALID_MEMBER_TYPE

ERR_INVALID_BASE_TYPE

public static final String ERR_INVALID_BASE_TYPE

ERR_INVALID_WHITESPACE_VALUE

public static final String ERR_INVALID_WHITESPACE_VALUE

ERR_PARSE_ERROR

public static final String ERR_PARSE_ERROR

ERR_INVALID_VALUE_FOR_THIS_TYPE

public static final String ERR_INVALID_VALUE_FOR_THIS_TYPE

ERR_FACET_MUST_BE_NON_NEGATIVE_INTEGER

public static final String ERR_FACET_MUST_BE_NON_NEGATIVE_INTEGER

ERR_FACET_MUST_BE_POSITIVE_INTEGER

public static final String ERR_FACET_MUST_BE_POSITIVE_INTEGER

ERR_OVERRIDING_FIXED_FACET

public static final String ERR_OVERRIDING_FIXED_FACET

ERR_INCONSISTENT_FACETS_1

public static final String ERR_INCONSISTENT_FACETS_1

ERR_INCONSISTENT_FACETS_2

public static final String ERR_INCONSISTENT_FACETS_2

ERR_X_AND_Y_ARE_EXCLUSIVE

public static final String ERR_X_AND_Y_ARE_EXCLUSIVE

ERR_LOOSENED_FACET

public static final String ERR_LOOSENED_FACET

ERR_SCALE_IS_GREATER_THAN_PRECISION

public static final String ERR_SCALE_IS_GREATER_THAN_PRECISION

ERR_DUPLICATE_FACET

public static final String ERR_DUPLICATE_FACET

ERR_NOT_APPLICABLE_FACET

public static final String ERR_NOT_APPLICABLE_FACET

ERR_EMPTY_UNION

public static final String ERR_EMPTY_UNION
Method Detail

getName

public String getName()
Description copied from interface: XSDatatype
gets the local name of the type. If this type is an anonymous type, then this method returns null.

In the terminology of the spec, this method returns the name property of this simple type component. If the name property is absent, this method returns null.

Specified by:
getName in interface XSDatatype

createValue

public final Object createValue(String lexicalValue,
                                ValidationContext context)
Description copied from interface: Datatype
Converts lexcial value and the current context to the corresponding value object.

The caller cannot generally assume that the value object is a meaningful Java object. For example, the caller cannot expect this method to return java.lang.Number type for the "integer" type of XML Schema Part2.

Also, the caller cannot assume that the equals method and the hashCode method of the value object is consistent with the semantics of the datatype. For that purpose, the sameValue method and the valueHashCode method have to be used. Note that this means you cannot use classes like java.util.Hashtable to store the value objects.

The returned value object should be used solely for the sameValue method.

Specified by:
createValue in interface Datatype
Following copied from interface: org.relaxng.datatype.Datatype
Returns:
null when the given lexical value is not a valid lexical value for this type.

checkValid

public final void checkValid(String content,
                             ValidationContext context)
                      throws DatatypeException
Description copied from interface: Datatype
Similar to the isValid method but throws an exception with diagnosis in case of errors.

If the specified 'literal' is a valid lexical representation for this datatype, then this method must return without throwing any exception. If not, the callee must throw an exception (with diagnosis message, if possible.)

The application can use this method to provide detailed error message to users. This method is kept separate from the isValid method to achieve higher performance during normal validation.

Specified by:
checkValid in interface Datatype
Following copied from interface: org.relaxng.datatype.Datatype
Throws:
DatatypeException - If the given literal is invalid, then this exception is thrown. If the callee supports error diagnosis, then the exception should contain a diagnosis message.

createJavaObject

public final Object createJavaObject(String literal,
                                     ValidationContext context)
Description copied from interface: DatabindableDatatype
converts lexcial value to a corresponding Java-friendly object by using the given context information.

For the actual types returned by each type, see here.

Note that due to the difference between those Java friendly types and actual XML Schema specification, the returned object sometimes loses accuracy. For example, the "time" type allows "0.0000000000001 sec" which cannot be represented in java.util.Calendar class.

Specified by:
createJavaObject in interface DatabindableDatatype
Following copied from interface: com.sun.msv.datatype.DatabindableDatatype
Returns:
null when the given lexical value is not a valid lexical value for this type.

isValid

public final boolean isValid(String literal,
                             ValidationContext context)
Description copied from interface: Datatype
Checks if the specified 'literal' matchs this Datatype under the current context.
Specified by:
isValid in interface Datatype
Following copied from interface: org.relaxng.datatype.Datatype
Parameters:
literal - the lexical representation to be checked.
context - context information that may be necessary to validate the given literal.
Returns:
true if the 'literal' is a member of this Datatype; false if it's not a member of this Datatype.

createStreamingValidator

public DatatypeStreamingValidator createStreamingValidator(ValidationContext context)
Description copied from interface: Datatype
Creates an instance of the streaming validator for this type.

By using streaming validators instead of the isValid method, the caller can avoid keeping the entire string into the memory, which is sometimes quite big.

Specified by:
createStreamingValidator in interface Datatype
Following copied from interface: org.relaxng.datatype.Datatype
Parameters:
context - context information that may be necessary to validate the given literal. The callee may keep a reference to this context object only while the returned streaming validator is being used.
Throws:
UnsupportedOperationException - if the streaming validation is not supported by the callee.

getFacetObject

public DataTypeWithFacet getFacetObject(String facetName)
gets the facet object that restricts the specified facet
Specified by:
getFacetObject in interface XSDatatype
Returns:
null if no such facet object exists.

getConcreteType

public abstract ConcreteType getConcreteType()
gets the concrete type object of the restriction chain.

sameValue

public final boolean sameValue(Object o1,
                               Object o2)
Description copied from interface: Datatype
Tests the equality of two value objects which was originally created by the createValue method of this object. The bahavior is undefined if objects not created by this type is passed. It is the caller's responsibility to ensure that value objects belong to this type.
Specified by:
sameValue in interface Datatype
Following copied from interface: org.relaxng.datatype.Datatype
Returns:
true if two value objects are considered equal according to the definition of this datatype; false if otherwise.

valueHashCode

public final int valueHashCode(Object o)
Description copied from interface: Datatype
computes the hash code for a value object, which is consistent with the sameValue method.
Specified by:
valueHashCode in interface Datatype
Following copied from interface: org.relaxng.datatype.Datatype
Returns:
hash code for the specified value object.

isDerivedTypeOf

public final boolean isDerivedTypeOf(XSDatatype baseType,
                                     boolean restrictionAllowed)
Description copied from interface: XSDatatype
tests if this type is a derived type of the specified type.

This method is an implementation of "Type Derivation OK (Simple)" of the spec. Therefore use caution if what you want is a casual method because this method may cause a lot of unintuitive result.

Note to implementors Use the static version of this method defined in the XSDatatypeImpl class. You don't need to implement this method from scratch.

Specified by:
isDerivedTypeOf in interface XSDatatype
Following copied from interface: com.sun.msv.datatype.xsd.XSDatatype
Parameters:
restrictionAllowed - This test needs "a subset of {extension,restriction,list,union} (of which only restriction is actually relevant). If this flag is set to true, this method behaves as if the empty set is passed as the set. This is usually what you want if you're simply trying to check the derivation relationship.

If this flag is set to false, this method behaves as if {restriction} is passed as the set.


isDerivedTypeOf

public static boolean isDerivedTypeOf(XSDatatype base,
                                      XSDatatype derived,
                                      boolean restrictionAllowed)
an implementation of "Type Derivation OK (Simple)" of the spec.
See Also:
isDerivedTypeOf(XSDatatype,boolean)

localize

public static String localize(String prop,
                              Object[] args)

localize

public static String localize(String prop)

localize

public static String localize(String prop,
                              Object arg1)

localize

public static String localize(String prop,
                              Object arg1,
                              Object arg2)

localize

public static String localize(String prop,
                              Object arg1,
                              Object arg2,
                              Object arg3)