com.sun.msv.grammar.trex
Class TypedString

java.lang.Object
  |
  +--com.sun.msv.grammar.trex.TypedString
All Implemented Interfaces:
DatabindableDatatype, Datatype, Serializable

public class TypedString
extends Object
implements DatabindableDatatype, Serializable

Datatype created by <string> element.

Author:
Kohsuke KAWAGUCHI
See Also:
Serialized Form

Field Summary
static String DIAG_TYPED_STRING
           
 boolean preserveWhiteSpace
          true indicates that whiteSpace should be preserved.
 String value
          this type only matches this string
 
Constructor Summary
TypedString(String value, boolean preserveWhiteSpace)
           
 
Method Summary
 void checkValid(String content, ValidationContext context)
          Similar to the isValid method but throws an exception with diagnosis in case of errors.
 String convertToLexicalValue(Object value, SerializationContext context)
           
 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 literal, ValidationContext context)
          Converts lexcial value and the current context to the corresponding value object.
 String displayName()
           
 Class getJavaObjectType()
          gets the type of the objects that are created by the createJavaObject method.
 String getName()
           
 boolean isValid(String literal, ValidationContext context)
          Checks if the specified 'literal' matchs this Datatype under the current context.
 boolean sameValue(Object o1, Object o2)
          Tests the equality of two value objects which was originally created by the createValue method of this object.
 String serializeJavaObject(Object obj, SerializationContext context)
          converts a value object back to the lexical representation.
 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
 

Field Detail

value

public final String value
this type only matches this string

preserveWhiteSpace

public final boolean preserveWhiteSpace
true indicates that whiteSpace should be preserved.

DIAG_TYPED_STRING

public static final String DIAG_TYPED_STRING
Constructor Detail

TypedString

public TypedString(String value,
                   boolean preserveWhiteSpace)
Method Detail

createValue

public Object createValue(String literal,
                          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.

createJavaObject

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

getJavaObjectType

public Class getJavaObjectType()
Description copied from interface: DatabindableDatatype
gets the type of the objects that are created by the createJavaObject method.
Specified by:
getJavaObjectType in interface DatabindableDatatype

convertToLexicalValue

public String convertToLexicalValue(Object value,
                                    SerializationContext context)

serializeJavaObject

public String serializeJavaObject(Object obj,
                                  SerializationContext context)
Description copied from interface: DatabindableDatatype
converts a value object back to the lexical representation.

This method is a kind of the "reverse" function of the createJavaObject method.

Specified by:
serializeJavaObject in interface DatabindableDatatype
Following copied from interface: com.sun.msv.datatype.DatabindableDatatype
Parameters:
context - The context object is used to obtain information necessary to serialize the value object. For example, QName type uses the context to encode the URI into a prefix.
Returns:
null if the given object is invalid with respect to this datatype.
Throws:
IllegalArgumentException - If the type of the specified value object is not recognized, this exception is thrown. For example, if you pass a String object to the serializeJavaObject method of the "positiveInteger" type, this exception is thrown.

isValid

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

checkValid

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

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.

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.

getName

public String getName()

displayName

public String displayName()