com.hp.hpl.jena.datatypes
Class BaseDatatype

java.lang.Object
  extended by com.hp.hpl.jena.datatypes.BaseDatatype
All Implemented Interfaces:
RDFDatatype
Direct Known Subclasses:
Functor.FunctorDatatype, XSDDatatype

public class BaseDatatype
extends Object
implements RDFDatatype

Base level implementation of datatype from which real implementations can inherit.

Version:
$Revision: 1.1 $ on $Date: 2009-06-29 08:55:50 $
Author:
Dave Reynolds

Nested Class Summary
static class BaseDatatype.TypedValue
          Pair object used to encode both lexical form and datatype for a typed literal with unknown datatype.
 
Constructor Summary
BaseDatatype(String uri)
          Constructor.
 
Method Summary
 Object cannonicalise(Object value)
          Cannonicalise a java Object value to a normal form.
 Object extendedTypeDefinition()
          Returns an object giving more details on the datatype.
 int getHashCode(com.hp.hpl.jena.graph.impl.LiteralLabel lit)
          Default implementation of getHashCode() delegates to the default from the literal label.
 Class<?> getJavaClass()
          Returns the java class which is used to represent value instances of this datatype.
 String getURI()
          Return the URI which is the label for this datatype
 boolean isEqual(com.hp.hpl.jena.graph.impl.LiteralLabel litLabel1, com.hp.hpl.jena.graph.impl.LiteralLabel litLabel2)
          Compares two instances of values of the given datatype.
 boolean isValid(String lexicalForm)
          Test whether the given string is a legal lexical form of this datatype.
 boolean isValidLiteral(com.hp.hpl.jena.graph.impl.LiteralLabel lit)
          Test whether the given LiteralLabel is a valid instance of this datatype.
 boolean isValidValue(Object valueForm)
          Test whether the given object is a legal value form of this datatype.
 boolean langTagCompatible(com.hp.hpl.jena.graph.impl.LiteralLabel value1, com.hp.hpl.jena.graph.impl.LiteralLabel value2)
          Helper function to compare language tag values
 RDFDatatype normalizeSubType(Object value, RDFDatatype dt)
          Normalization.
 Object parse(String lexicalForm)
          Parse a lexical form of this datatype to a value
 String toString()
          Display format
 String unparse(Object value)
          Convert a value of this datatype out to lexical form.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseDatatype

public BaseDatatype(String uri)
Constructor.

Parameters:
uri - the URI label to use for this datatype
Method Detail

getURI

public String getURI()
Return the URI which is the label for this datatype

Specified by:
getURI in interface RDFDatatype

unparse

public String unparse(Object value)
Convert a value of this datatype out to lexical form.

Specified by:
unparse in interface RDFDatatype

parse

public Object parse(String lexicalForm)
             throws DatatypeFormatException
Parse a lexical form of this datatype to a value

Specified by:
parse in interface RDFDatatype
Throws:
DatatypeFormatException - if the lexical form is not legal

isValid

public boolean isValid(String lexicalForm)
Test whether the given string is a legal lexical form of this datatype.

Specified by:
isValid in interface RDFDatatype

isValidLiteral

public boolean isValidLiteral(com.hp.hpl.jena.graph.impl.LiteralLabel lit)
Test whether the given LiteralLabel is a valid instance of this datatype. This takes into accound typing information as well as lexical form - for example an xsd:string is never considered valid as an xsd:integer (even if it is lexically legal like "1").

Specified by:
isValidLiteral in interface RDFDatatype

isValidValue

public boolean isValidValue(Object valueForm)
Test whether the given object is a legal value form of this datatype.

Specified by:
isValidValue in interface RDFDatatype

isEqual

public boolean isEqual(com.hp.hpl.jena.graph.impl.LiteralLabel litLabel1,
                       com.hp.hpl.jena.graph.impl.LiteralLabel litLabel2)
Compares two instances of values of the given datatype. This default requires value and datatype equality.

Specified by:
isEqual in interface RDFDatatype

getHashCode

public int getHashCode(com.hp.hpl.jena.graph.impl.LiteralLabel lit)
Default implementation of getHashCode() delegates to the default from the literal label.

Specified by:
getHashCode in interface RDFDatatype

langTagCompatible

public boolean langTagCompatible(com.hp.hpl.jena.graph.impl.LiteralLabel value1,
                                 com.hp.hpl.jena.graph.impl.LiteralLabel value2)
Helper function to compare language tag values


getJavaClass

public Class<?> getJavaClass()
Returns the java class which is used to represent value instances of this datatype.

Specified by:
getJavaClass in interface RDFDatatype

cannonicalise

public Object cannonicalise(Object value)
Cannonicalise a java Object value to a normal form. Primarily used in cases such as xsd:integer to reduce the Java object representation to the narrowest of the Number subclasses to ensure that indexing of typed literals works.

Specified by:
cannonicalise in interface RDFDatatype

extendedTypeDefinition

public Object extendedTypeDefinition()
Returns an object giving more details on the datatype. This is type system dependent. In the case of XSD types this will be an instance of org.apache.xerces.impl.xs.psvi.XSTypeDefinition.

Specified by:
extendedTypeDefinition in interface RDFDatatype

normalizeSubType

public RDFDatatype normalizeSubType(Object value,
                                    RDFDatatype dt)
Normalization. If the value is narrower than the current data type (e.g. value is xsd:date but the time is xsd:datetime) returns the narrower type for the literal. If the type is narrower than the value then it may normalize the value (e.g. set the mask of an XSDDateTime) Currently only used to narrow gener XSDDateTime objects to the minimal XSD date/time type.

Specified by:
normalizeSubType in interface RDFDatatype
Parameters:
value - the current object value
dt - the currently set data type
Returns:
a narrower version of the datatype based on the actual value range

toString

public String toString()
Display format

Overrides:
toString in class Object


Licenced under the Apache License, Version 2.0