org.whattf.datatype
Class AbstractDatatype

java.lang.Object
  extended by org.whattf.datatype.AbstractDatatype
All Implemented Interfaces:
Datatype
Direct Known Subclasses:
AbstractDatetime, Id, Idrefs, IriRef, Language, Month, Pattern, Ratio, Week

abstract class AbstractDatatype
extends Object
implements Datatype

Common superclass for HTML5 datatypes. Implements all methods of the Datatype interface and leaves a new checkValid for subclasses to implement.

Version:
$Id: AbstractDatatype.java,v 1.7 2006/11/26 14:22:54 hsivonen Exp $
Author:
hsivonen

Field Summary
private static int CASE_MASK
          Mask for ASCII case folding.
 
Fields inherited from interface org.relaxng.datatype.Datatype
ID_TYPE_ID, ID_TYPE_IDREF, ID_TYPE_IDREFS, ID_TYPE_NULL
 
Constructor Summary
AbstractDatatype()
          Constructor
 
Method Summary
abstract  void checkValid(CharSequence literal)
           
 void checkValid(String literal, ValidationContext context)
          Delegates to checkValid(CharSequence literal).
 DatatypeStreamingValidator createStreamingValidator(ValidationContext context)
          Merely returns a DatatypeStreamingValidatorImpl.
 Object createValue(String literal, ValidationContext context)
          Implements strict string equality semantics by returning literal itself.
 int getIdType()
          Always returns Datatype.ID_TYPE_NULL.
 boolean isContextDependent()
          Always returns false
 boolean isValid(String literal, ValidationContext context)
          Calls checkValid(CharSequence literal).
protected  boolean isWhitespace(char c)
          Checks if a UTF-16 code unit represents a whitespace character (U+0020, U+0009, U+000D or U+000A).
 boolean sameValue(Object value1, Object value2)
          Implements strict stirng equality semantics by performing a standard equals check on the arguments.
protected  char toAsciiLowerCase(char c)
          If the argument is an upper case ASCII letter, returns the letter in lower case.
protected  String toAsciiLowerCase(String str)
           
 int valueHashCode(Object value)
          Implements strict stirng equality semantics by returning the java.lang.Object-level hashCode of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CASE_MASK

private static final int CASE_MASK
Mask for ASCII case folding.

See Also:
Constant Field Values
Constructor Detail

AbstractDatatype

AbstractDatatype()
Constructor

Method Detail

isValid

public final boolean isValid(String literal,
                             ValidationContext context)
Calls checkValid(CharSequence literal).

Specified by:
isValid in interface Datatype
Parameters:
literal - the value
context - the validation context (ignored by subclasses)
Returns:
true if valid and false if not
See Also:
Datatype.isValid(java.lang.String, org.relaxng.datatype.ValidationContext)

checkValid

public final void checkValid(String literal,
                             ValidationContext context)
                      throws DatatypeException
Delegates to checkValid(CharSequence literal).

Specified by:
checkValid in interface Datatype
Parameters:
literal - the value
context - the validation context (ignored by subclasses)
Throws:
DatatypeException - if the literal does not conform to the datatype definition
See Also:
Datatype.checkValid(java.lang.String, org.relaxng.datatype.ValidationContext)

checkValid

public abstract void checkValid(CharSequence literal)
                         throws DatatypeException
Throws:
DatatypeException

createStreamingValidator

public DatatypeStreamingValidator createStreamingValidator(ValidationContext context)
Merely returns a DatatypeStreamingValidatorImpl.

Specified by:
createStreamingValidator in interface Datatype
Parameters:
context - the validation context (ignored by subclasses)
Returns:
An unoptimized DatatypeStreamingValidator
See Also:
Datatype.createStreamingValidator(org.relaxng.datatype.ValidationContext)

createValue

public final Object createValue(String literal,
                                ValidationContext context)
Implements strict string equality semantics by returning literal itself.

Specified by:
createValue in interface Datatype
Parameters:
literal - the value (get returned)
context - ignored
Returns:
the literal that was passed in
See Also:
Datatype.createValue(java.lang.String, org.relaxng.datatype.ValidationContext)

sameValue

public final boolean sameValue(Object value1,
                               Object value2)
Implements strict stirng equality semantics by performing a standard equals check on the arguments.

Specified by:
sameValue in interface Datatype
Parameters:
value1 - an object returned by createValue
value2 - another object returned by createValue
Returns:
true if the values are equal, false otherwise
See Also:
Datatype.sameValue(java.lang.Object, java.lang.Object)

valueHashCode

public final int valueHashCode(Object value)
Implements strict stirng equality semantics by returning the java.lang.Object-level hashCode of the object.

Specified by:
valueHashCode in interface Datatype
Parameters:
value - an object returned by createValue
Returns:
the hash code
See Also:
Datatype.valueHashCode(java.lang.Object)

getIdType

public int getIdType()
Always returns Datatype.ID_TYPE_NULL. (Overridden by subclasses that have a different ID-type.)

Specified by:
getIdType in interface Datatype
Returns:
Datatype.ID_TYPE_NULL
See Also:
Datatype.getIdType()

isContextDependent

public final boolean isContextDependent()
Always returns false

Specified by:
isContextDependent in interface Datatype
Returns:
false
See Also:
Datatype.isContextDependent()

isWhitespace

protected final boolean isWhitespace(char c)
Checks if a UTF-16 code unit represents a whitespace character (U+0020, U+0009, U+000D or U+000A).

Parameters:
c - the code unit
Returns:
true if whitespace, false otherwise

toAsciiLowerCase

protected final char toAsciiLowerCase(char c)
If the argument is an upper case ASCII letter, returns the letter in lower case. Otherwise returns the argument.

Parameters:
c - a UTF-16 code unit
Returns:
upper case ASCII lower cased

toAsciiLowerCase

protected final String toAsciiLowerCase(String str)