Java Code Examples for org.apache.commons.jxpath.ri.model.NodePointer#getNode()

The following examples show how to use org.apache.commons.jxpath.ri.model.NodePointer#getNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDOMNodeIterator.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new JDOMNodeIterator.
 * @param parent pointer
 * @param nodeTest test
 * @param reverse whether to iterate in reverse
 * @param startWith starting pointer
 */
public JDOMNodeIterator(
        NodePointer parent, NodeTest nodeTest,
        boolean reverse, NodePointer startWith) {
    this.parent = parent;
    if (startWith != null) {
        this.child = startWith.getNode();
    }
    // TBD: optimize me for different node tests
    Object node = parent.getNode();
    if (node instanceof Document) {
        this.children = ((Document) node).getContent();
    }
    else if (node instanceof Element) {
        this.children = ((Element) node).getContent();
    }
    else {
        this.children = Collections.EMPTY_LIST;
    }
    this.nodeTest = nodeTest;
    this.reverse = reverse;
}
 
Example 2
Source File: TestConfigurationNodePointer.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Recursive helper method for testing the returned iterators.
 *
 * @param p the node pointer to test
 */
private void checkIterators(final NodePointer p)
{
    final ImmutableNode node = (ImmutableNode) p.getNode();
    NodeIterator it = p.childIterator(null, false, null);
    assertEquals("Iterator count differs from children count", node
            .getChildren().size(), iteratorSize(it));

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

    it = p.attributeIterator(new QName(null, "*"));
    assertEquals("Iterator count differs from attribute count", node
            .getAttributes().size(), iteratorSize(it));
    for (int index = 1; it.setPosition(index); index++)
    {
        final NodePointer pattr = it.getNodePointer();
        assertTrue("Node pointer is no attribute", pattr.isAttribute());
        assertTrue("Wrong attribute name", node.getAttributes()
                .containsKey(pattr.getName().getName()));
    }
}
 
Example 3
Source File: DOMNodeIterator.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new DOMNodeIterator.
 * @param parent parent pointer
 * @param nodeTest test
 * @param reverse whether to iterate in reverse
 * @param startWith starting pointer
 */
public DOMNodeIterator(
    NodePointer parent,
    NodeTest nodeTest,
    boolean reverse,
    NodePointer startWith) {
    this.parent = parent;
    this.node = (Node) parent.getNode();
    if (startWith != null) {
        this.child = (Node) startWith.getNode();
    }
    this.nodeTest = nodeTest;
    this.reverse = reverse;
}
 
Example 4
Source File: JDOMNamespaceIterator.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new JDOMNamespaceIterator.
 * @param parent the parent NodePointer.
 */
public JDOMNamespaceIterator(NodePointer parent) {
    this.parent = parent;
    Object node = parent.getNode();
    if (node instanceof Document) {
        node = ((Document) node).getRootElement();
    }
    if (node instanceof Element) {
        namespaces = new ArrayList();
        prefixes = new HashSet();
        collectNamespaces((Element) node);
    }
}