|
|||||||||
| Home >> All >> org >> apache >> commons >> jxpath >> ri >> [ model overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.jxpath.ri.model
Class NodePointer

java.lang.Objectorg.apache.commons.jxpath.ri.model.NodePointer
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Comparable, org.apache.commons.jxpath.Pointer, java.io.Serializable
- Direct Known Subclasses:
- VariablePointer
- public abstract class NodePointer
- extends java.lang.Object
- implements org.apache.commons.jxpath.Pointer
- extends java.lang.Object
Common superclass for Pointers of all kinds. A NodePointer maps to a deterministic XPath that represents the location of a node in an object graph. This XPath uses only simple axes: child, namespace and attribute and only simple, context-independent predicates.
- Version:
- $Revision: 1.25 $ $Date: 2004/04/01 02:55:32 $
| Field Summary | |
private boolean |
attribute
|
protected int |
index
|
protected java.util.Locale |
locale
|
private org.apache.commons.jxpath.ri.NamespaceResolver |
namespaceResolver
|
protected NodePointer |
parent
|
private java.lang.Object |
rootNode
|
static java.lang.String |
UNKNOWN_NAMESPACE
|
static int |
WHOLE_COLLECTION
|
| Constructor Summary | |
protected |
NodePointer(NodePointer parent)
|
protected |
NodePointer(NodePointer parent,
java.util.Locale locale)
|
| Method Summary | |
java.lang.String |
asPath()
Returns an XPath that maps to this Pointer. |
NodeIterator |
attributeIterator(org.apache.commons.jxpath.ri.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(org.apache.commons.jxpath.ri.compiler.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. |
java.lang.Object |
clone()
Pointers are cloneable |
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. |
private int |
compareNodePointers(NodePointer p1,
int depth1,
NodePointer p2,
int depth2)
|
int |
compareTo(java.lang.Object object)
Compares this object with another, and returns a numerical result based on the comparison. |
NodePointer |
createAttribute(org.apache.commons.jxpath.JXPathContext context,
org.apache.commons.jxpath.ri.QName name)
Called to create a non-existing attribute |
NodePointer |
createChild(org.apache.commons.jxpath.JXPathContext context,
org.apache.commons.jxpath.ri.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(org.apache.commons.jxpath.JXPathContext context,
org.apache.commons.jxpath.ri.QName name,
int index,
java.lang.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(org.apache.commons.jxpath.JXPathContext context)
Called by a child pointer when it needs to create a parent object. |
NodePointer |
createPath(org.apache.commons.jxpath.JXPathContext context,
java.lang.Object value)
Called directly by JXPathContext. |
private static boolean |
equalStrings(java.lang.String s1,
java.lang.String s2)
|
abstract java.lang.Object |
getBaseValue()
Returns the value represented by the pointer before indexing. |
protected java.lang.String |
getDefaultNamespaceURI()
|
abstract java.lang.Object |
getImmediateNode()
Returns the object the pointer points to; does not convert it to a "canonical" type. |
NodePointer |
getImmediateParentPointer()
|
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. |
java.util.Locale |
getLocale()
If the Pointer has a parent, returns the parent's locale; otherwise returns the locale specified when this Pointer was created. |
abstract org.apache.commons.jxpath.ri.QName |
getName()
Returns the name of this node. |
org.apache.commons.jxpath.ri.NamespaceResolver |
getNamespaceResolver()
|
java.lang.String |
getNamespaceURI()
Returns the namespace URI associated with this Pointer. |
java.lang.String |
getNamespaceURI(java.lang.String prefix)
Decodes a namespace prefix to the corresponding URI. |
java.lang.Object |
getNode()
Returns the object the pointer points to; does not convert it to a "canonical" type. |
java.lang.Object |
getNodeValue()
Deprecated. 1.1 Please use getNode() |
NodePointer |
getParent()
|
org.apache.commons.jxpath.Pointer |
getPointerByID(org.apache.commons.jxpath.JXPathContext context,
java.lang.String id)
Locates a node by ID. |
org.apache.commons.jxpath.Pointer |
getPointerByKey(org.apache.commons.jxpath.JXPathContext context,
java.lang.String key,
java.lang.String value)
Locates a node by key and value. |
java.lang.Object |
getRootNode()
Returns the node this pointer is based on. |
java.lang.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. |
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 axiliary and can only be used as an intermediate in the chain of pointers. |
protected boolean |
isDefaultNamespace(java.lang.String prefix)
Returns true if the supplied prefix represents the default namespace in the context of the current node. |
boolean |
isLanguage(java.lang.String lang)
Returns true if the selected locale name starts with the specified prefix lang, case-insensitive. |
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(java.lang.String namespace)
Returns a NodePointer for the specified namespace. |
static NodePointer |
newChildNodePointer(NodePointer parent,
org.apache.commons.jxpath.ri.QName name,
java.lang.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(org.apache.commons.jxpath.ri.QName name,
java.lang.Object bean,
java.util.Locale locale)
Allocates an entirely new NodePointer by iterating through all installed NodePointerFactories until it finds one that can create a pointer. |
private static void |
printDeep(NodePointer pointer,
java.lang.String indent)
|
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 |
setIndex(int index)
|
void |
setNamespaceResolver(org.apache.commons.jxpath.ri.NamespaceResolver namespaceResolver)
|
abstract void |
setValue(java.lang.Object value)
Converts the value to the required type and changes the corresponding object to that value. |
boolean |
testNode(org.apache.commons.jxpath.ri.compiler.NodeTest test)
Checks if this Pointer matches the supplied NodeTest. |
java.lang.String |
toString()
Convert this Object to a human-readable String. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
WHOLE_COLLECTION
public static final int WHOLE_COLLECTION
- See Also:
- Constant Field Values
index
protected int index
UNKNOWN_NAMESPACE
public static final java.lang.String UNKNOWN_NAMESPACE
- See Also:
- Constant Field Values
attribute
private boolean attribute
rootNode
private transient java.lang.Object rootNode
namespaceResolver
private org.apache.commons.jxpath.ri.NamespaceResolver namespaceResolver
parent
protected NodePointer parent
locale
protected java.util.Locale locale
| Constructor Detail |
NodePointer
protected NodePointer(NodePointer parent)
NodePointer
protected NodePointer(NodePointer parent, java.util.Locale locale)
| Method Detail |
newNodePointer
public static NodePointer newNodePointer(org.apache.commons.jxpath.ri.QName name, java.lang.Object bean, java.util.Locale locale)
- Allocates an entirely new NodePointer by iterating through all installed
NodePointerFactories until it finds one that can create a pointer.
newChildNodePointer
public static NodePointer newChildNodePointer(NodePointer parent, org.apache.commons.jxpath.ri.QName name, java.lang.Object bean)
- Allocates an new child NodePointer by iterating through all installed
NodePointerFactories until it finds one that can create a pointer.
getNamespaceResolver
public org.apache.commons.jxpath.ri.NamespaceResolver getNamespaceResolver()
setNamespaceResolver
public void setNamespaceResolver(org.apache.commons.jxpath.ri.NamespaceResolver namespaceResolver)
getParent
public NodePointer getParent()
getImmediateParentPointer
public NodePointer getImmediateParentPointer()
setAttribute
public void setAttribute(boolean attribute)
- Set to true if the pointer represents the "attribute::" axis.
isAttribute
public boolean isAttribute()
- Returns true if the pointer represents the "attribute::" axis.
isRoot
public boolean isRoot()
- Returns true if this Pointer has no parent.
isLeaf
public abstract boolean isLeaf()
- If true, this node does not have children
isNode
public boolean isNode()
- Deprecated. Please use !isContainer()
isContainer
public boolean isContainer()
- If true, this node is axiliary and can only be used as an intermediate in
the chain of pointers.
getIndex
public int getIndex()
- If the pointer represents a collection, the index identifies
an element of that collection. The default value of
indexisWHOLE_COLLECTION, which just means that the pointer is not indexed at all. Note: the index on NodePointer starts with 0, not 1.
setIndex
public void setIndex(int index)
isCollection
public abstract boolean isCollection()
- Returns
trueif the value of the pointer is an array or a Collection.
getLength
public abstract int getLength()
- If the pointer represents a collection (or collection element),
returns the length of the collection.
Otherwise returns 1 (even if the value is null).
getValue
public java.lang.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.- Specified by:
getValuein interfaceorg.apache.commons.jxpath.Pointer
getValuePointer
public NodePointer getValuePointer()
- If this pointer manages a transparent container, like a variable,
this method returns the pointer to the contents.
Only an auxiliary (non-node) pointer can (and should) return a
value pointer other than itself.
Note that you probably don't want to override
getValuePointer()directly. Override thegetImmediateValuePointer()method instead. ThegetValuePointer()method is callsgetImmediateValuePointer()and, if the result is notthis, invokesgetValuePointer()recursively. The idea here is to open all nested containers. Let's say we have a container within a container within a container. ThegetValuePointer()method should then open all those containers and return the pointer to the ultimate contents. It does so with the above recursion.
getImmediateValuePointer
public NodePointer getImmediateValuePointer()
isActual
public boolean isActual()
- An actual pointer points to an existing part of an object graph, even
if it is null. A non-actual pointer represents a part that does not exist
at all.
For instance consider the pointer "/address/street".
If both address and street are not null,
the pointer is actual.
If address is not null, but street is null,
the pointer is still actual.
If address is null, the pointer is not actual.
(In JavaBeans) if address is not a property of the root bean,
a Pointer for this path cannot be obtained at all - actual or otherwise.
getName
public abstract org.apache.commons.jxpath.ri.QName getName()
- Returns the name of this node. Can be null.
getBaseValue
public abstract java.lang.Object getBaseValue()
- Returns the value represented by the pointer before indexing.
So, if the node represents an element of a collection, this
method returns the collection itself.
getNodeValue
public java.lang.Object getNodeValue()
- Deprecated. 1.1 Please use getNode()
- Returns the object the pointer points to; does not convert it to a "canonical" type.
- Returns the object the pointer points to; does not convert it to a "canonical" type.
getNode
public java.lang.Object getNode()
- Returns the object the pointer points to; does not convert it
to a "canonical" type. Opens containers, properties etc and returns
the ultimate contents.
- Specified by:
getNodein interfaceorg.apache.commons.jxpath.Pointer
getRootNode
public java.lang.Object getRootNode()
- Description copied from interface:
org.apache.commons.jxpath.Pointer - Returns the node this pointer is based on.
- Specified by:
getRootNodein interfaceorg.apache.commons.jxpath.Pointer
getImmediateNode
public abstract java.lang.Object getImmediateNode()
- Returns the object the pointer points to; does not convert it
to a "canonical" type.
setValue
public abstract void setValue(java.lang.Object value)
- Converts the value to the required type and changes the corresponding
object to that value.
- Specified by:
setValuein interfaceorg.apache.commons.jxpath.Pointer
compareChildNodePointers
public 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.
testNode
public boolean testNode(org.apache.commons.jxpath.ri.compiler.NodeTest test)
- Checks if this Pointer matches the supplied NodeTest.
equalStrings
private static boolean equalStrings(java.lang.String s1, java.lang.String s2)
createPath
public NodePointer createPath(org.apache.commons.jxpath.JXPathContext context, java.lang.Object value)
- Called directly by JXPathContext. Must create path and
set value.
remove
public void remove()
- Remove the node of the object graph this pointer points to.
createPath
public NodePointer createPath(org.apache.commons.jxpath.JXPathContext context)
- Called by a child pointer when it needs to create a parent object.
Must create an object described by this pointer and return
a new pointer that properly describes the new object.
createChild
public NodePointer createChild(org.apache.commons.jxpath.JXPathContext context, org.apache.commons.jxpath.ri.QName name, int index, java.lang.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. This method may have to expand the collection in order to assign
the element.
createChild
public NodePointer createChild(org.apache.commons.jxpath.JXPathContext context, org.apache.commons.jxpath.ri.QName name, int index)
- Called by a child pointer when it needs to create a parent object
for a non-existent collection element. It may have to expand the
collection, then create an element object and return a new pointer
describing the newly created element.
createAttribute
public NodePointer createAttribute(org.apache.commons.jxpath.JXPathContext context, org.apache.commons.jxpath.ri.QName name)
- Called to create a non-existing attribute
getLocale
public java.util.Locale getLocale()
- If the Pointer has a parent, returns the parent's locale;
otherwise returns the locale specified when this Pointer
was created.
isLanguage
public boolean isLanguage(java.lang.String lang)
- Returns true if the selected locale name starts
with the specified prefix lang, case-insensitive.
childIterator
public NodeIterator childIterator(org.apache.commons.jxpath.ri.compiler.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.
attributeIterator
public NodeIterator attributeIterator(org.apache.commons.jxpath.ri.QName qname)
- Returns a NodeIterator that iterates over all attributes of the current
node matching the supplied node name (could have a wildcard).
May return null if the object does not support the attributes.
namespaceIterator
public NodeIterator namespaceIterator()
- Returns a NodeIterator that iterates over all namespaces of the value
currently pointed at.
May return null if the object does not support the namespaces.
namespacePointer
public NodePointer namespacePointer(java.lang.String namespace)
- Returns a NodePointer for the specified namespace. Will return null
if namespaces are not supported.
Will return UNKNOWN_NAMESPACE if there is no such namespace.
getNamespaceURI
public java.lang.String getNamespaceURI(java.lang.String prefix)
- Decodes a namespace prefix to the corresponding URI.
getNamespaceURI
public java.lang.String getNamespaceURI()
- Returns the namespace URI associated with this Pointer.
isDefaultNamespace
protected boolean isDefaultNamespace(java.lang.String prefix)
- Returns true if the supplied prefix represents the
default namespace in the context of the current node.
getDefaultNamespaceURI
protected java.lang.String getDefaultNamespaceURI()
getPointerByID
public org.apache.commons.jxpath.Pointer getPointerByID(org.apache.commons.jxpath.JXPathContext context, java.lang.String id)
- Locates a node by ID.
getPointerByKey
public org.apache.commons.jxpath.Pointer getPointerByKey(org.apache.commons.jxpath.JXPathContext context, java.lang.String key, java.lang.String value)
- Locates a node by key and value.
asPath
public java.lang.String asPath()
- Returns an XPath that maps to this Pointer.
- Specified by:
asPathin interfaceorg.apache.commons.jxpath.Pointer
clone
public java.lang.Object clone()
- Description copied from interface:
org.apache.commons.jxpath.Pointer - Pointers are cloneable
- Specified by:
clonein interfaceorg.apache.commons.jxpath.Pointer
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object - Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string concatenation with this object. If the result is
null, string concatenation will instead use"null".The default implementation returns
getClass().getName() + "@" + Integer.toHexString(hashCode()).
compareTo
public int compareTo(java.lang.Object object)
- Description copied from interface:
java.lang.Comparable - Compares this object with another, and returns a numerical result based
on the comparison. If the result is negative, this object sorts less
than the other; if 0, the two are equal, and if positive, this object
sorts greater than the other. To translate this into boolean, simply
perform
o1.compareTo(o2) <op> 0, where op is one of <, <=, =, !=, >, or >=.You must make sure that the comparison is mutual, ie.
sgn(x.compareTo(y)) == -sgn(y.compareTo(x))(where sgn() is defined as -1, 0, or 1 based on the sign). This includes throwing an exception in either direction if the two are not comparable; hence,compareTo(null)should always throw an Exception.You should also ensure transitivity, in two forms:
x.compareTo(y) > 0 && y.compareTo(z) > 0impliesx.compareTo(z) > 0; andx.compareTo(y) == 0impliesx.compareTo(z) == y.compareTo(z).- Specified by:
compareToin interfacejava.lang.Comparable
compareNodePointers
private int compareNodePointers(NodePointer p1, int depth1, NodePointer p2, int depth2)
printPointerChain
public void printPointerChain()
- Print internal structure of a pointer for debugging
printDeep
private static void printDeep(NodePointer pointer, java.lang.String indent)
|
|||||||||
| Home >> All >> org >> apache >> commons >> jxpath >> ri >> [ model overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.commons.jxpath.ri.model.NodePointer