@Override public final DocumentInfo getDocumentRoot() { // TODO : 2 modes adoption mode, natural mode. XmlObject xmlObjectBaseRoot = xmlObjectNode.getXmlObjectBaseRoot(); return new XmlObjectDocumentInfo(xmlObjectBaseRoot, configuration); }
@Override public final String getBaseURI() { URI baseURI = xmlObjectNode.getXmlObjectBaseURI(); return baseURI == null ? null : baseURI.toString(); }
private void appendXmlObjectDescendants(XmlObjectNode xo, List<XmlObjectNode> result, IdentityHashMap<XmlObjectNode, Object> descendantsMap) { XmlObjectNode[] children = xo.getXmlObjectChildren(); for (XmlObjectNode child : children) { if (descendantsMap.containsKey(child)) continue; descendantsMap.put(child, null); result.add(child); appendXmlObjectDescendants(child, result, descendantsMap); } }
@Override public final XmlObject getXmlObjectRoot() { XmlObject parent; XmlObjectNode current = this; while (true) { parent = current.getXmlObjectParent(); if (parent == null) return (XmlObject) current; current = parent; } }
static AxisIterator createAncestorAxisIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> ancestors = wrapXmlObjectsAsNodeInfos( xmlObjectNode.getXmlObjectAncestors(), nodeTest, configuration); return new ReverseNodeArrayIterator(ancestors.toArray(new NodeInfo[ancestors.size()]), 0, ancestors.size()); }
static AxisIterator createDescendantIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> descendants = wrapXmlObjectsAsNodeInfos( xmlObjectNode.getXmlObjectDescendants(), nodeTest, configuration); return new NodeArrayIterator(descendants.toArray(new NodeInfo[descendants.size()])); }
@Override public final int compareTo(XmlObjectNode other) { Integer[] indexes = getXmlObjectBaseIndexes(); Integer[] otherIndexes = other.getXmlObjectBaseIndexes(); for (int i = 0; i < indexes.length; ++i) { int index = indexes[i]; if (otherIndexes.length == i) { // other is inferior because path is shorter. return 1; } int otherIndex = otherIndexes[i]; if (otherIndex < index) { return 1; } if (index < otherIndex) { return -1; } } if (otherIndexes.length > indexes.length) { return -1; } return 0; }
@Override public final int compareOrder(NodeInfo other) { assert other instanceof XmlObjectNodeNodeInfo; return this.getXmlObjectNode().compareTo(((XmlObjectNodeNodeInfo) other).getXmlObjectNode()); }
static AxisIterator createFollowingIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> following = wrapXmlObjectsAsNodeInfos( xmlObjectNode.getXmlObjectFollowing(), nodeTest, configuration); return new NodeArrayIterator(following.toArray(new NodeInfo[following.size()])); }
static AxisIterator createFollowingSiblingAxisIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> followingSiblings = wrapXmlObjectsAsNodeInfos( xmlObjectNode.getXmlObjectFollowingSiblings(), nodeTest, configuration); return new NodeArrayIterator(followingSiblings.toArray(new NodeInfo[followingSiblings.size()])); }
@Override public final XmlObject[] getXmlObjectAncestors() { LinkedList<XmlObject> ancestors = new LinkedList<XmlObject>(); XmlObjectNode current = this; XmlObject parent = null; while (true) { parent = current.getXmlObjectParent(); if (parent == null) break; ancestors.addFirst(parent); current = parent; } return ancestors.toArray(new XmlObject[ancestors.size()]); }
static AxisIterator createAncestorOrSelfAxisIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> ancestorsOrSelf = wrapXmlObjectsAsNodeInfos( xmlObjectNode.getXmlObjectAncestors(), nodeTest, configuration); ancestorsOrSelf.add(wrapXmlObjectAsNodeInfo(xmlObjectNode, configuration)); return new ReverseNodeArrayIterator(ancestorsOrSelf.toArray(new NodeInfo[ancestorsOrSelf.size()]), 0, ancestorsOrSelf.size()); }
static AxisIterator createDescendantOrSelfIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> descendantsOrSelf = wrapXmlObjectsAsNodeInfos( xmlObjectNode.getXmlObjectDescendants(), nodeTest, configuration); descendantsOrSelf.add(wrapXmlObjectAsNodeInfo(xmlObjectNode, configuration)); return new NodeArrayIterator(descendantsOrSelf.toArray(new NodeInfo[descendantsOrSelf.size()])); }
@Override public final NodeInfo getParent() { XmlObject parent = xmlObjectNode.getXmlObjectParent(); if (parent == null) return null; return new XmlObjectNodeInfo(parent, configuration); }
private void appendXmlObjectDescendants(XmlObjectNode xo, List<XmlObjectNode> result, IdentityHashMap<XmlObjectNode, Object> descendantsMap) { XmlObjectNode[] children = xo.getXmlObjectChildren(); for (XmlObjectNode child : children) { if (descendantsMap.containsKey(child)) continue; descendantsMap.put(child, null); result.add(child); appendXmlObjectDescendants( child, result, descendantsMap); } }
@Override public final XmlObject getXmlObjectBaseRoot() { XmlObject parent; URI currentURI; XmlObjectNode current = this; while (true) { parent = current.getXmlObjectParent(); if (parent == null) { return (XmlObject) current; } currentURI = getXmlObjectBaseURI(); if ((currentURI != null) && (!currentURI.equals(parent.getXmlObjectBaseURI()))) { return (XmlObject) current; } current = parent; } }
static AxisIterator createChildIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { Deque<NodeInfo> children = wrapXmlObjectsAsNodeInfos(xmlObjectNode.getXmlObjectChildren(), nodeTest, configuration); return new NodeArrayIterator(children.toArray(new NodeInfo[children.size()])); }
static AxisIterator createParentAxisIterator(XmlObjectNode xmlObjectNode, NodeTest nodeTest, Configuration configuration) { XmlObject parent = xmlObjectNode.getXmlObjectParent(); if (parent == null) return createEmptyAxisIterator(); XmlObjectNodeNodeInfo parentNodeInfo = wrapXmlObjectAsNodeInfo(parent, configuration); if (!nodeTest.matches(parentNodeInfo)) return createEmptyAxisIterator(); return SingleNodeIterator.makeIterator(parentNodeInfo); }