org.jaxen.ContextSupport - java examples

Here are the examples of the java api org.jaxen.ContextSupport taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

38 Examples 7

19 View Complete Implementation : DefaultAllNodeStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public boolean matches(Object node, ContextSupport contextSupport) {
    return true;
}

19 View Complete Implementation : DefaultStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator axisIterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return gereplacederableAxis().iterator(contextNode, support);
}

19 View Complete Implementation : IterableAncestorAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getAncestorAxisIterator(contextNode);
}

19 View Complete Implementation : IterableAncestorOrSelfAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getAncestorOrSelfAxisIterator(contextNode);
}

19 View Complete Implementation : IterableAttributeAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Gets an iterator for the attribute axis.
 *
 * @param contextNode  the current context node to work from
 * @param support  the additional context information
 */
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getAttributeAxisIterator(contextNode);
}

19 View Complete Implementation : IterableAttributeAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Does this axis support named access?
 *
 * @param support  the additional context information
 * @return true if named access is supported. If not iterator() will be used.
 */
public boolean supportsNamedAccess(ContextSupport support) {
    return (support.getNavigator() instanceof NamedAccessNavigator);
}

19 View Complete Implementation : IterableAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Gets the iterator for a specific XPath axis.
 *
 * @param contextNode  the current context node to work from
 * @param support  the additional context information
 * @return an iterator for the axis
 * @throws UnsupportedAxisException
 */
public abstract Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException;

19 View Complete Implementation : IterableAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Does this axis support named access?
 *
 * @param support  the additional context information
 * @return true if named access supported. If not iterator() will be used
 */
public boolean supportsNamedAccess(ContextSupport support) {
    return false;
}

19 View Complete Implementation : IterableAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Gets the iterator for a specific XPath axis that supports named access.
 *
 * @param contextNode  the current context node to work from
 * @param support  the additional context information
 * @param localName  the local name of the nodes to return
 * @param namespacePrefix  the prefix of the namespace of the nodes to return
 * @param namespaceURI  the URI of the namespace of the nodes to return
 */
public Iterator namedAccessIterator(Object contextNode, ContextSupport support, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException {
    throw new UnsupportedOperationException("Named access unsupported");
}

19 View Complete Implementation : IterableChildAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Gets the iterator for the child axis.
 *
 * @param contextNode  the current context node to work from
 * @param support  the additional context information
 * @return an iterator over the children of the context node
 * @throws UnsupportedAxisException if the child axis is not supported
 */
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getChildAxisIterator(contextNode);
}

19 View Complete Implementation : IterableChildAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Does this axis support named access?
 *
 * @param support the additional context information
 * @return true if named access supported. If not iterator() will be used
 */
public boolean supportsNamedAccess(ContextSupport support) {
    return (support.getNavigator() instanceof NamedAccessNavigator);
}

19 View Complete Implementation : IterableDescendantAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getDescendantAxisIterator(contextNode);
}

19 View Complete Implementation : IterableDescendantOrSelfAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getDescendantOrSelfAxisIterator(contextNode);
}

19 View Complete Implementation : IterableFollowingAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getFollowingAxisIterator(contextNode);
}

19 View Complete Implementation : IterableFollowingSiblingAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getFollowingSiblingAxisIterator(contextNode);
}

19 View Complete Implementation : IterableNamespaceAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getNamespaceAxisIterator(contextNode);
}

19 View Complete Implementation : IterableParentAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getParentAxisIterator(contextNode);
}

19 View Complete Implementation : IterablePrecedingAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getPrecedingAxisIterator(contextNode);
}

19 View Complete Implementation : IterablePrecedingSiblingAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getPrecedingSiblingAxisIterator(contextNode);
}

19 View Complete Implementation : IterableSelfAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
    return support.getNavigator().getSelfAxisIterator(contextNode);
}

18 View Complete Implementation : DefaultCommentNodeStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public boolean matches(Object node, ContextSupport contextSupport) {
    Navigator nav = contextSupport.getNavigator();
    return nav.isComment(node);
}

18 View Complete Implementation : PredicateSet.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * <p>Returns true if any of the supplied nodes satisfy
 * all the predicates in the set. Returns false if none of the supplied
 * nodes matches all the predicates in the set. Returns false if the
 * node-set is empty.</p>
 *
 * @param contextNodeSet the nodes to test against these predicates
 * @param support ????
 * @return true if any node in the contextNodeSet matches all the predicates
 * @throws JaxenException
 */
