Author: karthick
Date: Fri Aug 7 20:29:03 2009
New Revision: 802169
URL: http://svn.apache.org/viewvc?rev=802169&view=rev
Log:
This patch resolves ODE-646 as well as ODE-542. Thanks to Mark Ford!
Added:
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/compiler/
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImplTest.java
Modified:
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
Modified:
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java?rev=802169&r1=802168&r2=802169&view=diff
==============================================================================
---
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
(original)
+++
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
Fri Aug 7 20:29:03 2009
@@ -21,7 +21,9 @@
import java.net.URI;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -298,14 +300,13 @@
return null;
}
- private List<String> getVariableNames(String xquery) {
- List<String> variableNames = new ArrayList<String>();
+ protected static Collection<String> getVariableNames(String xquery) {
+ Collection<String> variableNames = new LinkedHashSet<String>();
for (int index = xquery.indexOf("$"); index != -1; index =
xquery.indexOf("$")) {
- StringBuffer variableName = new StringBuffer();
- for (char ch = xquery.charAt(++index);
- XMLChar.isNCName(ch);
- ch = xquery.charAt(++index)) {
- variableName.append(ch);
+ StringBuilder variableName = new StringBuilder();
+ index++;
+ while(index < xquery.length() &&
XMLChar.isNCName(xquery.charAt(index))) {
+ variableName.append(xquery.charAt(index++));
}
variableNames.add(variableName.toString());
xquery = xquery.substring(index);
Added:
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImplTest.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImplTest.java?rev=802169&view=auto
==============================================================================
---
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImplTest.java
(added)
+++
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImplTest.java
Fri Aug 7 20:29:03 2009
@@ -0,0 +1,39 @@
+package org.apache.ode.bpel.elang.xquery10.compiler;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+
+import junit.framework.TestCase;
+
+public class XQuery10ExpressionCompilerImplTest extends TestCase {
+
+ public void testGetVariableNames() throws Exception {
+ String xq = "let $status := string($SomeVariable/ns:somePath)\n" +
+ " return\n" +
+ " if ($status = 'ABC' ) then\n" +
+ " '123'\n" +
+ " else $status (: workaround :)";
+
+ assertMatches(xq);
+ }
+
+ public void testGetVariableNames_endsWithVariableName() throws Exception {
+ String xq = "let $status := string($SomeVariable/ns:somePath)\n" +
+ " return\n" +
+ " if ($status = 'ABC' ) then\n" +
+ " '123'\n" +
+ " else $status";
+
+ assertMatches(xq);
+ }
+
+ private void assertMatches(String xq) {
+ Collection<String> varNames =
XQuery10ExpressionCompilerImpl.getVariableNames(xq);
+ Collection<String> expected = new
LinkedHashSet(Arrays.asList("status", "SomeVariable"));
+
+ assertEquals(2, varNames.size());
+ assertEquals(expected, varNames);
+ }
+
+}