Author: mbenson Date: Wed Jan 10 14:37:24 2007 New Revision: 495015 URL: http://svn.apache.org/viewvc?view=rev&rev=495015 Log: [JXPATH-50] properly handle NodeSet returned by extension function. Submitted by Keith D. Gregory.
Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java?view=diff&rev=495015&r1=495014&r2=495015 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java Wed Jan 10 14:37:24 2007 @@ -16,6 +16,7 @@ */ package org.apache.commons.jxpath.ri.compiler; +import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; @@ -74,6 +75,9 @@ if (result instanceof EvalContext) { return new ValueIterator((EvalContext) result); } + if (result instanceof NodeSet) { + return new ValueIterator(((NodeSet) result).getPointers().iterator()); + } return ValueUtils.iterate(result); } @@ -85,6 +89,11 @@ if (result instanceof EvalContext) { return (EvalContext) result; } + if (result instanceof NodeSet) { + return new PointerIterator(((NodeSet) result).getPointers().iterator(), + new QName(null, "value"), + context.getRootContext().getCurrentNodePointer().getLocale()); + } return new PointerIterator(ValueUtils.iterate(result), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); @@ -95,6 +104,7 @@ private QName qname; private Locale locale; + //to what method does the following comment refer? /** * @deprecated Use the method that takes a NamespaceManager */ @@ -110,7 +120,7 @@ public Object next() { Object o = iterator.next(); - return NodePointer.newNodePointer(qname, o, locale); + return o instanceof Pointer ? o : NodePointer.newNodePointer(qname, o, locale); } public void remove() { Modified: jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java?view=diff&rev=495015&r1=495014&r2=495015 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java Wed Jan 10 14:37:24 2007 @@ -46,6 +46,7 @@ public class ExtensionFunctionTest extends JXPathTestCase { private Functions functions; private JXPathContext context; + private TestBean testBean; public static void main(String[] args) { TestRunner.run(ExtensionFunctionTest.class); @@ -62,7 +63,8 @@ public void setUp() { if (context == null) { - context = JXPathContext.newContext(new TestBean()); + testBean = new TestBean(); + context = JXPathContext.newContext(testBean); Variables vars = context.getVariables(); vars.declareVariable("test", new TestFunctions(4, "test")); @@ -337,6 +339,11 @@ "test:nodeSet()/name", list("Name 1", "Name 2")); + assertXPathValueIterator( + context, + "test:nodeSet()", + list(testBean.getBeans()[0], testBean.getBeans()[1])); + assertXPathPointerIterator( context, "test:nodeSet()/name", @@ -379,4 +386,4 @@ return 0; } } -} \ No newline at end of file +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]