protected boolean evaluateAsBoolean(List contextNodeSet, ContextSupport support) throws JaxenException {
    return anyMatchingNode(contextNodeSet, support);
}

18 View Complete Implementation : ContextTest.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public clreplaced ContextTest extends TestCase {

    private List nodeSet;

    private ContextSupport support;

    public ContextTest(String name) {
        super(name);
    }

    public void setUp() {
        this.nodeSet = new ArrayList();
        this.nodeSet.add("one");
        this.nodeSet.add("two");
        this.nodeSet.add("three");
        this.nodeSet.add("four");
        this.support = new ContextSupport();
    }

    public void tearDown() {
        this.nodeSet = null;
    }

    public void testSetNodeSet() {
        Context original = new Context(this.support);
        replacedertEquals(0, original.getNodeSet().size());
        original.setNodeSet(this.nodeSet);
        replacedertEquals(4, original.getNodeSet().size());
    }

    public void testShrinkNodeSet() {
        Context original = new Context(this.support);
        original.setNodeSet(this.nodeSet);
        original.setPosition(3);
        ArrayList list = new ArrayList();
        list.add("1");
        list.add("2");
        list.add("3");
        original.setNodeSet(list);
        replacedertEquals(0, original.getPosition());
    }

    public void testDuplicate() {
        Context original = new Context(this.support);
        original.setNodeSet(this.nodeSet);
        original.setSize(4);
        original.setPosition(2);
        Context dupe = original.duplicate();
        replacedertEquals(2, dupe.getPosition());
        replacedertEquals(4, dupe.getSize());
        replacedertTrue(original != dupe);
        List dupeNodeSet = dupe.getNodeSet();
        replacedertTrue(original.getNodeSet() != dupe.getNodeSet());
        dupeNodeSet.clear();
        replacedertSame(dupeNodeSet, dupe.getNodeSet());
        replacedertEquals(0, dupe.getNodeSet().size());
        replacedertEquals(4, original.getNodeSet().size());
        dupe.setSize(0);
        dupe.setPosition(0);
        replacedertEquals(0, dupe.getSize());
        replacedertEquals(0, dupe.getPosition());
        replacedertEquals(4, original.getSize());
        replacedertEquals(2, original.getPosition());
    }

    public void testXMLPrefixIsAlwaysBound() throws ParserConfigurationException, SAXException, IOException, JaxenException {
        DoreplacedentBuilderFactory factory = DoreplacedentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DoreplacedentBuilder builder = factory.newDoreplacedentBuilder();
        Doreplacedent doc = builder.parse("xml/basic.xml");
        Element root = doc.getDoreplacedentElement();
        root.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en");
        XPath xpath = new DOMXPath("/*/@xml:lang");
        List result = xpath.selectNodes(doc);
        replacedertEquals(1, result.size());
    }

    public void testIsSerializable() throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(support);
        oos.close();
        replacedertTrue(out.toByteArray().length > 0);
    }
}

18 View Complete Implementation : YangFunctionContext.java
Copyright Eclipse Public License 1.0
Author : opendaylight
private static SchemaContext getSchemaContext(final NormalizedNodeContext normalizedNodeContext) {
    final ContextSupport contextSupport = normalizedNodeContext.getContextSupport();
    verify(contextSupport instanceof NormalizedNodeContextSupport, "Unhandled context support %s", contextSupport.getClreplaced());
    return ((NormalizedNodeContextSupport) contextSupport).getSchemaContext();
}

17 View Complete Implementation : DefaultTextNodeStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public boolean matches(Object node, ContextSupport support) {
    Navigator nav = support.getNavigator();
    return nav.isText(node);
}

17 View Complete Implementation : IterableAttributeAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Gets the iterator for the attribute axis that supports named access.
 *
 * @param contextNode  the current context node to work from
 * @param support  the additional context information
 * @param localName  the local name of the attributes to return
 * @param namespacePrefix  the prefix of the namespace of the attributes to return
 * @param namespaceURI  the uri of the namespace of the attributes to return
 */
