Package org.apache.jena.datatypes
Class BaseDatatype
- java.lang.Object
-
- org.apache.jena.datatypes.BaseDatatype
-
- All Implemented Interfaces:
RDFDatatype
- Direct Known Subclasses:
AdhocDatatype
,FunctorDatatype
,RDFhtml
,RDFjson
,RDFLangString
,XMLLiteralType
,XSDDatatype
public class BaseDatatype extends java.lang.Object implements RDFDatatype
Base level implementation of datatype from which real implementations can inherit.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BaseDatatype.TypedValue
Pair object used to encode both lexical form and datatype for a typed literal with unknown datatype.
-
Constructor Summary
Constructors Constructor Description BaseDatatype(java.lang.String uri)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
cannonicalise(java.lang.Object value)
Cannonicalise a java Object value to a normal form.java.lang.Object
extendedTypeDefinition()
Returns an object giving more details on the datatype.int
getHashCode(LiteralLabel lit)
Default implementation of getHashCode() delegates to the default from the literal label.java.lang.Class<?>
getJavaClass()
Returns the java class which is used to represent value instances of this datatype.java.lang.String
getURI()
Return the URI which is the label for this datatypeboolean
isEqual(LiteralLabel litLabel1, LiteralLabel litLabel2)
Compares two instances of values of the given datatype.boolean
isValid(java.lang.String lexicalForm)
Test whether the given string is a legal lexical form of this datatype.boolean
isValidLiteral(LiteralLabel lit)
Test whether the given LiteralLabel is a valid instance of this datatype.boolean
isValidValue(java.lang.Object valueForm)
Test whether the given object is a legal value form of this datatype.boolean
langTagCompatible(LiteralLabel value1, LiteralLabel value2)
Helper function to compare language tag valuesRDFDatatype
normalizeSubType(java.lang.Object value, RDFDatatype dt)
Normalization.java.lang.Object
parse(java.lang.String lexicalForm)
Parse a lexical form of this datatype to a valuejava.lang.String
toString()
Display formatjava.lang.String
unparse(java.lang.Object value)
Convert a value of this datatype out to lexical form.
-
-
-
Method Detail
-
getURI
public java.lang.String getURI()
Return the URI which is the label for this datatype- Specified by:
getURI
in interfaceRDFDatatype
-
unparse
public java.lang.String unparse(java.lang.Object value)
Convert a value of this datatype out to lexical form.- Specified by:
unparse
in interfaceRDFDatatype
-
parse
public java.lang.Object parse(java.lang.String lexicalForm) throws DatatypeFormatException
Parse a lexical form of this datatype to a value- Specified by:
parse
in interfaceRDFDatatype
- Throws:
DatatypeFormatException
- if the lexical form is not legal
-
isValid
public boolean isValid(java.lang.String lexicalForm)
Test whether the given string is a legal lexical form of this datatype.- Specified by:
isValid
in interfaceRDFDatatype
-
isValidLiteral
public boolean isValidLiteral(LiteralLabel lit)
Test whether the given LiteralLabel is a valid instance of this datatype. This takes into account 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 interfaceRDFDatatype
-
isValidValue
public boolean isValidValue(java.lang.Object valueForm)
Test whether the given object is a legal value form of this datatype.- Specified by:
isValidValue
in interfaceRDFDatatype
-
isEqual
public boolean isEqual(LiteralLabel litLabel1, LiteralLabel litLabel2)
Compares two instances of values of the given datatype. This default requires value and datatype equality.- Specified by:
isEqual
in interfaceRDFDatatype
-
getHashCode
public int getHashCode(LiteralLabel lit)
Default implementation of getHashCode() delegates to the default from the literal label.- Specified by:
getHashCode
in interfaceRDFDatatype
-
langTagCompatible
public boolean langTagCompatible(LiteralLabel value1, LiteralLabel value2)
Helper function to compare language tag values
-
getJavaClass
public java.lang.Class<?> getJavaClass()
Returns the java class which is used to represent value instances of this datatype.- Specified by:
getJavaClass
in interfaceRDFDatatype
-
cannonicalise
public java.lang.Object cannonicalise(java.lang.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 interfaceRDFDatatype
-
extendedTypeDefinition
public java.lang.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 oforg.apache.xerces.impl.xs.psvi.XSTypeDefinition
.- Specified by:
extendedTypeDefinition
in interfaceRDFDatatype
-
normalizeSubType
public RDFDatatype normalizeSubType(java.lang.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 interfaceRDFDatatype
- Parameters:
value
- the current object valuedt
- the currently set data type- Returns:
- a narrower version of the datatype based on the actual value range
-
toString
public java.lang.String toString()
Display format- Overrides:
toString
in classjava.lang.Object
-
-