Repository: ode
Updated Branches:
  refs/heads/master e9a4f89d5 -> 768cb6dce
  refs/heads/ode-1.3.x 2eb6ba8cf -> 37c6cecfa


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/37c6cecf
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/37c6cecf
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/37c6cecf

Branch: refs/heads/ode-1.3.x
Commit: 37c6cecfad04672374957465c4ef379107ffe427
Parents: 2eb6ba8
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:18:09 2015 +0200

----------------------------------------------------------------------
 .../xpath20/runtime/JaxpFunctionResolver.java   | 22 +++++++++++++++++++-
 .../runtime/XPath20ExpressionRuntimeTest.java   | 12 +++++++++++
 .../src/test/resources/xpath20/variables.xml    | 10 +++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode/blob/37c6cecf/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 4f5aab3..9016eab 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]);
-                   clonedElmt.removeChild(deleteElmt);
+                   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/37c6cecf/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 a6482ef..e20a98e 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
@@ -19,6 +19,7 @@
 package org.apache.ode.bpel.elang.xpath20.runtime;
 
 import junit.framework.TestCase;
+
 import org.apache.ode.bpel.common.FaultException;
 import org.apache.ode.bpel.compiler.bom.Expression;
 import 
org.apache.ode.bpel.elang.xpath20.compiler.XPath20ExpressionCompilerBPEL20;
@@ -30,6 +31,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.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -109,6 +111,14 @@ public class XPath20ExpressionRuntimeTest extends TestCase 
implements Evaluation
         assertNull(DOMUtils.getFirstChildElement((Element)retVal));
     }
 
+    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);
     }
@@ -153,6 +163,8 @@ public class XPath20ExpressionRuntimeTest extends TestCase 
implements Evaluation
         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/37c6cecf/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 7588891..61ac09d 100644
--- a/bpel-runtime/src/test/resources/xpath20/variables.xml
+++ b/bpel-runtime/src/test/resources/xpath20/variables.xml
@@ -62,4 +62,14 @@
                          </tns:ApplicationData>
 
        </elementVar>
+       <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

Reply via email to