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

The following examples show how to use org.apache.commons.jxpath.ri.model.NodePointer#attributeIterator() . 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: SimplePathInterpreter.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
/**
 * Get a NodeIterator.
 * @param context evaluation context
 * @param pointer owning pointer
 * @param step triggering step
 * @return NodeIterator
 */
private static NodeIterator getNodeIterator(
    EvalContext context,
    NodePointer pointer,
    Step step) {
    if (step.getAxis() == Compiler.AXIS_CHILD) {
        NodeTest nodeTest = step.getNodeTest();
        QName qname = ((NodeNameTest) nodeTest).getNodeName();
        String prefix = qname.getPrefix();
        if (prefix != null) {
            String namespaceURI = context.getJXPathContext()
                    .getNamespaceURI(prefix);
            nodeTest = new NodeNameTest(qname, namespaceURI);
        }
        return pointer.childIterator(nodeTest, false, null);
    }
    // else Compiler.AXIS_ATTRIBUTE
    if (!(step.getNodeTest() instanceof NodeNameTest)) {
        throw new UnsupportedOperationException(
            "Not supported node test for attributes: "
                + step.getNodeTest());
    }
    return pointer.attributeIterator(
        ((NodeNameTest) step.getNodeTest()).getNodeName());
}
 
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: SimplePathInterpreter.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the pointer has an attribute called "name" and
 * its value is equal to the supplied string.
 * @param pointer input pointer
 * @param name name to check
 * @return boolean
 */
private static boolean isNameAttributeEqual(
    NodePointer pointer,
    String name) {
    NodeIterator it = pointer.attributeIterator(QNAME_NAME);
    return it != null
        && it.setPosition(1)
        && name.equals(it.getNodePointer().getValue());
}
 
Example 4
Source File: CollectionAttributeNodeIterator.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
protected NodeIterator getElementNodeIterator(NodePointer elementPointer) {
    return elementPointer.attributeIterator(name);
}