fixes ODE-991. Thanks to Ciaran Jessup for the patch.
Project: http://git-wip-us.apache.org/repos/asf/ode/repo Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/768cb6dc Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/768cb6dc Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/768cb6dc Branch: refs/heads/master Commit: 768cb6dcee7f97a2d606ea7ae60f35a79e03238d Parents: e9a4f89 Author: Tammo van Lessen <[email protected]> Authored: Thu Jun 11 12:18:09 2015 +0200 Committer: Tammo van Lessen <[email protected]> Committed: Thu Jun 11 12:24:33 2015 +0200 ---------------------------------------------------------------------- .../xpath20/runtime/JaxpFunctionResolver.java | 22 +++++++++++++++++++- .../runtime/XPath20ExpressionRuntimeTest.java | 13 +++++++++++- .../src/test/resources/xpath20/variables.xml | 10 +++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ode/blob/768cb6dc/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java ---------------------------------------------------------------------- diff --git a/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java b/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java index aa29367..3bceb21 100644 --- a/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java +++ b/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java @@ -35,11 +35,13 @@ import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; import javax.xml.xpath.XPathFunctionResolver; +import net.sf.saxon.dom.DOMNodeList; import net.sf.saxon.dom.NodeWrapper; import net.sf.saxon.trans.XPathException; import net.sf.saxon.value.DayTimeDurationValue; import net.sf.saxon.value.IntegerValue; import net.sf.saxon.value.QNameValue; +import net.sf.saxon.value.SequenceExtent; import net.sf.saxon.value.YearMonthDurationValue; import org.apache.commons.httpclient.URIException; @@ -885,6 +887,15 @@ public class JaxpFunctionResolver implements XPathFunctionResolver { targetNodes.add((Element) ((NodeWrapper) delete).getUnderlyingNode()); } else if (delete instanceof Element) { targetNodes.add((Element) delete); + } else if (delete instanceof SequenceExtent) { + try { + DOMNodeList nodeList= DOMNodeList.checkAndMake((SequenceExtent)delete); + for (int i=0;i<nodeList.getLength();i++){ + targetNodes.add(nodeList.item(i)); + } + } catch (XPathException e) { + throw new XPathFunctionException(e); + } } else { throw new XPathFunctionException("Unexpected argument type: " + delete.getClass()); } @@ -918,12 +929,21 @@ public class JaxpFunctionResolver implements XPathFunctionResolver { } } } + // 2xLoops as previously the contents of the 'children' list appeared to + // be being changed by the clonedElmt.removeChild call, meaning the position + // offset was incorrect, a possibly better approach would be to sort the position + // indices and iterate *backwards* but for my needs this approach suffices. + List<Node> clonedChildrenToRemove = new ArrayList<Node>(); final Element clonedElmt = (Element) parentElmt.cloneNode(true); children = clonedElmt.getChildNodes(); for (int target = 0; target < positions.length; target++) { - Element deleteElmt = (Element) children.item(positions[target]); + Element deleteElmt = (Element) children.item(positions[target]); + clonedChildrenToRemove.add(deleteElmt); + } + for (Node deleteElmt : clonedChildrenToRemove) { clonedElmt.removeChild(deleteElmt); } + // Saxon doesn't like clones with no children, so I'll oblige if (clonedElmt.getChildNodes().getLength() == 0) { try { http://git-wip-us.apache.org/repos/asf/ode/blob/768cb6dc/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java ---------------------------------------------------------------------- diff --git a/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java b/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java index 3968b05..137a848 100644 --- a/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java +++ b/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java @@ -18,11 +18,11 @@ */ package org.apache.ode.bpel.elang.xpath20.runtime; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.net.URI; @@ -44,6 +44,7 @@ import org.apache.ode.bpel.o.OMessageVarType.Part; import org.apache.ode.bpel.o.OProcess.OProperty; import org.apache.ode.bpel.o.OScope.Variable; import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.Namespaces; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -230,6 +231,14 @@ public class XPath20ExpressionRuntimeTest implements EvaluationContext { fail("Missing '"+insertElementName+"' element has not been inserted"); } } + + public void testODE911() throws Exception { + OXPath20ExpressionBPEL20 exp = compile("ode:delete($ODE991var/tns:empty)"); + Element retVal = (Element)_runtime.evaluateNode(exp, this); + assertNotNull(retVal); + assertEquals(3, retVal.getElementsByTagNameNS("http://foobar", "notempty").getLength()); + assertEquals(0, retVal.getElementsByTagNameNS("http://foobar", "empty").getLength()); + } public Node readVariable(Variable variable, Part part) throws FaultException { return _vars.get(variable.name); @@ -274,6 +283,8 @@ public class XPath20ExpressionRuntimeTest implements EvaluationContext { doc.appendChild(e); e.appendChild(doc.createTextNode(xpath)); Expression exp = new Expression(e); + exp.getNamespaceContext().register("tns", "http://foobar"); + exp.getNamespaceContext().register("ode", Namespaces.ODE_EXTENSION_NS); return (OXPath20ExpressionBPEL20)_compiler.compileLValue(exp); } http://git-wip-us.apache.org/repos/asf/ode/blob/768cb6dc/bpel-runtime/src/test/resources/xpath20/variables.xml ---------------------------------------------------------------------- diff --git a/bpel-runtime/src/test/resources/xpath20/variables.xml b/bpel-runtime/src/test/resources/xpath20/variables.xml index 919cbc3..38c5996 100644 --- a/bpel-runtime/src/test/resources/xpath20/variables.xml +++ b/bpel-runtime/src/test/resources/xpath20/variables.xml @@ -71,4 +71,14 @@ </tns:ExampleMessage> </messageTypeVar> + <elementVar name="ODE991var" xmlns:tns="http://foobar" > + <tns:ApplicationData> + <tns:empty/> + <tns:notempty/> + <tns:empty/> + <tns:notempty/> + <tns:empty/> + <tns:notempty/> + </tns:ApplicationData> + </elementVar> </variables> \ No newline at end of file
