com.hp.hpl.jena.graph
Class Node

java.lang.Object
  extended by com.hp.hpl.jena.graph.Node
Direct Known Subclasses:
Node_Concrete, Node_Fluid

public abstract class Node
extends java.lang.Object

A Node has five subtypes: Node_Blank, Node_Anon, Node_URI, Node_Variable, and Node_ANY. Nodes are only constructed by the node factory methods, and they will attempt to re-use existing nodes with the same label if they are recent enough.

Author:
Jeremy Carroll and Chris Dollin

Nested Class Summary
static class Node.NotLiteral
          Exception thrown if a literal-access operation is attemted on a non-literal node.
 
Field Summary
static Node ANY
          The canonical instance of Node_ANY.
static Node NULL
          The canonical NULL.
 
Method Summary
static void cache(boolean wantCache)
          provided only for testing purposes.
static Node create(com.hp.hpl.jena.graph.Node.NodeMaker maker, java.lang.Object label)
          We object strongly to null labels: for example, they make .equals flaky.
static Node createAnon()
          make a blank node with a fresh anon id
static Node createAnon(AnonId id)
          make a blank node with the specified label
static Node createLiteral(com.hp.hpl.jena.graph.impl.LiteralLabel lit)
          make a literal node with the specified literal value
static Node createLiteral(java.lang.String value)
           
static Node createLiteral(java.lang.String lit, java.lang.String lang, boolean isXml)
          make a literal with specified language and XMLishness.
static Node createLiteral(java.lang.String lex, java.lang.String lang, RDFDatatype dtype)
          Build a typed literal node from its lexical form.
static Node createUncachedLiteral(java.lang.Object value, java.lang.String lang, RDFDatatype dtype)
           
static Node createURI(java.lang.String uri)
          make a URI node with the specified URIref string
static Node createVariable(java.lang.String name)
          make a variable node with a given name
abstract  boolean equals(java.lang.Object o)
          Nodes only equal other Nodes that have equal labels.
 AnonId getBlankNodeId()
          get the blank node id if the node is blank, otherwise die horribly
 java.lang.String getBlankNodeLabel()
          Answer the label of this blank node or throw an UnsupportedOperationException if it's not blank.
 java.lang.Object getIndexingValue()
          Answer the object which is the index value for this Node.
 com.hp.hpl.jena.graph.impl.LiteralLabel getLiteral()
          Answer the literal value of a literal node, or throw an UnsupportedOperationException if it's not a literal node
 RDFDatatype getLiteralDatatype()
          Answer the RDF datatype object of this node's literal value, if it is a literal; otherwise die horribly.
 java.lang.String getLiteralDatatypeURI()
          Answer the data-type URI of this node's literal value, if it is a literal; otherwise die horribly.
 boolean getLiteralIsXML()
           
 java.lang.String getLiteralLanguage()
          Answer the language of this node's literal value, if it is a literal; otherwise die horribly.
 java.lang.String getLiteralLexicalForm()
          Answer the lexical form of this node's literal value, if it is a literal; otherwise die horribly.
 java.lang.Object getLiteralValue()
          Answer the value of this node's literal value, if it is a literal; otherwise die horribly.
 java.lang.String getLocalName()
          get the localname part of this node if it's a URI node, else die horribly
 java.lang.String getName()
          get a variable nodes name, otherwise die horribly
 java.lang.String getNameSpace()
          get the namespace part of this node if it's a URI node, else die horribly
static RDFDatatype getType(java.lang.String s)
           
 java.lang.String getURI()
          get the URI of this node if it has one, else die horribly
 int hashCode()
           
 boolean hasURI(java.lang.String uri)
          answer true iff this node is a URI node with the given URI
 boolean isBlank()
          Answer true iff this node is a blank node [subclasses override]
abstract  boolean isConcrete()
          Answer true iff this node is concrete, ie not variable, ie URI, blank, or literal.
 boolean isLiteral()
          Answer true iff this node is a literal node [subclasses override]
 boolean isURI()
          Answer true iff this node is a URI node [subclasses override]
 boolean isVariable()
          Answer true iff this node is a variable node - subclasses override
 boolean matches(Node other)
          Answer true iff this node accepts the other one as a match.
 boolean sameValueAs(java.lang.Object o)
          Test that two nodes are semantically equivalent.
 java.lang.String toString()
          Answer a human-readable representation of this Node.
 java.lang.String toString(boolean quoting)
          Answer a human-readable representation of this Node where literals are quoted according to quoting but URIs are not compressed.
 java.lang.String toString(PrefixMapping pm)
          Answer a human-readable representation of the Node, quoting literals and compressing URIs.
 java.lang.String toString(PrefixMapping pm, boolean quoting)
          Answer a human readable representation of this Node, quoting literals if specified, and compressing URIs using the prefix mapping supplied.
abstract  java.lang.Object visitWith(NodeVisitor v)
          Visit a Node and dispatch on it to the appropriate method from the NodeVisitor v.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY

public static final Node ANY
The canonical instance of Node_ANY. No other instances are required.


NULL

public static final Node NULL
The canonical NULL. It appears here so that revised definitions [eg as a bnode] that require the cache-and-maker system will work; the NodeMaker constants should be non-null at this point.

Method Detail

getType

public static RDFDatatype getType(java.lang.String s)

createAnon

public static Node createAnon()
make a blank node with a fresh anon id


createAnon

public static Node createAnon(AnonId id)
make a blank node with the specified label


createLiteral

public static Node createLiteral(com.hp.hpl.jena.graph.impl.LiteralLabel lit)
make a literal node with the specified literal value


createURI

public static Node createURI(java.lang.String uri)
make a URI node with the specified URIref string


createVariable

