org.jrdf.graph
Class AbstractLiteral

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

public abstract class AbstractLiteral
extends Object
implements Literal, Serializable

A base implementation of an RDF Literal.

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

Constructor Summary
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 null for a plain 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.
 String getLexicalForm()
          Obtain the text of this literal.
 int hashCode()
          Returns a hash-code value for this 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
 

Constructor Detail

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
Method Detail

getLexicalForm

public String getLexicalForm()
Obtain the text of this literal.

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

getLanguage

public String getLanguage()
Returns the language code of the literal. When no language is specified for a plain literal, this field contains a zero-length String. Otherwise, this will be null.

Specified by:
getLanguage in interface Literal
Returns:
the language code of the literal or null in the case of a datatyped literal.

isWellFormedXML

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

Specified by:
isWellFormedXML in interface Literal
Returns:
whether the literal is wll formed XML.

getDatatypeURI

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

Specified by:
getDatatypeURI in interface Literal
Returns:
the URI of the RDF datatype of this resource, or null 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.

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

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

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
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.