Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.hp.hpl.jena.graph
Class Node  view Node download Node.java

java.lang.Object
  extended bycom.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.


Nested Class Summary
(package private) static class Node.NodeMaker
          an abstraction to allow code sharing
 
Field Summary
static Node ANY
          The canonical instance of Node_ANY; no-one else need use the constructor.
private static boolean caching
           
protected  java.lang.Object label
           
(package private) static org.apache.commons.logging.Log log
           
(package private) static Node.NodeMaker makeAnon
           
(package private) static Node.NodeMaker makeLiteral
           
(package private) static Node.NodeMaker makeURI
           
(package private) static Node.NodeMaker makeVariable
           
static Node NULL
          The canonical NULL.
(package private) static NodeCache present
           
(package private) static java.lang.String RDFprefix
           
(package private) static int THRESHOLD
           
 
Constructor Summary
(package private) Node(java.lang.Object label)
          keep the distinguishing label value.
 
Method Summary
static void cache(boolean wantCache)
          provided only for testing purposes.
private static Node cacheNewNode(java.lang.Object label, Node n)
          cache the node n under the key label, and return that node.
static Node create(Node.NodeMaker maker, java.lang.Object label)
          We object strongly to null labels: for example, they make .equals flaky.
static Node create(com.hp.hpl.jena.shared.PrefixMapping pm, java.lang.String x)
          As for create(String), but the PrefixMapping used to translate URI strings is an additional argument.
static Node create(java.lang.String x)
          Returns a Node described by the string, primarily for testing purposes.
static Node createAnon()
          make a blank node with a fresh anon id
static Node createAnon(com.hp.hpl.jena.rdf.model.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, com.hp.hpl.jena.datatypes.RDFDatatype dtype)
          Build a typed literal node from its lexical form.
static Node createUncachedLiteral(java.lang.Object value, java.lang.String lang, com.hp.hpl.jena.datatypes.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.
 com.hp.hpl.jena.rdf.model.AnonId getBlankNodeId()
          get the blank node id if the node is blank, otherwise die horribly
 com.hp.hpl.jena.graph.impl.LiteralLabel getLiteral()
          get the literal value of a literal node, 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
private static com.hp.hpl.jena.datatypes.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()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 boolean hasURI(java.lang.String uri)
          answer true iff this node is a URI node with the given URI
 boolean isBlank()
          is this a blank node - overridden in Node_Blank
abstract  boolean isConcrete()
          Answer true iff this node is concrete, ie not variable, ie URI, blank, or literal.
 boolean isLiteral()
          is this a literal node - overridden in Node_Literal
 boolean isURI()
          is this a URI node - overridden in Node_URI
 boolean isVariable()
          is this a variable node - overridden in Node_Variable
private static com.hp.hpl.jena.graph.impl.LiteralLabel literal(com.hp.hpl.jena.shared.PrefixMapping pm, java.lang.String spelling, java.lang.String langOrType)
           
 boolean matches(Node other)
          Answer true iff this node accepts the other one as a match.
private static com.hp.hpl.jena.graph.impl.LiteralLabel newString(com.hp.hpl.jena.shared.PrefixMapping pm, char quote, java.lang.String nodeString)
           
 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(com.hp.hpl.jena.shared.PrefixMapping pm)
          Answer a human-readable representation of the Node, quoting literals and compressing URIs.
 java.lang.String toString(com.hp.hpl.jena.shared.PrefixMapping pm, boolean quoting)
          Answer a human readable representation of this Node, quoting literals if specified, and compressing URIs using the prefix mapping supplied.
private static char unEscape(char ch)
           
private static java.lang.String unEscape(java.lang.String spelling)
           
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

label

protected final java.lang.Object label

THRESHOLD

static final int THRESHOLD
See Also:
Constant Field Values

present

static final NodeCache present

log

static final org.apache.commons.logging.Log log

ANY

public static final Node ANY
The canonical instance of Node_ANY; no-one else need use the constructor.


RDFprefix

static final java.lang.String RDFprefix
See Also:
Constant Field Values

makeAnon

static final Node.NodeMaker makeAnon

makeLiteral

static final Node.NodeMaker makeLiteral

makeURI

static final Node.NodeMaker makeURI

makeVariable

static final Node.NodeMaker makeVariable

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.


caching

private static boolean caching
Constructor Detail

Node

Node(java.lang.Object label)
keep the distinguishing label value.

Method Detail

create

public static Node create(java.lang.String x)
Returns a Node described by the string, primarily for testing purposes. The string represents a URI, a numeric literal, a string literal, a bnode label, or a variable.
  • 'some text' :: a string literal with that text
  • 'some text'someLanguage:: a string literal with that text and language
  • 'some text'someURI:: a typed literal with that text and datatype
  • digits :: a literal [OF WHAT TYPE] with that [numeric] value
  • _XXX :: a bnode with an AnonId built from _XXX
  • ?VVV :: a variable with name VVV
  • &PPP :: to be done
  • name:stuff :: the URI; name may be expanded using the Extended map


create

public static Node create(com.hp.hpl.jena.shared.PrefixMapping pm,
                          java.lang.String x)
As for create(String), but the PrefixMapping used to translate URI strings is an additional argument.


getType

private static com.hp.hpl.jena.datatypes.RDFDatatype getType(java.lang.String s)

literal

private static com.hp.hpl.jena.graph.impl.LiteralLabel literal(com.hp.hpl.jena.shared.PrefixMapping pm,
                                                               java.lang.String spelling,
                                                               java.lang.String langOrType)

unEscape

private static java.lang.String unEscape(java.lang.String spelling)

unEscape

private static char unEscape(char ch)

newString

private static com.hp.hpl.jena.graph.impl.LiteralLabel newString(com.hp.hpl.jena.shared.PrefixMapping pm,
                                                                 char quote,
                                                                 java.lang.String nodeString)

createAnon

public static Node createAnon(com.hp.hpl.jena.rdf.model.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


createAnon

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


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. This intermediate implementation logs a warning to allow users moving over to Jena2 to correct their code. When they've had the opportunity, arrange to throw an exception, and delete _nullLiteralsGenerateWarnings_ and update the regression tests as directed.


createLiteral

public static Node createLiteral(java.lang.String lex,
                                 java.lang.String lang,
                                 com.hp.hpl.jena.datatypes.RDFDatatype dtype)
                          throws com.hp.hpl.jena.datatypes.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.


createUncachedLiteral

public static Node createUncachedLiteral(java.lang.Object value,
                                         java.lang.String lang,
                                         com.hp.hpl.jena.datatypes.RDFDatatype dtype)
                                  throws com.hp.hpl.jena.datatypes.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.


isConcrete

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


isLiteral

public boolean isLiteral()
is this a literal node - overridden in Node_Literal


isBlank

public boolean isBlank()
is this a blank node - overridden in Node_Blank


isURI

public boolean isURI()
is this a URI node - overridden in Node_URI


isVariable

public boolean isVariable()
is this a variable node - overridden in Node_Variable


getBlankNodeId

public com.hp.hpl.jena.rdf.model.AnonId getBlankNodeId()
get the blank node id if the node is blank, otherwise die horribly


getLiteral

public com.hp.hpl.jena.graph.impl.LiteralLabel getLiteral()
get the literal value of a literal node, otherwise die horribly


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


cacheNewNode

private static Node cacheNewNode(java.lang.Object label,
                                 Node n)
cache the node n under the key label, and return that node.


equals

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


sameValueAs

public boolean sameValueAs(java.lang.Object o)
Test that two nodes 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.

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


hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


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.


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


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(com.hp.hpl.jena.shared.PrefixMapping pm)
Answer a human-readable representation of the Node, quoting literals and compressing URIs.


toString

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