public Iterator namedAccessIterator(Object contextNode, ContextSupport support, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException {
    NamedAccessNavigator nav = (NamedAccessNavigator) support.getNavigator();
    return nav.getAttributeAxisIterator(contextNode, localName, namespacePrefix, namespaceURI);
}

17 View Complete Implementation : IterableChildAxis.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Gets an iterator for the child XPath axis that supports named access.
 *
 * @param contextNode  the current context node to work from
 * @param support  the additional context information
 * @param localName  the local name of the children to return
 * @param namespacePrefix  the prefix of the namespace of the children to return
 * @param namespaceURI  the URI of the namespace of the children to return
 * @return an iterator over the children of the context node
 * @throws UnsupportedAxisException if the child axis is not supported by the model
 */
public Iterator namedAccessIterator(Object contextNode, ContextSupport support, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException {
    NamedAccessNavigator nav = (NamedAccessNavigator) support.getNavigator();
    return nav.getChildAxisIterator(contextNode, localName, namespacePrefix, namespaceURI);
}

16 View Complete Implementation : DefaultProcessingInstructionNodeStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public boolean matches(Object node, ContextSupport support) {
    Navigator nav = support.getNavigator();
    if (nav.isProcessingInstruction(node)) {
        String name = getName();
        if (name == null || name.length() == 0) {
            return true;
        } else {
            return name.equals(nav.getProcessingInstructionTarget(node));
        }
    }
    return false;
}

15 View Complete Implementation : PredicateSet.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * <p>Returns all of the supplied nodes that satisfy
 * all the predicates in the set. </p>
 *
 * @param contextNodeSet the nodes to test against these predicates
 * @param support ????
 * @return all the nodes that match each of the predicates
 * @throws JaxenException
 */
protected List evaluatePredicates(List contextNodeSet, ContextSupport support) throws JaxenException {
    // Easy way out (necessary)
    if (predicates.size() == 0) {
        return contextNodeSet;
    }
    Iterator predIter = predicates.iterator();
    // initial list to filter
    List nodes2Filter = contextNodeSet;
    // apply all predicates
    while (predIter.hasNext()) {
        nodes2Filter = applyPredicate((Predicate) predIter.next(), nodes2Filter, support);
    }
    return nodes2Filter;
}

12 View Complete Implementation : DefaultLocationPath.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Object evaluate(Context context) throws JaxenException {
    List nodeSet = context.getNodeSet();
    List contextNodeSet = new ArrayList(nodeSet);
    ContextSupport support = context.getContextSupport();
    Context stepContext = new Context(support);
    Iterator stepIter = getSteps().iterator();
    while (stepIter.hasNext()) {
        Step eachStep = (Step) stepIter.next();
        stepContext.setNodeSet(contextNodeSet);
        contextNodeSet = eachStep.evaluate(stepContext);
        // now we need to reverse the list if this is a reverse axis
        if (isReverseAxis(eachStep)) {
            Collections.reverse(contextNodeSet);
        }
    }
    if (getSteps().size() > 1) {
        Collections.sort(contextNodeSet, new NodeComparator(support.getNavigator()));
    }
    return contextNodeSet;
}

12 View Complete Implementation : DefaultNameStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Checks whether the node matches this step.
 *
 * @param node  the node to check
 * @param contextSupport  the context support
 * @return true if matches
 * @throws JaxenException
 */
public boolean matches(Object node, ContextSupport contextSupport) throws JaxenException {
    Navigator nav = contextSupport.getNavigator();
    String myUri = null;
    String nodeName = null;
    String nodeUri = null;
    if (nav.isElement(node)) {
        nodeName = nav.getElementName(node);
        nodeUri = nav.getElementNamespaceUri(node);
    } else if (nav.isText(node)) {
        return false;
    } else if (nav.isAttribute(node)) {
        if (getAxis() != Axis.ATTRIBUTE) {
            return false;
        }
        nodeName = nav.getAttributeName(node);
        nodeUri = nav.getAttributeNamespaceUri(node);
    } else if (nav.isDoreplacedent(node)) {
        return false;
    } else if (nav.isNamespace(node)) {
        if (getAxis() != Axis.NAMESPACE) {
            // Only works for namespace::*
            return false;
        }
        nodeName = nav.getNamespacePrefix(node);
    } else {
        return false;
    }
    if (hasPrefix) {
        myUri = contextSupport.translateNamespacePrefixToUri(this.prefix);
        if (myUri == null) {
            throw new UnresolvableException("Cannot resolve namespace prefix '" + this.prefix + "'");
        }
    } else if (matchesAnyName) {
        return true;
    }
    // If we map to a non-empty namespace and the node does not
    // or vice-versa, fail-fast.
    if (hasNamespace(myUri) != hasNamespace(nodeUri)) {
        return false;
    }
    // To fail-fast, we check the equality of
    // local-names first.  Shorter strings compare
    // quicker.
    if (matchesAnyName || nodeName.equals(getLocalName())) {
        return matchesNamespaceURIs(myUri, nodeUri);
    }
    return false;
}

12 View Complete Implementation : DefaultLocationPath.java
Copyright MIT License
Author : archimatetool
public Object evaluate(Context context) throws JaxenException {
    List nodeSet = context.getNodeSet();
    List contextNodeSet = new ArrayList(nodeSet);
    ContextSupport support = context.getContextSupport();
    Context stepContext = new Context(support);
    Iterator stepIter = getSteps().iterator();
    while (stepIter.hasNext()) {
        Step eachStep = (Step) stepIter.next();
        stepContext.setNodeSet(contextNodeSet);
        contextNodeSet = eachStep.evaluate(stepContext);
        // now we need to reverse the list if this is a reverse axis
        if (isReverseAxis(eachStep)) {
            Collections.reverse(contextNodeSet);
        }
    }
    if (getSteps().size() > 1 || nodeSet.size() > 1) {
        Collections.sort(contextNodeSet, new NodeComparator(support.getNavigator()));
    }
    return contextNodeSet;
}

11 View Complete Implementation : DefaultAbsoluteLocationPath.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public Object evaluate(Context context) throws JaxenException {
    ContextSupport support = context.getContextSupport();
    Navigator nav = support.getNavigator();
    Context absContext = new Context(support);
    List contextNodes = context.getNodeSet();
    if (contextNodes.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    Object firstNode = contextNodes.get(0);
    Object docNode = nav.getDoreplacedentNode(firstNode);
    if (docNode == null) {
        return Collections.EMPTY_LIST;
    }
    List list = new SingletonList(docNode);
    absContext.setNodeSet(list);
    return super.evaluate(absContext);
}

10 View Complete Implementation : PredicateSet.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public List applyPredicate(Predicate predicate, List nodes2Filter, ContextSupport support) throws JaxenException {
    final int nodes2FilterSize = nodes2Filter.size();
    List filteredNodes = new ArrayList(nodes2FilterSize);
    // Set up a dummy context with a list to hold each node
    Context predContext = new Context(support);
    List tempList = new ArrayList(1);
    predContext.setNodeSet(tempList);
    // loop through the current nodes to filter and add to the
    // filtered nodes list if the predicate succeeds
    for (int i = 0; i < nodes2FilterSize; ++i) {
        Object contextNode = nodes2Filter.get(i);
        tempList.clear();
        tempList.add(contextNode);
        predContext.setNodeSet(tempList);
        // ????
        predContext.setPosition(i + 1);
        predContext.setSize(nodes2FilterSize);
        Object predResult = predicate.evaluate(predContext);
        if (predResult instanceof Number) {
            // Here we replacedume nodes are in forward or reverse order
            // as appropriate for axis
            int proximity = ((Number) predResult).intValue();
            if (proximity == (i + 1)) {
                filteredNodes.add(contextNode);
            }
        } else {
            Boolean includes = BooleanFunction.evaluate(predResult, predContext.getNavigator());
            if (includes.booleanValue()) {
                filteredNodes.add(contextNode);
            }
        }
    }
    return filteredNodes;
}

9 View Complete Implementation : DefaultStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public List evaluate(final Context context) throws JaxenException {
    final List contextNodeSet = context.getNodeSet();
    final IdenreplacedySet unique = new IdenreplacedySet();
    final int contextSize = contextNodeSet.size();
    // ???? try linked lists instead?
    // ???? initial size for these?
    final ArrayList interimSet = new ArrayList();
    final ArrayList newNodeSet = new ArrayList();
    final ContextSupport support = context.getContextSupport();
    // ???? use iterator instead
    for (int i = 0; i < contextSize; ++i) {
        Object eachContextNode = contextNodeSet.get(i);
        /* See jaxen-106. Might be able to optimize this by doing
                 * specific matching for individual axes. For instance on namespace axis
                 * we should only get namespace nodes and on attribute axes we only get 
                 * attribute nodes. Self and parent axes have single members.
                 * Children, descendant, ancestor, and sibling axes never 
                 * see any attributes or namespaces
                 */
        Iterator axisNodeIter = axis.iterator(eachContextNode, support);
        while (axisNodeIter.hasNext()) {
            Object eachAxisNode = axisNodeIter.next();
            if (!unique.contains(eachAxisNode)) {
                if (matches(eachAxisNode, support)) {
                    unique.add(eachAxisNode);
                    interimSet.add(eachAxisNode);
                }
            }
        }
        newNodeSet.addAll(getPredicateSet().evaluatePredicates(interimSet, support));
        interimSet.clear();
    }
    return newNodeSet;
}

7 View Complete Implementation : PredicateSet.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private boolean anyMatchingNode(List contextNodeSet, ContextSupport support) throws JaxenException {
    // Easy way out (necessary)
    if (predicates.size() == 0) {
        return false;
    }
    Iterator predIter = predicates.iterator();
    // initial list to filter
    List nodes2Filter = contextNodeSet;
    // apply all predicates
    while (predIter.hasNext()) {
        final int nodes2FilterSize = nodes2Filter.size();
        // Set up a dummy context with a list to hold each node
        Context predContext = new Context(support);
        List tempList = new ArrayList(1);
        predContext.setNodeSet(tempList);
        // loop through the current nodes to filter and add to the
        // filtered nodes list if the predicate succeeds
        for (int i = 0; i < nodes2FilterSize; ++i) {
            Object contextNode = nodes2Filter.get(i);
            tempList.clear();
            tempList.add(contextNode);
            predContext.setNodeSet(tempList);
            // ????
            predContext.setPosition(i + 1);
            predContext.setSize(nodes2FilterSize);
            Object predResult = ((Predicate) predIter.next()).evaluate(predContext);
            if (predResult instanceof Number) {
                // Here we replacedume nodes are in forward or reverse order
                // as appropriate for axis
                int proximity = ((Number) predResult).intValue();
                if (proximity == (i + 1)) {
                    return true;
                }
            } else {
                Boolean includes = BooleanFunction.evaluate(predResult, predContext.getNavigator());
                if (includes.booleanValue()) {
                    return true;
                }
            }
        }
    }
    return false;
}

6 View Complete Implementation : DefaultNameStep.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Evaluate the context node set to find the new node set.
 * <p>
 * This method overrides the version in <code>DefaultStep</code> for performance.
 */
public List evaluate(Context context) throws JaxenException {
    List contextNodeSet = context.getNodeSet();
    int contextSize = contextNodeSet.size();
    // optimize for context size 0
    if (contextSize == 0) {
        return Collections.EMPTY_LIST;
    }
    ContextSupport support = context.getContextSupport();
    IterableAxis iterableAxis = gereplacederableAxis();
    boolean namedAccess = (!matchesAnyName && iterableAxis.supportsNamedAccess(support));
    // optimize for context size 1 (common case, avoids lots of object creation)
    if (contextSize == 1) {
        Object contextNode = contextNodeSet.get(0);
        if (namedAccess) {
            // get the iterator over the nodes and check it
            String uri = null;
            if (hasPrefix) {
                uri = support.translateNamespacePrefixToUri(prefix);
                if (uri == null) {
                    throw new UnresolvableException("XPath expression uses unbound namespace prefix " + prefix);
                }
            }
            Iterator axisNodeIter = iterableAxis.namedAccessIterator(contextNode, support, localName, prefix, uri);
            if (axisNodeIter == null || !axisNodeIter.hasNext()) {
                return Collections.EMPTY_LIST;
            }
            // convert iterator to list for predicate test
            // no need to filter as named access guarantees this
            List newNodeSet = new ArrayList();
            while (axisNodeIter.hasNext()) {
                newNodeSet.add(axisNodeIter.next());
            }
            // evaluate the predicates
            return getPredicateSet().evaluatePredicates(newNodeSet, support);
        } else {
            // get the iterator over the nodes and check it
            Iterator axisNodeIter = iterableAxis.iterator(contextNode, support);
            if (axisNodeIter == null || !axisNodeIter.hasNext()) {
                return Collections.EMPTY_LIST;
            }
            // run through iterator, filtering using matches()
            // adding to list for predicate test
            List newNodeSet = new ArrayList(contextSize);
            while (axisNodeIter.hasNext()) {
                Object eachAxisNode = axisNodeIter.next();
                if (matches(eachAxisNode, support)) {
                    newNodeSet.add(eachAxisNode);
                }
            }
            // evaluate the predicates
            return getPredicateSet().evaluatePredicates(newNodeSet, support);
        }
    }
    // full case
    IdenreplacedySet unique = new IdenreplacedySet();
    List interimSet = new ArrayList(contextSize);
    List newNodeSet = new ArrayList(contextSize);
    if (namedAccess) {
        String uri = null;
        if (hasPrefix) {
            uri = support.translateNamespacePrefixToUri(prefix);
            if (uri == null) {
                throw new UnresolvableException("XPath expression uses unbound namespace prefix " + prefix);
            }
        }
        for (int i = 0; i < contextSize; ++i) {
            Object eachContextNode = contextNodeSet.get(i);
            Iterator axisNodeIter = iterableAxis.namedAccessIterator(eachContextNode, support, localName, prefix, uri);
            if (axisNodeIter == null || !axisNodeIter.hasNext()) {
                continue;
            }
            while (axisNodeIter.hasNext()) {
                Object eachAxisNode = axisNodeIter.next();
                interimSet.add(eachAxisNode);
            }
            // evaluate the predicates
            List predicateNodes = getPredicateSet().evaluatePredicates(interimSet, support);
            // ensure only one of each node in the result
            Iterator predicateNodeIter = predicateNodes.iterator();
            while (predicateNodeIter.hasNext()) {
                Object eachPredicateNode = predicateNodeIter.next();
                if (!unique.contains(eachPredicateNode)) {
                    unique.add(eachPredicateNode);
                    newNodeSet.add(eachPredicateNode);
                }
            }
            interimSet.clear();
        }
    } else {
        for (int i = 0; i < contextSize; ++i) {
            Object eachContextNode = contextNodeSet.get(i);
            Iterator axisNodeIter = axisIterator(eachContextNode, support);
            if (axisNodeIter == null || !axisNodeIter.hasNext()) {
                continue;
            }
            /* See jaxen-106. Might be able to optimize this by doing
                 * specific matching for individual axes. For instance on namespace axis
                 * we should only get namespace nodes and on attribute axes we only get 
                 * attribute nodes. Self and parent axes have single members.
                 * Children, descendant, ancestor, and sibling axes never 
                 * see any attributes or namespaces
                 */
            // ensure only unique matching nodes in the result
            while (axisNodeIter.hasNext()) {
                Object eachAxisNode = axisNodeIter.next();
                if (matches(eachAxisNode, support)) {
                    interimSet.add(eachAxisNode);
                }
            }
            // evaluate the predicates
            List predicateNodes = getPredicateSet().evaluatePredicates(interimSet, support);
            // ensure only one of each node in the result
            Iterator predicateNodeIter = predicateNodes.iterator();
            while (predicateNodeIter.hasNext()) {
                Object eachPredicateNode = predicateNodeIter.next();
                if (!unique.contains(eachPredicateNode)) {
                    unique.add(eachPredicateNode);
                    newNodeSet.add(eachPredicateNode);
                }
            }
            interimSet.clear();
        }
    }
    return newNodeSet;
}

3 View Complete Implementation : EvaluateFunction.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static List evaluate(Context context, Object arg) throws FunctionCallException {
    List contextNodes = context.getNodeSet();
    if (contextNodes.size() == 0)
        return Collections.EMPTY_LIST;
    Navigator nav = context.getNavigator();
    String xpathString;
    if (arg instanceof String)
        xpathString = (String) arg;
    else
        xpathString = StringFunction.evaluate(arg, nav);
    try {
        XPath xpath = nav.parseXPath(xpathString);
        ContextSupport support = context.getContextSupport();
        xpath.setVariableContext(support.getVariableContext());
        xpath.setFunctionContext(support.getFunctionContext());
        xpath.setNamespaceContext(support.getNamespaceContext());
        return xpath.selectNodes(context.duplicate());
    } catch (org.jaxen.saxpath.SAXPathException e) {
        throw new FunctionCallException(e.toString());
    }
}