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

Examples of org.apache.commons.jxpath.ri.model.NodeIterator


     * @return boolean
     */
    private boolean isRecursive() {
        Object node = currentNodePointer.getNode();
        for (int i = stack.size() - 1; --i >= 0;) {
            NodeIterator it = (NodeIterator) stack.get(i);
            Pointer pointer = it.getNodePointer();
            if (pointer != null && pointer.getNode() == node) {
                return true;
            }
        }
        return false;
View Full Code Here


            Attribute attr = element.getAttribute(name.getName());
            if (attr == null) {
                element.setAttribute(name.getName(), "");
            }
        }
        NodeIterator it = attributeIterator(name);
        it.setPosition(1);
        return it.getNodePointer();
    }
View Full Code Here

        NodePointer ptr = (NodePointer) pointer.clone();
        int length = ptr.getLength();
        for (int i = 0; i < length; i++) {
            ptr.setIndex(i);
            NodePointer elementPointer = ptr.getValuePointer();
            NodeIterator iter = getElementNodeIterator(elementPointer);

            for (int j = 1; iter.setPosition(j); j++) {
                NodePointer childPointer = iter.getNodePointer();
                if (reverse) {
                    collection.add(0, childPointer);
                }
                else {
                    collection.add(childPointer);
View Full Code Here

                name = (QName)property;
            }
            else {
                name = new QName(null, (String)property);
            }
            NodeIterator it = parent.childIterator(new NodeNameTest(name), false, null);
            if (it != null && it.setPosition(index == -1 ? 1 : index + 1)){
                return it.getNodePointer();
            }
            else {
                PropertyPointer pointer = new NullPropertyPointer(parent);
                pointer.setPropertyName(name.toString());
                pointer.setIndex(index);
View Full Code Here

                }
            }
        }

        while (!stack.isEmpty()){
            NodeIterator it = (NodeIterator)stack.peek();
            if (it.setPosition(it.getPosition() + 1)){
                currentNodePointer = it.getNodePointer();
                if (!currentNodePointer.isLeaf()){
                    stack.push(currentNodePointer.childIterator(null, false, null));
                }
                if (currentNodePointer.testNode(nodeTest)){
                    position++;
View Full Code Here

        }
        if (!getAbstractFactory(context).createObject(context, this, node, name.toString(), index)){
            throw new JXPathException("Factory could not create a child node for path: " +
                    asPath() + "/" + name + "[" + (index+1) + "]");
        }
        NodeIterator it = childIterator(new NodeNameTest(name), false, null);
        if (it == null || !it.setPosition(index + 1)){
            throw new JXPathException("Factory could not create a child node for path: " +
                    asPath() + "/" + name + "[" + (index+1) + "]");
        }
        return it.getNodePointer();
    }
View Full Code Here

                }
            }

            while (!stack.isEmpty()){
                if (!reverse){
                    NodeIterator it = (NodeIterator)stack.peek();
                    if (it.setPosition(it.getPosition() + 1)){
                        currentNodePointer = it.getNodePointer();
                        if (!currentNodePointer.isLeaf()){
                            stack.push(currentNodePointer.childIterator(null, reverse, null));
                        }
                        if (currentNodePointer.testNode(nodeTest)){
                            super.setPosition(getCurrentPosition() + 1);
                            return true;
                        }
                    }
                    else {
                        // We get here only if the name test failed and the iterator ended
                        stack.pop();
                    }
                }
                else {
                    NodeIterator it = (NodeIterator)stack.peek();
                    if (it.setPosition(it.getPosition() + 1)){
                        currentNodePointer = it.getNodePointer();
                        if (!currentNodePointer.isLeaf()){
                            stack.push(currentNodePointer.childIterator(null, reverse, null));
                        }
                        else if (currentNodePointer.testNode(nodeTest)){
                            super.setPosition(getCurrentPosition() + 1);
                            return true;
                        }
                    }
                    else {
                        stack.pop();
                        if (!stack.isEmpty()){
                            it = (PropertyIterator)stack.peek();
                            currentNodePointer = it.getNodePointer();
                            if (currentNodePointer.testNode(nodeTest)){
                                super.setPosition(getCurrentPosition() + 1);
                                return true;
                            }
                        }
View Full Code Here

     * @param p the node pointer to test
     */
    private void checkIterators(NodePointer p)
    {
        ConfigurationNode node = (ConfigurationNode) p.getNode();
        NodeIterator it = p.childIterator(null, false, null);
        assertEquals("Iterator count differs from children count", node
                .getChildrenCount(), iteratorSize(it));

        for (int index = 1; it.setPosition(index); index++)
        {
            NodePointer pchild = it.getNodePointer();
            assertEquals("Wrong child", node.getChild(index - 1), pchild
                    .getNode());
            checkIterators(pchild);
        }

        it = p.attributeIterator(new QName(null, "*"));
        assertEquals("Iterator count differs from attribute count", node
                .getAttributeCount(), iteratorSize(it));
        for (int index = 1; it.setPosition(index); index++)
        {
            NodePointer pattr = it.getNodePointer();
            assertTrue("Node pointer is no attribute", pattr.isAttribute());
            assertEquals("Wrong attribute", node.getAttribute(index - 1), pattr
                    .getNode());
            checkIterators(pattr);
        }
View Full Code Here

     * @param p the node pointer to test
     */
    private void checkIterators(NodePointer p)
    {
        ConfigurationNode node = (ConfigurationNode) p.getNode();
        NodeIterator it = p.childIterator(null, false, null);
        assertEquals("Iterator count differs from children count", node
                .getChildrenCount(), iteratorSize(it));

        for (int index = 1; it.setPosition(index); index++)
        {
            NodePointer pchild = it.getNodePointer();
            assertEquals("Wrong child", node.getChild(index - 1), pchild
                    .getNode());
            checkIterators(pchild);
        }

        it = p.attributeIterator(new QName(null, "*"));
        assertEquals("Iterator count differs from attribute count", node
                .getAttributeCount(), iteratorSize(it));
        for (int index = 1; it.setPosition(index); index++)
        {
            NodePointer pattr = it.getNodePointer();
            assertTrue("Node pointer is no attribute", pattr.isAttribute());
            assertEquals("Wrong attribute", node.getAttribute(index - 1), pattr
                    .getNode());
            checkIterators(pattr);
        }
View Full Code Here

            }
            else {
                nodeTest = new NodeNameTest(name);
            }

            NodeIterator it =
                childIterator(nodeTest, false, null);
            if (it != null && it.setPosition(index + 1)) {
                return it.getNodePointer();
            }
        }
        throw new JXPathException(
            "Factory could not create "
                + "a child node for path: "
View Full Code Here

TOP

Related Classes of org.apache.commons.jxpath.ri.model.NodeIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.