public static Node createVariable(java.lang.String name)
make a variable node with a given name


createLiteral

public static Node createLiteral(java.lang.String value)

createLiteral

public static Node createLiteral(java.lang.String lit,
                                 java.lang.String lang,
                                 boolean isXml)
make a literal with specified language and XMLishness. _lit_ must *not* be null.

Parameters:
isXml - If true then lit is exclusive canonical XML of type rdf:XMLLiteral, and no checking will be invoked.

createLiteral

public static Node createLiteral(java.lang.String lex,
                                 java.lang.String lang,
                                 RDFDatatype dtype)
                          throws DatatypeFormatException
Build a typed literal node from its lexical form. The lexical form will be parsed now and the value stored. If the form is not legal this will throw an exception.

Parameters:
lex - the lexical form of the literal
lang - the optional language tag
dtype - the type of the literal, null for old style "plain" literals
Throws:
DatatypeFormatException - if lex is not a legal form of dtype

createUncachedLiteral

public static Node createUncachedLiteral(java.lang.Object value,
                                         java.lang.String lang,
                                         RDFDatatype dtype)
                                  throws DatatypeFormatException
Throws:
DatatypeFormatException

visitWith

public abstract java.lang.Object visitWith(NodeVisitor v)
Visit a Node and dispatch on it to the appropriate method from the NodeVisitor v.

Parameters:
v - the visitor to apply to the node
Returns:
the value returned by the applied method

isConcrete

public abstract boolean isConcrete()
Answer true iff this node is concrete, ie not variable, ie URI, blank, or literal.


isLiteral

public boolean isLiteral()
Answer true iff this node is a literal node [subclasses override]


isBlank

public boolean isBlank()
Answer true iff this node is a blank node [subclasses override]


isURI

public boolean isURI()
Answer true iff this node is a URI node [subclasses override]


isVariable

public boolean isVariable()
Answer true iff this node is a variable node - subclasses override


getBlankNodeId

public AnonId getBlankNodeId()
get the blank node id if the node is blank, otherwise die horribly


getBlankNodeLabel

public java.lang.String getBlankNodeLabel()
Answer the label of this blank node or throw an UnsupportedOperationException if it's not blank.


getLiteral

public com.hp.hpl.jena.graph.impl.LiteralLabel getLiteral()
Answer the literal value of a literal node, or throw an UnsupportedOperationException if it's not a literal node


getLiteralValue

public java.lang.Object getLiteralValue()
Answer the value of this node's literal value, if it is a literal; otherwise die horribly.


getLiteralLexicalForm

public java.lang.String getLiteralLexicalForm()
Answer the lexical form of this node's literal value, if it is a literal; otherwise die horribly.


getLiteralLanguage

public java.lang.String getLiteralLanguage()
Answer the language of this node's literal value, if it is a literal; otherwise die horribly.


getLiteralDatatypeURI

public java.lang.String getLiteralDatatypeURI()
Answer the data-type URI of this node's literal value, if it is a literal; otherwise die horribly.


getLiteralDatatype

public RDFDatatype getLiteralDatatype()
Answer the RDF datatype object of this node's literal value, if it is a literal; otherwise die horribly.


getLiteralIsXML

public boolean getLiteralIsXML()

getIndexingValue

public java.lang.Object getIndexingValue()
Answer the object which is the index value for this Node. The default is this Node itself; overridden in Node_Literal for literal indexing purposes. Only concrete nodes should use this method.


getURI

public java.lang.String getURI()
get the URI of this node if it has one, else die horribly


getNameSpace

public java.lang.String getNameSpace()
get the namespace part of this node if it's a URI node, else die horribly


getLocalName

public java.lang.String getLocalName()
get the localname part of this node if it's a URI node, else die horribly


getName

public java.lang.String getName()
get a variable nodes name, otherwise die horribly


hasURI

public boolean hasURI(java.lang.String uri)
answer true iff this node is a URI node with the given URI


cache

public static void cache(boolean wantCache)
provided only for testing purposes. _cache(false)_ switches off caching and clears the cache. _cache(true)_ switches caching [back] on. This allows structural equality to be tested.


create

public static Node create(com.hp.hpl.jena.graph.Node.NodeMaker maker,
                          java.lang.Object label)
We object strongly to null labels: for example, they make .equals flaky. We reuse nodes from the recent cache if we can. Otherwise, the maker knows how to construct a new node of the correct class, and we add that node to the cache. create is synchronised to avoid threading problems - a separate thread might zap the cache entry that get is currently looking at.


equals

public abstract boolean equals(java.lang.Object o)
Nodes only equal other Nodes that have equal labels.

Overrides:
equals in class java.lang.Object

sameValueAs

public boolean sameValueAs(java.lang.Object o)
Test that two nodes are semantically equivalent. In some cases this may be the same 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.

Default implementation is to use equals, subclasses should override this.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

matches

public boolean matches(Node other)
Answer true iff this node accepts the other one as a match. The default is an equality test; it is over-ridden in subclasses to provide the appropriate semantics for literals, ANY, and variables.

Parameters:
other - a node to test for matching
Returns:
true iff this node accepts the other as a match

toString

public java.lang.String toString()
Answer a human-readable representation of this Node. It will not compress URIs, nor quote literals (because at the moment too many places use toString() for something machine-oriented).

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(boolean quoting)
Answer a human-readable representation of this Node where literals are quoted according to quoting but URIs are not compressed.


toString

public java.lang.String toString(PrefixMapping pm)
Answer a human-readable representation of the Node, quoting literals and compressing URIs.


toString

public java.lang.String toString(PrefixMapping pm,
                                 boolean quoting)
Answer a human readable representation of this Node, quoting literals if specified, and compressing URIs using the prefix mapping supplied.



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