Package org.apache.commons.jxpath.ri.model

# Class NodePointer

java.lang.Object
org.apache.commons.jxpath.ri.model.NodePointer

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Comparable`, `Pointer`

Direct Known Subclasses:
  `CollectionPointer`, `ContainerPointer`, `DOMAttributePointer`, `DOMNodePointer`, `JDOMAttributePointer`, `JDOMNamespacePointer`, `JDOMNodePointer`, `LangAttributePointer`, `NamespacePointer`, `PropertyOwnerPointer`, `PropertyPointer`, `VariablePointer`

public abstract class NodePointer extends Object implements Pointer
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.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected int`
  `index`
  Index for this NodePointer.
  `protected Locale`
  `locale`
  Locale
  `protected NodePointer`
  `parent`
  Parent pointer
  `static final String`
  `UNKNOWN_NAMESPACE`
  Constant to indicate unknown namespace
  `static final int`
  `WHOLE_COLLECTION`
  Whole collection index.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `NodePointer(NodePointer parent)`
  Constructs a new NodePointer.
  `protected`
  `NodePointer(NodePointer parent, Locale locale)`
  Constructs a new NodePointer.

- ## Method Summary

  Modifier and Type
  Method
  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 qName)`
  Called to create a non-existing attribute
  `NodePointer`
  `createChild(JXPathContext context, QName qName, 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 qName, 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)`
  Gets the AbstractFactory associated with the specified JXPathContext.
  `abstract Object`
  `getBaseValue()`
  Gets the value represented by the pointer before indexing.
  `protected String`
  `getDefaultNamespaceURI()`
  Gets the default ns uri
  `abstract Object`
  `getImmediateNode()`
  Returns the object the pointer points to; does not convert it to a "canonical" type.
  `NodePointer`
  `getImmediateParentPointer()`
  Gets the immediate parent pointer.
  `NodePointer`
  `getImmediateValuePointer()`
  Gets this instance by default, subclasses can return a pointer for the immediately contained value.
  `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()`
  Gets the name of this node.
  `NamespaceResolver`
  `getNamespaceResolver()`
  Gets 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()`
  Gets 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()`
  Gets 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 !
  `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 qName, 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 qName, 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)`
  Sets to true if the pointer represents the "attribute::" axis.
  `void`
  `setExceptionHandler(ExceptionHandler exceptionHandler)`
  Sets the exceptionHandler of this NodePointer.
  `void`
  `setIndex(int index)`
  Sets the index of this NodePointer.
  `void`
  `setNamespaceResolver(NamespaceResolver namespaceResolver)`
  Sets 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.

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### WHOLE_COLLECTION

    public static final int WHOLE_COLLECTION
    Whole collection index.
    See Also:
      - Constant Field Values

  - ### UNKNOWN_NAMESPACE

    public static final String UNKNOWN_NAMESPACE
    Constant to indicate unknown namespace
    See Also:
      - Constant Field Values

  - ### index

    protected int index
    Index for this NodePointer.

  - ### parent

    protected NodePointer parent
    Parent pointer

  - ### locale

    protected Locale locale
    Locale

- ## Constructor Details

  - ### NodePointer

    protected NodePointer(NodePointer parent)
    Constructs a new NodePointer.
    Parameters:
      `parent` - Pointer

  - ### NodePointer

    protected NodePointer(NodePointer parent, Locale locale)
    Constructs a new NodePointer.
    Parameters:
      `parent` - Pointer
      `locale` - Locale

- ## Method Details

  - ### newChildNodePointer

    public static NodePointer newChildNodePointer(NodePointer parent, QName qName, Object bean)
    Allocates an new child NodePointer by iterating through all installed NodePointerFactories until it finds one that can create a pointer.
    Parameters:
      `parent` - pointer
      `qName` - QName
      `bean` - Object
    Returns:
      NodePointer

  - ### newNodePointer

    public static NodePointer newNodePointer(QName qName, Object bean, Locale locale)
    Allocates an entirely new NodePointer by iterating through all installed NodePointerFactories until it finds one that can create a pointer.
    Parameters:
      `qName` - QName
      `bean` - Object
      `locale` - Locale
    Returns:
      NodePointer

  - ### verify

    public static NodePointer verify(NodePointer nodePointer)
    Verify the structure of a given NodePointer.
    Parameters:
      `nodePointer` - to check
    Returns:
      nodePointer
    Throws:
      `JXPathNotFoundException` - Thrown when there is no value at the NodePointer.

  - ### asPath

    public String asPath()
    Returns an XPath that maps to this Pointer.
    Specified by:
      `asPath` in interface `Pointer`
    Returns:
      String XPath expression

  - ### attributeIterator

    public 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). May return null if the object does not support the attributes.
    Parameters:
      `qname` - the attribute name to test
    Returns:
      NodeIterator

  - ### childIterator

    public 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.
    Parameters:
      `test` - NodeTest to filter children
      `reverse` - specified iteration direction
      `startWith` - the NodePointer to start with
    Returns:
      NodeIterator

  - ### clone

    public Object clone()
    Clone this NodePointer.
    Specified by:
      `clone` in interface `Pointer`
    Overrides:
      `clone` in class `Object`
    Returns:
      cloned NodePointer

  - ### 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.
    Parameters:
      `pointer1` - first pointer to be compared
      `pointer2` - second pointer to be compared
    Returns:
      int per Java comparison conventions

  - ### compareTo

    public int compareTo(Object object)
    Specified by:
      `compareTo` in interface `Comparable`

  - ### createAttribute

    public NodePointer createAttribute(JXPathContext context, QName qName)
    Called to create a non-existing attribute
    Parameters:
      `context` - the owning JXPathCOntext
      `qName` - the QName at which an attribute should be created
    Returns:
      created NodePointer

  - ### createChild

    public NodePointer createChild(JXPathContext context, QName qName, 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.
    Parameters:
      `context` - the owning JXPathCOntext
      `qName` - the QName at which a child should be created
      `index` - child index.
    Returns:
      created NodePointer

  - ### createChild

    public NodePointer createChild(JXPathContext context, QName qName, 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. This method may have to expand the collection in order to assign the element.
    Parameters:
      `context` - the owning JXPathCOntext
      `qName` - the QName at which a child should be created
      `index` - child index.
      `value` - node value to set
    Returns:
      created NodePointer

  - ### createPath

    public NodePointer createPath(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.
    Parameters:
      `context` - the owning JXPathContext
    Returns:
      created NodePointer

  - ### createPath

    public NodePointer createPath(JXPathContext context, Object value)
    Called directly by JXPathContext. Must create path and set value.
    Parameters:
      `context` - the owning JXPathContext
      `value` - the new value to set
    Returns:
      created NodePointer

  - ### escape

    protected String escape(String string)
    Return a string escaping single and double quotes.
    Parameters:
      `string` - string to treat
    Returns:
      string with any necessary changes made.

  - ### getAbstractFactory

    protected AbstractFactory getAbstractFactory(JXPathContext context)
    Gets the AbstractFactory associated with the specified JXPathContext.
    Parameters:
      `context` - JXPathContext
    Returns:
      AbstractFactory

  - ### getBaseValue

    public abstract Object getBaseValue()
    Gets the value represented by the pointer before indexing. So, if the node represents an element of a collection, this method returns the collection itself.
    Returns:
      Object value

  - ### getDefaultNamespaceURI

    protected String getDefaultNamespaceURI()
    Gets the default ns uri
    Returns:
      String uri

  - ### getImmediateNode

    public abstract Object getImmediateNode()
    Returns the object the pointer points to; does not convert it to a "canonical" type.
    Returns:
      Object node

  - ### getImmediateParentPointer

    public NodePointer getImmediateParentPointer()
    Gets the immediate parent pointer.
    Returns:
      NodePointer

  - ### getImmediateValuePointer

    public NodePointer getImmediateValuePointer()
    Gets this instance by default, subclasses can return a pointer for the immediately contained value.
    Returns:
      NodePointer is either `this` or a pointer for the immediately contained value.
    See Also:
      - `getValuePointer()`

  - ### getIndex

    public int getIndex()
    If the pointer represents a collection, the index identifies an element of that collection. The default value of `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.
    Returns:
      the index.

  - ### 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).
    Returns:
      the length.

  - ### getLocale

    public Locale getLocale()
    If the Pointer has a parent, returns the parent's locale; otherwise returns the locale specified when this Pointer was created.
    Returns:
      Locale for this NodePointer

  - ### getName

    public abstract QName getName()
    Gets the name of this node. Can be null.
    Returns:
      QName The name of this node. Can be null.

  - ### getNamespaceResolver

    public NamespaceResolver getNamespaceResolver()
    Gets the NamespaceResolver associated with this NodePointer.
    Returns:
      NamespaceResolver

  - ### getNamespaceURI

    public String getNamespaceURI()
    Returns the namespace URI associated with this Pointer.
    Returns:
      String uri

  - ### getNamespaceURI

    public String getNamespaceURI(String prefix)
    Decodes a namespace prefix to the corresponding URI.
    Parameters:
      `prefix` - prefix to decode
    Returns:
      String uri

  - ### getNode

    public 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:
      `getNode` in interface `Pointer`
    Returns:
      Object node

  - ### getNodeSetByKey

    public NodeSet getNodeSetByKey(JXPathContext context, String key, Object value)
    Find a NodeSet by key/value.
    Parameters:
      `context` - owning JXPathContext
      `key` - key to search for
      `value` - value to match
    Returns:
      NodeSet found

  - ### getNodeValue

    @Deprecated public Object getNodeValue()
    Deprecated.
    1.1 Please use getNode()
    Returns the object the pointer points to; does not convert it to a "canonical" type.
    Returns:
      Object node value

  - ### getParent

    public NodePointer getParent()
    Gets the parent pointer.
    Returns:
      NodePointer

  - ### getPointerByID

    public Pointer getPointerByID(JXPathContext context, String id)
    Locates a node by ID.
    Parameters:
      `context` - JXPathContext owning context
      `id` - String id
    Returns:
      Pointer found

  - ### getPointerByKey

    public Pointer getPointerByKey(JXPathContext context, String key, String value)
    Locates a node by key and value.
    Parameters:
      `context` - owning JXPathContext
      `key` - key to search for
      `value` - value to match
    Returns:
      Pointer found

  - ### getRootNode

    public Object getRootNode()
    Gets the root node.
    Specified by:
      `getRootNode` in interface `Pointer`
    Returns:
      Object value of this pointer's root (top parent).

  - ### getValue

    public 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:
      `getValue` in interface `Pointer`
    Returns:
      Object value

  - ### 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 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.
    Returns:
      NodePointer

  - ### handle

    public void handle(Throwable t)
    Handle a Throwable using an installed ExceptionHandler, if available. Public to facilitate calling for RI support; not truly intended for public consumption.
    Parameters:
      `t` - to handle

  - ### handle

    public void handle(Throwable t, NodePointer originator)
    Handle a Throwable using an installed ExceptionHandler, if available. Public to facilitate calling for RI support; not truly intended for public consumption.
    Parameters:
      `t` - to handle
      `originator` - context

  - ### 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.
    Returns:
      boolean

  - ### isAttribute

    public boolean isAttribute()
    Returns true if the pointer represents the "attribute::" axis.
    Returns:
      boolean

  - ### isCollection

    public abstract boolean isCollection()
    Returns `true` if the value of the pointer is an array or a Collection.
    Returns:
      boolean

  - ### isContainer

    public boolean isContainer()
    If true, this node is auxiliary and can only be used as an intermediate in the chain of pointers.
    Returns:
      boolean

  - ### isDefaultNamespace

    protected boolean isDefaultNamespace(String prefix)
    Returns true if the supplied prefix represents the default namespace in the context of the current node.
    Parameters:
      `prefix` - the prefix to check
    Returns:
      `true` if prefix is default

  - ### isLanguage

    public boolean isLanguage(String lang)
    Check whether our locale matches the specified language.
    Parameters:
      `lang` - String language to check
    Returns:
      true if the selected locale name starts with the specified prefix lang, case-insensitive.

  - ### isLeaf

    public abstract boolean isLeaf()
    If true, this node does not have children
    Returns:
      boolean

  - ### isNode

    @Deprecated public boolean isNode()
    Deprecated.
    Please use !isContainer()
    Tests whether this pointer is considered to be a node.
    Returns:
      boolean

  - ### isRoot

    public boolean isRoot()
    Returns true if this Pointer has no parent.
    Returns:
      boolean

  - ### 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.
    Returns:
      NodeIterator

  - ### namespacePointer

    public NodePointer namespacePointer(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.
    Parameters:
      `namespace` - incoming namespace
    Returns:
      NodePointer for `namespace`

  - ### printPointerChain

    public void printPointerChain()
    Print internal structure of a pointer for debugging

  - ### remove

    public void remove()
    Remove the node of the object graph this pointer points to.

  - ### setAttribute

    public void setAttribute(boolean attribute)
    Sets to true if the pointer represents the "attribute::" axis.
    Parameters:
      `attribute` - boolean

  - ### setExceptionHandler

    public void setExceptionHandler(ExceptionHandler exceptionHandler)
    Sets the exceptionHandler of this NodePointer.
    Parameters:
      `exceptionHandler` - the ExceptionHandler to set

  - ### setIndex

    public void setIndex(int index)
    Sets the index of this NodePointer.
    Parameters:
      `index` - int

  - ### setNamespaceResolver

    public void setNamespaceResolver(NamespaceResolver namespaceResolver)
    Sets the NamespaceResolver for this NodePointer.
    Parameters:
      `namespaceResolver` - NamespaceResolver

  - ### setValue

    public abstract void setValue(Object value)
    Converts the value to the required type and changes the corresponding object to that value.
    Specified by:
      `setValue` in interface `Pointer`
    Parameters:
      `value` - the value to set

  - ### testNode

    public boolean testNode(NodeTest test)
    Checks if this Pointer matches the supplied NodeTest.
    Parameters:
      `test` - the NodeTest to execute
    Returns:
      true if a match

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`