public interface Literal extends RDFNode
In RDF2003 literals can be typed. If typed then the literal comprises a datatype, a lexical form and a value (together with an optional xml:lang string). Old style literals have no type and are termed "plain" literals.
Implementations of this interface should be able to support both plain and typed literals. In the case of typed literals the primitive accessor methods such as getInt() determine if the literal value can be coerced to an appropriate java wrapper class. If so then the class is unwrapped to extract the primitive value returned. If the coercion fails then a runtime DatatypeFormatException is thrown.
In the case of plain literals then the primitive accessor methods duplicate the behaviour of jena1. The literal is internally stored in lexical form but the accessor methods such as getInt will attempt to parse the lexical form and if successful will return the primitive value.
Object (i.e. non-primitive) values are supported. In the case of typed literals
then a global TypeMapper registry determines what datatype representation to
use for a given Object type. In the case of plain literals then the object
will be stored in the lexical form given by its toString
method.
Factory objects, provided by the application, are needed in that case to covert
the lexical form back into the appropriate object type.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Test whether another object is equal to this object.
|
boolean |
getBoolean()
If the literal is interpretable as a Boolean return its value
as a boolean.
|
byte |
getByte()
If the literal is interpretable as a Byte return its value.
|
char |
getChar()
If the literal is interpretable as a Char return its value.
|
RDFDatatype |
getDatatype()
Return the datatype of the literal.
|
String |
getDatatypeURI()
Return the uri of the datatype of the literal.
|
double |
getDouble()
If the literal is interpretable as a Double return its value.
|
float |
getFloat()
If the literal is interpretable as a Float return its value.
|
int |
getInt()
If the literal is interpretable as a Integer return its value.
|
String |
getLanguage()
If a language is defined for this literal return it
|
String |
getLexicalForm()
Return the lexical form of the literal.
|
long |
getLong()
If the literal is interpretable as a Long return its value.
|
short |
getShort()
If the literal is interpretable as a Short return its value.
|
String |
getString()
If the literal is interpretable as a string return its value.
|
Object |
getValue()
Return the value of the literal.
|
Literal |
inModel(Model m)
Answer a version of this literal in the model m.
|
boolean |
isWellFormedXML()
Answer true iff this literal is (or claims to be) well-formed XML.
|
boolean |
sameValueAs(Literal other)
Test that two literals are semantically equivalent.
|
as, asLiteral, asResource, canAs, getModel, isAnon, isLiteral, isResource, isURIResource, toString, visitWith
asNode
Literal inModel(Model m)
Object getValue()
RDFDatatype getDatatype()
String getDatatypeURI()
String getLexicalForm()
boolean getBoolean()
byte getByte()
short getShort()
int getInt()
long getLong()
char getChar()
float getFloat()
double getDouble()
String getString()
String getLanguage()
boolean isWellFormedXML()
boolean equals(Object o)
A plain Literal is equal to another object only if the object is also a plain Literal and the string value and language of both literals are equal. In the case of a typed literal equality is defined by the datatype equality function on the value spaces and may or may not include comparison of the lang strings.
boolean sameValueAs(Literal other)
Licenced under the Apache License, Version 2.0