com.hp.hpl.jena.rdf.model
Interface Literal

All Superinterfaces:
RDFNode

public interface Literal
extends RDFNode

An RDF Literal.

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 primitve accessor methods duplicate the behvaiour 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.

Version:
$Name: $ $Revision: 1.8 $ $Date: 2003/06/17 12:25:04 $
Author:
bwm and der

Method Summary
 boolean equals(java.lang.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.
 java.lang.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.
 java.lang.String getLanguage()
          If a language is defined for this literal return it
 java.lang.String getLexicalForm()
          Return the lexical form of the literal.
 long getLong()
          If the literal is interpretable as a Long return its value.
 java.lang.Object getObject(ObjectF f)
          In the case of plain literals this recreates an object from its lexical form using the given factory.
 short getShort()
          If the literal is interpretable as a Short return its value.
 java.lang.String getString()
          If the literal is interpretable as a string return its value.
 java.lang.Object getValue()
          Return the value of the literal.
 boolean getWellFormed()
          Return whether Literal is well formed XML
 boolean isLiteral()
          Answer true.
 boolean sameValueAs(Literal other)
          Test that two literals are semantically equivalent.
 
Methods inherited from interface com.hp.hpl.jena.rdf.model.RDFNode
as, asNode, canAs, inModel, toString, visitWith
 

Method Detail

isLiteral

public boolean isLiteral()
Answer true.


getValue

public java.lang.Object getValue()
Return the value of the literal. In the case of plain literals this will return the literal string. In the case of typed literals it will return a java object representing the value. In the case of typed literals representing a java primitive then the appropriate java wrapper class (Integer etc) will be returned.


getDatatype

public RDFDatatype getDatatype()
Return the datatype of the literal. This will be null in the case of plain literals.


getDatatypeURI

public java.lang.String getDatatypeURI()
Return the uri of the datatype of the literal. This will be null in the case of plain literals.


getLexicalForm

public java.lang.String getLexicalForm()
Return the lexical form of the literal.


getBoolean

public boolean getBoolean()
If the literal is interpretable as a Boolean return its value as a boolean. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a boolean

getByte

public byte getByte()
If the literal is interpretable as a Byte return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a byte

getShort

public short getShort()
If the literal is interpretable as a Short return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a short

getInt

public int getInt()
If the literal is interpretable as a Integer return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as an int

getLong

public long getLong()
If the literal is interpretable as a Long return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a long

getChar

public char getChar()
If the literal is interpretable as a Char return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a char

getFloat

public float getFloat()
If the literal is interpretable as a Float return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a float

getDouble

public double getDouble()
If the literal is interpretable as a Double return its value. Plain literals are interpreted by parsing their lexical representation, typed literals are interpreted by coercion of the java object representing their value.

Returns:
the literal interpeted as a double

getString

public java.lang.String getString()
If the literal is interpretable as a string return its value. For typed literals this will throw an error for non string literals and one needs to use getLexicalForm to return the string form of other datatypes.

Returns:
the literal string

getObject

public java.lang.Object getObject(ObjectF f)
In the case of plain literals this recreates an object from its lexical form using the given factory. In the case of typed literals the factory is ignored and the value is returned instead.

Parameters:
f - A factory object for creating the returned object.
Returns:
the object created from the literal string

getLanguage

public java.lang.String getLanguage()
If a language is defined for this literal return it

Returns:
the language for this literal if it exists, or null

getWellFormed

public boolean getWellFormed()
Return whether Literal is well formed XML

Returns:
true if the literal is well formed XML, e.g. as would be produced from a parseType="Literal" element.

equals

public boolean equals(java.lang.Object o)
Test whether another object is equal to this object.

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.

Parameters:
o - The object to test against
Returns:
true if the the objects are equal, false otherwise

sameValueAs

public boolean sameValueAs(Literal other)
Test that two literals are semantically equivalent. In some cases this may be the sames as equals, in others equals is stricter. For example, two xsd:int literals with the same value but different language tag are semantically equivalent but distinguished by the java equality function in order to support round tripping.



Copyright © 2001-2003 Hewlett-Packard. All Rights Reserved.