net.sf.saxon.option.axiom

## Class AxiomDocumentWrapper

- java.lang.Object
- - net.sf.saxon.tree.wrapper.AbstractNodeWrapper
  - - net.sf.saxon.option.axiom.AxiomParentNodeWrapper
    - - net.sf.saxon.option.axiom.AxiomDocumentWrapper

- All Implemented Interfaces:
    Source, PullEvent, DocumentInfo, Item, NodeInfo, Sequence, SiblingCountingNode, VirtualNode

      public class AxiomDocumentWrapper
      extends AxiomParentNodeWrapper
      implements DocumentInfo

  The root node of an XPath tree. (Or equivalently, the tree itself).

  This class is used not only for a document, but also for the root of a document-less tree fragment.

  Author:
    Michael H. Kay

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `AxiomDocumentWrapper.FollowingSiblingIterator`
    `protected static class` | `AxiomDocumentWrapper.PrecedingSiblingIterator`

    - ### Nested classes/interfaces inherited from class net.sf.saxon.option.axiom.AxiomParentNodeWrapper

      `AxiomParentNodeWrapper.ChildWrappingIterator, AxiomParentNodeWrapper.DescendantWrappingIterator`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `baseURI`
    `protected Configuration` | `config`
    `protected long` | `documentNumber`

    - ### Fields inherited from class net.sf.saxon.option.axiom.AxiomParentNodeWrapper

      `node`

    - ### Fields inherited from interface net.sf.saxon.om.NodeInfo

      `ALL_NAMESPACES, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AxiomDocumentWrapper(org.apache.axiom.om.OMDocument root, String baseURI, Configuration config)` Create a Saxon wrapper for an Axiom document node

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareOrder(NodeInfo other)` Determine the relative position of this node and another node, in document order.
    `String` | `getBaseURI()` Get the Base URI for the node, that is, the URI used for resolving a relative URI contained in the node.
    `Configuration` | `getConfiguration()` Get the configuration previously set using setConfiguration
    `String` | `getDisplayName()` Get the display name of this node.
    `long` | `getDocumentNumber()` Get the unique document number for this document (the number is unique for all documents within a NamePool)
    `DocumentInfo` | `getDocumentRoot()` Get the root node, if it is a document node.
    `int` | `getFingerprint()` Get fingerprint.
    `String` | `getLocalPart()` Get the local part of the name of this node.
    `int` | `getNameCode()` Get name code.
    `NamePool` | `getNamePool()` Get the name pool used for the names in this document
    `int` | `getNodeKind()` Get the kind of node.
    `NodeInfo` | `getParent()` Get the NodeInfo object representing the parent of this node
    `String` | `getPrefix()` Get the prefix of the name of the node.
    `NodeInfo` | `getRoot()` Get the root node of the tree containing this node
    `int` | `getSiblingPosition()` Get the index position of this node among its siblings (starting from 0)
    `String` | `getSystemId()` Get the System ID for the node.
    `int` | `getTypeAnnotation()` Get the type annotation of this node, if any.
    `String[]` | `getUnparsedEntity(String name)` Get the unparsed entity with a given name
    `Iterator<String>` | `getUnparsedEntityNames()` Get the list of unparsed entities defined in this document
    `String` | `getURI()` Get the URI part of the name of this node.
    `Object` | `getUserData(String key)` Get user data held in the document node.
    `boolean` | `isSameNodeInfo(NodeInfo other)` Determine whether this is the same node as another node.
    `boolean` | `isTyped()` Ask whether the document contains any nodes whose type annotation is anything other than UNTYPED
    `protected AxisIterator<NodeInfo>` | `iterateAttributes(NodeTest nodeTest)` Return an iterator over the attributes of this element node.
    `protected AxisIterator<NodeInfo>` | `iterateSiblings(NodeTest nodeTest, boolean forwards)` Return an iterator over the siblings of this node.
    `protected static NodeInfo` | `makeWrapper(org.apache.axiom.om.OMNode node, AxiomDocumentWrapper docWrapper, AxiomParentNodeWrapper parent, int index)` Factory method to wrap an Axiom node with a wrapper that implements the Saxon NodeInfo interface.
    `NodeInfo` | `selectID(String id, boolean getParent)` Get the element with a given ID, if any
    `void` | `setConfiguration(Configuration config)` Set the configuration, which defines the name pool used for all names in this document.
    `void` | `setSystemId(String systemId)` Set the system identifier for this Source.
    `void` | `setUserData(String key, Object value)` Set user data on the document node.
    `NodeInfo` | `wrap(org.apache.axiom.om.OMNode node)` Wrap a node in the Axiom document.
    `NodeInfo` | `wrap(org.apache.axiom.om.OMNode node, AxiomParentNodeWrapper parent, int index)` Wrap a node whose parent and sibling position are known in the Axiom document.

    - ### Methods inherited from class net.sf.saxon.option.axiom.AxiomParentNodeWrapper

      `atomize, generateId, getStringValueCS, getUnderlyingNode, hasChildNodes, iterateChildren, iterateDescendants`

    - ### Methods inherited from class net.sf.saxon.tree.wrapper.AbstractNodeWrapper

      `comparePosition, copy, equals, getAttributeValue, getColumnNumber, getDeclaredNamespaces, getLineNumber, getRealNode, getSchemaType, getStringValue, hashCode, head, isId, isIdref, isNilled, iterate, iterateAxis, iterateAxis`

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

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.om.NodeInfo

      `atomize, comparePosition, copy, equals, generateId, getAttributeValue, getColumnNumber, getDeclaredNamespaces, getLineNumber, getSchemaType, getStringValue, hasChildNodes, hashCode, isId, isIdref, isNilled, iterateAxis, iterateAxis`

    - ### Methods inherited from interface net.sf.saxon.om.Item

      `getStringValueCS`

    - ### Methods inherited from interface net.sf.saxon.om.Sequence

      `head, iterate`

- - ### Field Detail

    - #### config

          protected Configuration config

    - #### baseURI

          protected String baseURI

    - #### documentNumber

          protected long documentNumber

  - ### Constructor Detail

    - #### AxiomDocumentWrapper

          public AxiomDocumentWrapper(org.apache.axiom.om.OMDocument root,
                              String baseURI,
                              Configuration config)

      Create a Saxon wrapper for an Axiom document node
      Parameters:
        `root` - The Axiom root node
        `baseURI` - The base URI for all the nodes in the tree
        `config` - The configuration which defines the name pool used for all names in this tree

  - ### Method Detail

    - #### wrap

          public NodeInfo wrap(org.apache.axiom.om.OMNode node)

      Wrap a node in the Axiom document.
      Parameters:
        `node` - The node to be wrapped. This must be a node in the same document (the system does not check for this).
      Returns:
        the wrapping NodeInfo object

    - #### wrap

          public NodeInfo wrap(org.apache.axiom.om.OMNode node,
                      AxiomParentNodeWrapper parent,
                      int index)

      Wrap a node whose parent and sibling position are known in the Axiom document.
      Parameters:
        `node` - The node to be wrapped. This must be a node in the same document (the system does not check for this).
        `parent` - the (wrapper of the) parent node; null if unknown
        `index` - the position of this node among its siblings; -1 if unknown
      Returns:
        the wrapping NodeInfo object

    - #### makeWrapper

          protected static NodeInfo makeWrapper(org.apache.axiom.om.OMNode node,
                             AxiomDocumentWrapper docWrapper,
                             AxiomParentNodeWrapper parent,
                             int index)

      Factory method to wrap an Axiom node with a wrapper that implements the Saxon NodeInfo interface.
      Parameters:
        `node` - The Axiom node (an element, text, processing-instruction, or comment node)
        `docWrapper` - The wrapper for the Document containing this node
        `parent` - The wrapper for the parent of the Axiom node. May be null if not known.
        `index` - The position of this node relative to its siblings. May be -1 if not known
      Returns:
        The new wrapper for the supplied node

    - #### setConfiguration

          public void setConfiguration(Configuration config)

      Set the configuration, which defines the name pool used for all names in this document. This is always called after a new document has been created. The implementation must register the name pool with the document, so that it can be retrieved using getNamePool(). It must also call NamePool.allocateDocumentNumber(), and return the relevant document number when getDocumentNumber() is subsequently called.
      Parameters:
        `config` - The configuration to be used

    - #### getConfiguration

          public Configuration getConfiguration()

      Get the configuration previously set using setConfiguration
      Specified by:
        `getConfiguration` in interface `NodeInfo`
      Overrides:
        `getConfiguration` in class `AbstractNodeWrapper`
      Returns:
        the Configuration

    - #### getNamePool

          public NamePool getNamePool()

      Get the name pool used for the names in this document
      Specified by:
        `getNamePool` in interface `NodeInfo`
      Overrides:
        `getNamePool` in class `AbstractNodeWrapper`
      Returns:
        the name pool in which all the names used in this document are registered

    - #### isTyped

          public boolean isTyped()

      Ask whether the document contains any nodes whose type annotation is anything other than UNTYPED
      Specified by:
        `isTyped` in interface `DocumentInfo`
      Returns:
        true if the document contains elements whose type is other than UNTYPED

    - #### getDocumentNumber

          public long getDocumentNumber()

      Get the unique document number for this document (the number is unique for all documents within a NamePool)
      Specified by:
        `getDocumentNumber` in interface `NodeInfo`
      Overrides:
        `getDocumentNumber` in class `AbstractNodeWrapper`
      Returns:
        the unique number identifying this document within the name pool

    - #### getSiblingPosition

          public int getSiblingPosition()

      Get the index position of this node among its siblings (starting from 0)
      Specified by:
        `getSiblingPosition` in interface `SiblingCountingNode`
      Returns:
        0 for the first child, 1 for the second child, etc.

    - #### getNameCode

          public int getNameCode()

      Get name code. The name code is a coded form of the node name: two nodes with the same name code have the same namespace URI, the same local name, and the same prefix. By masking the name code with &0xfffff, you get a fingerprint: two nodes with the same fingerprint have the same local name and namespace URI.
      Specified by:
        `getNameCode` in interface `NodeInfo`
      Overrides:
        `getNameCode` in class `AbstractNodeWrapper`
      Returns:
        an integer name code, which may be used to obtain the actual node name from the name pool. For unnamed nodes (text nodes, comments, document nodes, and namespace nodes for the default namespace), returns -1.
      See Also:
        `allocate`

    - #### getNodeKind

          public int getNodeKind()

      Get the kind of node. This will be a value such as `Type.ELEMENT` or `Type.ATTRIBUTE`. There are seven kinds of node: documents, elements, attributes, text, comments, processing-instructions, and namespaces.
      Specified by:
        `getNodeKind` in interface `NodeInfo`
      Returns:
        an integer identifying the kind of node. These integer values are the same as those used in the DOM
      Since:
        8.4
      See Also:
        `Type`

    - #### isSameNodeInfo

          public boolean isSameNodeInfo(NodeInfo other)

      Determine whether this is the same node as another node.

      Note that two different NodeInfo instances can represent the same conceptual node. Therefore the "==" operator should not be used to test node identity. The equals() method should give the same result as isSameNodeInfo(), but since this rule was introduced late it might not apply to all implementations.

      Note: a.isSameNodeInfo(b) if and only if generateId(a)==generateId(b).

      This method has the same semantics as isSameNode() in DOM Level 3, but works on Saxon NodeInfo objects rather than DOM Node objects.
      Specified by:
        `isSameNodeInfo` in interface `NodeInfo`
      Overrides:
        `isSameNodeInfo` in class `AbstractNodeWrapper`
      Parameters:
        `other` - the node to be compared with this node
      Returns:
        true if this NodeInfo object and the supplied NodeInfo object represent the same node in the tree.

    - #### getBaseURI

          public String getBaseURI()

      Get the Base URI for the node, that is, the URI used for resolving a relative URI contained in the node.
      Specified by:
        `getBaseURI` in interface `NodeInfo`
      Overrides:
        `getBaseURI` in class `AbstractNodeWrapper`
      Returns:
        the base URI of the node, taking into account xml:base attributes if present

    - #### getSystemId

          public String getSystemId()

      Get the System ID for the node. Note this is not the same as the base URI: the base URI can be modified by xml:base, but the system ID cannot. The base URI is used primarily for resolving relative URIs within the content of the document. The system ID is used primarily in conjunction with a line number, for identifying the location of elements within the source XML, in particular when errors are found. For a document node, the System ID represents the value of the document-uri property as defined in the XDM data model.
      Specified by:
        `getSystemId` in interface `Source`
      Specified by:
        `getSystemId` in interface `NodeInfo`
      Overrides:
        `getSystemId` in class `AbstractNodeWrapper`
      Returns:
        the System Identifier of the entity in the source document containing the node, or null if not known or not applicable.
      Since:
        8.4

    - #### setSystemId

          public void setSystemId(String systemId)

      Set the system identifier for this Source.

      The system identifier is optional if the source does not get its data from a URL, but it may still be useful to provide one. The application can use a system identifier, for example, to resolve relative URIs and to include in error messages and warnings.

      Specified by:
        `setSystemId` in interface `Source`
      Overrides:
        `setSystemId` in class `AbstractNodeWrapper`
      Parameters:
        `systemId` - The system identifier as a URL string.

    - #### getFingerprint

          public int getFingerprint()

      Get fingerprint. The fingerprint is a coded form of the expanded name of the node: two nodes with the same name code have the same namespace URI and the same local name. A fingerprint of -1 should be returned for a node with no name.
      Specified by:
        `getFingerprint` in interface `NodeInfo`
      Overrides:
        `getFingerprint` in class `AbstractNodeWrapper`
      Returns:
        an integer fingerprint; two nodes with the same fingerprint have the same expanded QName. For unnamed nodes (text nodes, comments, document nodes, and namespace nodes for the default namespace), returns -1.

    - #### getParent

          public NodeInfo getParent()

      Get the NodeInfo object representing the parent of this node
      Specified by:
        `getParent` in interface `NodeInfo`
      Returns:
        the parent of this node; null if this node has no parent

    - #### getLocalPart

          public String getLocalPart()

      Get the local part of the name of this node. This is the name after the ":" if any.
      Specified by:
        `getLocalPart` in interface `NodeInfo`
      Returns:
        the local part of the name. For an unnamed node, returns "".

    - #### getPrefix

          public String getPrefix()

      Get the prefix of the name of the node. This is defined only for elements and attributes. If the node has no prefix, or for other kinds of node, return a zero-length string.
      Specified by:
        `getPrefix` in interface `NodeInfo`
      Returns:
        The prefix of the name of the node.

    - #### getURI

          public String getURI()

      Get the URI part of the name of this node. This is the URI corresponding to the prefix, or the URI of the default namespace if appropriate.
      Specified by:
        `getURI` in interface `NodeInfo`
      Returns:
        The URI of the namespace of this node. For an unnamed node, or for a node with an empty prefix, return an empty string.

    - #### getDisplayName

          public String getDisplayName()

      Get the display name of this node. For elements and attributes this is [prefix:]localname. For unnamed nodes, it is an empty string.
      Specified by:
        `getDisplayName` in interface `NodeInfo`
      Overrides:
        `getDisplayName` in class `AbstractNodeWrapper`
      Returns:
        The display name of this node. For a node with no name, return an empty string.

    - #### getRoot

          public NodeInfo getRoot()

      Get the root node of the tree containing this node
      Specified by:
        `getRoot` in interface `NodeInfo`
      Overrides:
        `getRoot` in class `AbstractNodeWrapper`
      Returns:
        the NodeInfo representing the top-level ancestor of this node. This will not necessarily be a document node. If this node has no parent, then the method returns this node.
      Since:
        8.4

    - #### iterateAttributes

          protected AxisIterator<NodeInfo> iterateAttributes(NodeTest nodeTest)

      Description copied from class: `AbstractNodeWrapper`
      Return an iterator over the attributes of this element node. This method is only called after checking that the node is an element.
      Specified by:
        `iterateAttributes` in class `AbstractNodeWrapper`
      Parameters:
        `nodeTest` - a test that the returned attributes must satisfy
      Returns:
        an iterator over the attribute nodes. The order of the result, although arbitrary, must be consistent with document order.

    - #### iterateSiblings

          protected AxisIterator<NodeInfo> iterateSiblings(NodeTest nodeTest,
                                               boolean forwards)

      Description copied from class: `AbstractNodeWrapper`
      Return an iterator over the siblings of this node. This method is only called after checking that the node is an element, text, comment, or PI node.
      Specified by:
        `iterateSiblings` in class `AbstractNodeWrapper`
      Parameters:
        `nodeTest` - a test that the returned siblings must satisfy
        `forwards` - true for following siblings, false for preceding siblings
      Returns:
        an iterator over the sibling nodes, in axis order.

    - #### getDocumentRoot

          public DocumentInfo getDocumentRoot()

      Get the root node, if it is a document node.
      Specified by:
        `getDocumentRoot` in interface `NodeInfo`
      Returns:
        the DocumentInfo representing the containing document. If this node is part of a tree that does not have a document node as its root, returns null.
      Since:
        8.4

    - #### selectID

          public NodeInfo selectID(String id,
                          boolean getParent)

      Get the element with a given ID, if any
      Specified by:
        `selectID` in interface `DocumentInfo`
      Parameters:
        `id` - the required ID value
        `getParent` - true if the parent of the selected node is required (for element-with-id)
      Returns:
        the element with the given ID, or null if there is no such ID present (or if the parser has not notified attributes as being of type ID).

    - #### getUnparsedEntityNames

          public Iterator<String> getUnparsedEntityNames()

      Get the list of unparsed entities defined in this document
      Specified by:
        `getUnparsedEntityNames` in interface `DocumentInfo`
      Returns:
        an Iterator, whose items are of type String, containing the names of all unparsed entities defined in this document. If there are no unparsed entities or if the information is not available then an empty iterator is returned

    - #### getUnparsedEntity

          public String[] getUnparsedEntity(String name)

      Get the unparsed entity with a given name
      Specified by:
        `getUnparsedEntity` in interface `DocumentInfo`
      Parameters:
        `name` - the name of the entity
      Returns:
        null: Axiom does not provide access to unparsed entities

    - #### getTypeAnnotation

          public int getTypeAnnotation()

      Get the type annotation of this node, if any. Returns -1 for kinds of nodes that have no annotation, and for elements annotated as untyped, and attributes annotated as untypedAtomic.
      Specified by:
        `getTypeAnnotation` in interface `NodeInfo`
      Overrides:
        `getTypeAnnotation` in class `AbstractNodeWrapper`
      Returns:
        the type annotation of the node.
      See Also:
        `Type`

    - #### setUserData

          public void setUserData(String key,
                         Object value)

      Set user data on the document node. The user data can be retrieved subsequently using `getUserData(java.lang.String)`
      Specified by:
        `setUserData` in interface `DocumentInfo`
      Parameters:
        `key` - A string giving the name of the property to be set. Clients are responsible for choosing a key that is likely to be unique. Must not be null. Keys used internally by Saxon are prefixed "saxon:".
        `value` - The value to be set for the property. May be null, which effectively removes the existing value for the property.

    - #### getUserData

          public Object getUserData(String key)

      Get user data held in the document node. This retrieves properties previously set using `setUserData(java.lang.String, java.lang.Object)`
      Specified by:
        `getUserData` in interface `DocumentInfo`
      Parameters:
        `key` - A string giving the name of the property to be retrieved.
      Returns:
        the value of the property, or null if the property has not been defined.

    - #### compareOrder

          public int compareOrder(NodeInfo other)

      Determine the relative position of this node and another node, in document order. The other node will always be in the same document.
      Specified by:
        `compareOrder` in interface `NodeInfo`
      Parameters:
        `other` - The other node, whose position is to be compared with this node
      Returns:
        -1 if this node precedes the other node, +1 if it follows the other node, or 0 if they are the same node. (In this case, isSameNode() will always return true, and the two nodes will produce the same result for generateId())

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.