Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

All Superinterfaces:
  FrontsNode, 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.16 $ $Date: 2008/01/02 12:05:46 $
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()` Deprecated. use isWellFormedXML instead.
`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.

Methods inherited from interface com.hp.hpl.jena.rdf.model.RDFNode
`as, canAs, inModel, isAnon, isLiteral, isResource, isURIResource, toString, visitWith`

Methods inherited from interface com.hp.hpl.jena.graph.FrontsNode
`asNode`

Method Detail

### getValue

    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

    RDFDatatype getDatatype()

  Return the datatype of the literal. This will be null in the case of plain literals.

### getDatatypeURI

    java.lang.String getDatatypeURI()

  Return the uri of the datatype of the literal. This will be null in the case of plain literals.

### getLexicalForm

    java.lang.String getLexicalForm()

  Return the lexical form of the literal.

### getBoolean

    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

    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

    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

    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

    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

    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

    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

    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

    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

    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

    java.lang.String getLanguage()

  If a language is defined for this literal return it

  Returns:
    the language for this literal if it exists, or empty string if none

### getWellFormed

    boolean getWellFormed()

  Deprecated. use isWellFormedXML instead.

  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.

### isWellFormedXML

    boolean isWellFormedXML()

  Answer true iff this literal is (or claims to be) well-formed XML.

### equals

    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.

  Overrides:
    `equals` in class `java.lang.Object`
  Parameters:
    `o` - The object to test against
  Returns:
    true if the the objects are equal, false otherwise

### sameValueAs

    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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP