public abstract class NodePointer extends Object implements Pointer
Modifier and Type | Field and Description |
---|---|
protected int |
index
Index for this NodePointer
|
protected Locale |
locale
Locale
|
protected NodePointer |
parent
Parent pointer
|
static String |
UNKNOWN_NAMESPACE
Constant to indicate unknown namespace
|
static int |
WHOLE_COLLECTION
Whole collection index.
|
Modifier | Constructor and Description |
---|---|
protected |
NodePointer(NodePointer parent)
Create a new NodePointer.
|
protected |
NodePointer(NodePointer parent,
Locale locale)
Create a new NodePointer.
|
Modifier and Type | Method and Description |
---|---|
String |
asPath()
Returns an XPath that maps to this Pointer.
|
NodeIterator |
attributeIterator(QName qname)
Returns a NodeIterator that iterates over all attributes of the current
node matching the supplied node name (could have a wildcard).
|
NodeIterator |
childIterator(NodeTest test,
boolean reverse,
NodePointer startWith)
Returns a NodeIterator that iterates over all children or all children
that match the given NodeTest, starting with the specified one.
|
Object |
clone()
Clone this NodePointer.
|
abstract int |
compareChildNodePointers(NodePointer pointer1,
NodePointer pointer2)
Compares two child NodePointers and returns a positive number,
zero or a positive number according to the order of the pointers.
|
int |
compareTo(Object object) |
NodePointer |
createAttribute(JXPathContext context,
QName name)
Called to create a non-existing attribute
|
NodePointer |
createChild(JXPathContext context,
QName name,
int index)
Called by a child pointer when it needs to create a parent object for a
non-existent collection element.
|
NodePointer |
createChild(JXPathContext context,
QName name,
int index,
Object value)
Called by a child pointer if that child needs to assign the value
supplied in the createPath(context, value) call to a non-existent
node.
|
NodePointer |
createPath(JXPathContext context)
Called by a child pointer when it needs to create a parent object.
|
NodePointer |
createPath(JXPathContext context,
Object value)
Called directly by JXPathContext.
|
protected String |
escape(String string)
Return a string escaping single and double quotes.
|
protected AbstractFactory |
getAbstractFactory(JXPathContext context)
Get the AbstractFactory associated with the specified JXPathContext.
|
abstract Object |
getBaseValue()
Returns the value represented by the pointer before indexing.
|
protected String |
getDefaultNamespaceURI()
Get the default ns uri
|
abstract Object |
getImmediateNode()
Returns the object the pointer points to; does not convert it
to a "canonical" type.
|
NodePointer |
getImmediateParentPointer()
Get the immediate parent pointer.
|
NodePointer |
getImmediateValuePointer() |
int |
getIndex()
If the pointer represents a collection, the index identifies
an element of that collection.
|
abstract int |
getLength()
If the pointer represents a collection (or collection element),
returns the length of the collection.
|
Locale |
getLocale()
If the Pointer has a parent, returns the parent's locale; otherwise
returns the locale specified when this Pointer was created.
|
abstract QName |
getName()
Returns the name of this node.
|
NamespaceResolver |
getNamespaceResolver()
Get the NamespaceResolver associated with this NodePointer.
|
String |
getNamespaceURI()
Returns the namespace URI associated with this Pointer.
|
String |
getNamespaceURI(String prefix)
Decodes a namespace prefix to the corresponding URI.
|
Object |
getNode()
Returns the object the pointer points to; does not convert it
to a "canonical" type.
|
NodeSet |
getNodeSetByKey(JXPathContext context,
String key,
Object value)
Find a NodeSet by key/value.
|
Object |
getNodeValue()
Deprecated.
1.1 Please use getNode()
|
NodePointer |
getParent()
Get the parent pointer.
|
Pointer |
getPointerByID(JXPathContext context,
String id)
Locates a node by ID.
|
Pointer |
getPointerByKey(JXPathContext context,
String key,
String value)
Locates a node by key and value.
|
Object |
getRootNode()
Get the root node.
|
Object |
getValue()
By default, returns
getNode() , can be overridden to
return a "canonical" value, like for instance a DOM element should
return its string value. |
NodePointer |
getValuePointer()
If this pointer manages a transparent container, like a variable,
this method returns the pointer to the contents.
|
void |
handle(Throwable t)
Handle a Throwable using an installed ExceptionHandler, if available.
|
void |
handle(Throwable t,
NodePointer originator)
Handle a Throwable using an installed ExceptionHandler, if available.
|
boolean |
isActual()
An actual pointer points to an existing part of an object graph, even
if it is null.
|
boolean |
isAttribute()
Returns true if the pointer represents the "attribute::" axis.
|
abstract boolean |
isCollection()
Returns
true if the value of the pointer is an array or
a Collection. |
boolean |
isContainer()
If true, this node is auxiliary and can only be used as an intermediate in
the chain of pointers.
|
protected boolean |
isDefaultNamespace(String prefix)
Returns true if the supplied prefix represents the
default namespace in the context of the current node.
|
boolean |
isLanguage(String lang)
Check whether our locale matches the specified language.
|
abstract boolean |
isLeaf()
If true, this node does not have children
|
boolean |
isNode()
Deprecated.
Please use !isContainer()
|
boolean |
isRoot()
Returns true if this Pointer has no parent.
|
NodeIterator |
namespaceIterator()
Returns a NodeIterator that iterates over all namespaces of the value
currently pointed at.
|
NodePointer |
namespacePointer(String namespace)
Returns a NodePointer for the specified namespace.
|
static NodePointer |
newChildNodePointer(NodePointer parent,
QName name,
Object bean)
Allocates an new child NodePointer by iterating through all installed
NodePointerFactories until it finds one that can create a pointer.
|
static NodePointer |
newNodePointer(QName name,
Object bean,
Locale locale)
Allocates an entirely new NodePointer by iterating through all installed
NodePointerFactories until it finds one that can create a pointer.
|
void |
printPointerChain()
Print internal structure of a pointer for debugging
|
void |
remove()
Remove the node of the object graph this pointer points to.
|
void |
setAttribute(boolean attribute)
Set to true if the pointer represents the "attribute::" axis.
|
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Set the exceptionHandler of this NodePointer.
|
void |
setIndex(int index)
Set the index of this NodePointer.
|
void |
setNamespaceResolver(NamespaceResolver namespaceResolver)
Set the NamespaceResolver for this NodePointer.
|
abstract void |
setValue(Object value)
Converts the value to the required type and changes the corresponding
object to that value.
|
boolean |
testNode(NodeTest test)
Checks if this Pointer matches the supplied NodeTest.
|
String |
toString() |
static NodePointer |
verify(NodePointer nodePointer)
Verify the structure of a given NodePointer.
|
public static final int WHOLE_COLLECTION
public static final String UNKNOWN_NAMESPACE
protected int index
protected NodePointer parent
protected NodePointer(NodePointer parent)
parent
- Pointerprotected NodePointer(NodePointer parent, Locale locale)
parent
- Pointerlocale
- Localepublic static NodePointer newNodePointer(QName name, Object bean, Locale locale)
name
- QNamebean
- Objectlocale
- Localepublic static NodePointer newChildNodePointer(NodePointer parent, QName name, Object bean)
parent
- pointername
- QNamebean
- Objectpublic NamespaceResolver getNamespaceResolver()
public void setNamespaceResolver(NamespaceResolver namespaceResolver)
namespaceResolver
- NamespaceResolverpublic NodePointer getParent()
public NodePointer getImmediateParentPointer()
public void setAttribute(boolean attribute)
attribute
- booleanpublic boolean isAttribute()
public boolean isRoot()
public abstract boolean isLeaf()
public boolean isNode()
public boolean isContainer()
public int getIndex()
index
is WHOLE_COLLECTION
, which just means that the pointer
is not indexed at all.
Note: the index on NodePointer starts with 0, not 1.public void setIndex(int index)
index
- intpublic abstract boolean isCollection()
true
if the value of the pointer is an array or
a Collection.public abstract int getLength()
public Object getValue()
getNode()
, can be overridden to
return a "canonical" value, like for instance a DOM element should
return its string value.public NodePointer getValuePointer()
getValuePointer()
directly. Override the
getImmediateValuePointer()
method instead. The
getValuePointer()
method is calls
getImmediateValuePointer()
and, if the result is not
this
, invokes getValuePointer()
recursively.
The idea here is to open all nested containers. Let's say we have a
container within a container within a container. The
getValuePointer()
method should then open all those
containers and return the pointer to the ultimate contents. It does so
with the above recursion.public NodePointer getImmediateValuePointer()
this
or a pointer
for the immediately contained value.getValuePointer()
public boolean isActual()
public abstract Object getBaseValue()
public Object getNodeValue()
public Object getNode()
public Object getRootNode()
getRootNode
in interface Pointer
public abstract Object getImmediateNode()
public abstract void setValue(Object value)
public abstract int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2)
pointer1
- first pointer to be comparedpointer2
- second pointer to be comparedpublic boolean testNode(NodeTest test)
test
- the NodeTest to executepublic NodePointer createPath(JXPathContext context, Object value)
context
- the owning JXPathContextvalue
- the new value to setpublic void remove()
public NodePointer createPath(JXPathContext context)
context
- the owning JXPathContextpublic NodePointer createChild(JXPathContext context, QName name, int index, Object value)
context
- the owning JXPathCOntextname
- the QName at which a child should be createdindex
- child index.value
- node value to setpublic NodePointer createChild(JXPathContext context, QName name, int index)
context
- the owning JXPathCOntextname
- the QName at which a child should be createdindex
- child index.public NodePointer createAttribute(JXPathContext context, QName name)
context
- the owning JXPathCOntextname
- the QName at which an attribute should be createdpublic Locale getLocale()
public boolean isLanguage(String lang)
lang
- String language to checkpublic NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith)
test
- NodeTest to filter childrenreverse
- specified iteration directionstartWith
- the NodePointer to start withpublic NodeIterator attributeIterator(QName qname)
qname
- the attribute name to testpublic NodeIterator namespaceIterator()
public NodePointer namespacePointer(String namespace)
namespace
- incoming namespacenamespace
public String getNamespaceURI(String prefix)
prefix
- prefix to decodepublic String getNamespaceURI()
protected boolean isDefaultNamespace(String prefix)
prefix
- the prefix to checktrue
if prefix is defaultprotected String getDefaultNamespaceURI()
public Pointer getPointerByID(JXPathContext context, String id)
context
- JXPathContext owning contextid
- String idpublic Pointer getPointerByKey(JXPathContext context, String key, String value)
context
- owning JXPathContextkey
- key to search forvalue
- value to matchpublic NodeSet getNodeSetByKey(JXPathContext context, String key, Object value)
context
- owning JXPathContextkey
- key to search forvalue
- value to matchpublic int compareTo(Object object)
compareTo
in interface Comparable
public void printPointerChain()
public void setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler
- the ExceptionHandler to setpublic void handle(Throwable t, NodePointer originator)
t
- to handleoriginator
- contextpublic void handle(Throwable t)
t
- to handleprotected String escape(String string)
string
- string to treatprotected AbstractFactory getAbstractFactory(JXPathContext context)
context
- JXPathContextpublic static NodePointer verify(NodePointer nodePointer)
nodePointer
- to checkJXPathNotFoundException
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.