org.jrdf.graph
Class AbstractLiteral

java.lang.Object
  extended by org.jrdf.graph.AbstractLiteral
All Implemented Interfaces:
Serializable, Literal, Node, ObjectNode, TypedNodeVisitable, Value
Direct Known Subclasses:
LiteralImpl, LiteralImpl

public abstract class AbstractLiteral
extends Object
implements Literal, Serializable

A base implementation of an RDF Literal.

Version:
$Revision: 1822 $
Author:
Andrew Newman, Simon Raboczi
See Also:
Serialized Form

Field Summary
protected  URI datatypeURI
          RDF datatype URI, NullURI for untyped literal.
protected  String language
          The language code of the literal.
protected  DatatypeValue value
          The lexical form of the literal.
 
Constructor Summary
protected AbstractLiteral()
           
protected AbstractLiteral(Object newObject)
          Construct a datatype literal based on an existing Java class.
protected AbstractLiteral(String newLexicalForm)
          Construct a plain literal.
protected AbstractLiteral(String newLexicalForm, String newLanguage)
          Construct a literal with language.
protected AbstractLiteral(String newLexicalForm, URI newDatatypeURI)
          Construct a datatyped literal.
 
Method Summary
 void accept(TypedNodeVisitor visitor)
          Accept a call from a TypedNodeVisitor.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one.
 URI getDatatypeURI()
          Returns the URI of the RDF datatype of this resource, or NO_DATATYPE for a plain literal.
 DatatypeValue getDatatypeValue()
          Obtain the data type representation of this literal.
 String getEscapedForm()
          Provide a legible representation of a literal, following the N-Triples format defined in §3.2 of the W3C's RDF Test Cases Recommendation.
 String getEscapedLexicalForm()
          Returns an escaped lexical form where double quotes and backslashes are escaped.
 String getLanguage()
          Returns the language code of the literal, or "" if no language specified.
 String getLexicalForm()
          Obtain the text of this literal.
 Object getValue()
          Obtain a Java native representation of the datatype.
 int hashCode()
          Returns a hash-code value for this literal.
 boolean isDatatypedLiteral()
          Returns true if the literal is a datatype literal.
 boolean isLanguageLiteral()
          Returns true if the literal is a language literal.
 boolean isPlainLiteral()
          Returns true if the literal is a untyped/plain literal.
 boolean isWellFormedXML()
          Whether the literal is well formed XML.
 String toString()
          Returns the lexical form.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

protected DatatypeValue value
The lexical form of the literal.


language

protected String language
The language code of the literal.


datatypeURI

protected URI datatypeURI
RDF datatype URI, NullURI for untyped literal.

Constructor Detail

AbstractLiteral

protected AbstractLiteral()

AbstractLiteral

protected AbstractLiteral(String newLexicalForm)
Construct a plain literal.

Parameters:
newLexicalForm - the text part of the literal
Throws:
IllegalArgumentException - if newLexicalForm is null

AbstractLiteral

protected AbstractLiteral(String newLexicalForm,
                          String newLanguage)
Construct a literal with language.

Parameters:
newLexicalForm - the text part of the literal
newLanguage - the language code, possibly the empty string but not null
Throws:
IllegalArgumentException - if lexicalForm or lang are null

AbstractLiteral

protected AbstractLiteral(String newLexicalForm,
                          URI newDatatypeURI)
Construct a datatyped literal.

Parameters:
newLexicalForm - the text part of the literal
newDatatypeURI - the URI for a datatyped literal
Throws:
IllegalArgumentException - if lexicalForm or datatype are null

AbstractLiteral

protected AbstractLiteral(Object newObject)
Construct a datatype literal based on an existing Java class.

Parameters:
newObject - the object to use to construct the literal from. Uses a map of registered classes to creator objects.
Throws:
IllegalArgumentException - if the class is not registered to convert to a datatype.
Method Detail

getLexicalForm

public String getLexicalForm()
Description copied from interface: Value
Obtain the text of this literal.

Specified by:
getLexicalForm in interface Value
Returns:
the text of the literal, never null

getValue

public Object getValue()
Description copied from interface: Literal
Obtain a Java native representation of the datatype.

Specified by:
getValue in interface Literal
Specified by:
getValue in interface Value
Returns:
a Java native representation of the datatype.

getDatatypeValue

public DatatypeValue getDatatypeValue()
Description copied from interface: Literal
Obtain the data type representation of this literal.

Specified by:
getDatatypeValue in interface Literal
Returns:
the value object (data type) of this literal.

getLanguage

public String getLanguage()
Description copied from interface: Literal
Returns the language code of the literal, or "" if no language specified.

Specified by:
getLanguage in interface Literal
Returns:
the language code of the literal, or "" if no language specified.

isDatatypedLiteral

public boolean isDatatypedLiteral()
Description copied from interface: Literal
Returns true if the literal is a datatype literal.

Specified by:
isDatatypedLiteral in interface Literal
Returns:
true if the literal is a datatype literal.

isLanguageLiteral

public boolean isLanguageLiteral()
Description copied from interface: Literal
Returns true if the literal is a language literal.

Specified by:
isLanguageLiteral in interface Literal
Returns:
true if the literal is a language literal.

isPlainLiteral

public boolean isPlainLiteral()
Description copied from interface: Literal
Returns true if the literal is a untyped/plain literal.

Specified by:
isPlainLiteral in interface Literal
Returns:
true if the literal is a untyped/plain literal.

isWellFormedXML

public boolean isWellFormedXML()
Whether the literal is well formed XML.

Specified by:
isWellFormedXML in interface Value
Returns:
whether the literal is well formed XML.

getDatatypeURI

public URI getDatatypeURI()
Returns the URI of the RDF datatype of this resource, or NO_DATATYPE for a plain literal.

Specified by:
getDatatypeURI in interface Literal
Returns:
the URI of the RDF datatype of this resource, or NO_DATATYPE for a plain literal.

accept

public void accept(TypedNodeVisitor visitor)
Accept a call from a TypedNodeVisitor.

Specified by:
accept in interface TypedNodeVisitable
Parameters:
visitor - the object doing the visiting.

hashCode

public int hashCode()
Description copied from interface: Literal
Returns a hash-code value for this literal. The hash code is based upon XORing all of the literal's components hash codes including the lexical form, datatype, and language.

Specified by:
hashCode in interface Literal
Overrides:
hashCode in class Object
Returns:
a hash-code value for this literal.

equals

public boolean equals(Object obj)
Description copied from interface: Literal
Indicates whether some other object is "equal to" this one.

A literal is equal to another literal if:

Specified by:
equals in interface Literal
Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

getEscapedForm

public String getEscapedForm()
Provide a legible representation of a literal, following the N-Triples format defined in §3.2 of the W3C's RDF Test Cases Recommendation.

Well-formed Unicode surrogate pairs in the lexical form are escaped as a single 8-digit hexadecimal \U escape sequence rather than a pair of 4-digit &x5C;u sequences representing the surrogates.

Specified by:
getEscapedForm in interface Literal
Returns:
this instance in N-Triples format

toString

public String toString()
Returns the lexical form.

Specified by:
toString in interface Literal
Overrides:
toString in class Object
Returns:
the lexical form.

getEscapedLexicalForm

public String getEscapedLexicalForm()
Description copied from interface: Literal
Returns an escaped lexical form where double quotes and backslashes are escaped.

Specified by:
getEscapedLexicalForm in interface Literal
Returns:
String the lexical form.