You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2007/07/27 00:56:39 UTC

svn commit: r560025 - in /incubator/ode/trunk: bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/ bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/ bpel-test/src/test/java/org/apache/ode/test/ bpel-test/src/test...

Author: mriou
Date: Thu Jul 26 15:56:38 2007
New Revision: 560025

URL: http://svn.apache.org/viewvc?view=rev&rev=560025
Log:
Added a (non standard) XPath utility function to split a string into several elements each containing one section of the split. XSLT is overkill for those simple transformations.

Added:
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.bpel
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.wsdl
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/deploy.xml
      - copied, changed from r559618, incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/deploy.xml
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/test.properties
      - copied, changed from r559618, incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/test.properties
Modified:
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
    incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
    incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/DataHandling20Test.java

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java?view=diff&rev=560025&r1=560024&r2=560025
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java (original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java Thu Jul 26 15:56:38 2007
@@ -24,31 +24,36 @@
  * XPath-4-BPEL related constants.
  */
 public class Constants {
-  /**
-   * Extension function bpws:getVariableData('variableName', 'partName'?,
-   * 'locationPath'?)
-   */
-  public static final String EXT_FUNCTION_GETVARIABLEDATA = "getVariableData";
+    /**
+     * Extension function bpws:getVariableData('variableName', 'partName'?,
+     * 'locationPath'?)
+     */
+    public static final String EXT_FUNCTION_GETVARIABLEDATA = "getVariableData";
 
-  /**
-   * Extension function
-   * bpws:getVariableProperty('variableName','propertyName')
-   */
-  public static final String EXT_FUNCTION_GETVARIABLEPROPRTY = "getVariableProperty";
+    /**
+     * Extension function
+     * bpws:getVariableProperty('variableName','propertyName')
+     */
+    public static final String EXT_FUNCTION_GETVARIABLEPROPRTY = "getVariableProperty";
 
-  /**
-   * Extension function bpws:getLinkStatus('getLinkName')
-   */
-  public static final String EXT_FUNCTION_GETLINKSTATUS = "getLinkStatus";
+    /**
+     * Extension function bpws:getLinkStatus('getLinkName')
+     */
+    public static final String EXT_FUNCTION_GETLINKSTATUS = "getLinkStatus";
 
-  /**
-   * Extension function bpws:getLinkStatus('getLinkName')
-   */
-  public static final String EXT_FUNCTION_DOXSLTRANSFORM = "doXslTransform";
+    /**
+     * Extension function bpws:getLinkStatus('getLinkName')
+     */
+    public static final String EXT_FUNCTION_DOXSLTRANSFORM = "doXslTransform";
 
-  public static boolean isBpelNamespace(String uri){
-    return Namespaces.WS_BPEL_20_NS.equals(uri) || Namespaces.WSBPEL2_0_FINAL_EXEC.equals(uri)
-             || Namespaces.BPEL11_NS.equals(uri);
-  }
+    /**
+     * Non standard extension function ode:splitToElements(sourceText, 'separator' 'targetLocalName', 'targetNS'?)
+     */
+    public static final String NON_STDRD_FUNCTION_SPLITTOELEMENTS = "splitToElements";
+
+    public static boolean isBpelNamespace(String uri){
+        return Namespaces.WS_BPEL_20_NS.equals(uri) || Namespaces.WSBPEL2_0_FINAL_EXEC.equals(uri)
+                || Namespaces.BPEL11_NS.equals(uri);
+    }
 
 }

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java?view=diff&rev=560025&r1=560024&r2=560025
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java (original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java Thu Jul 26 15:56:38 2007
@@ -35,6 +35,7 @@
 import org.apache.ode.bpel.o.OScope;
 import org.apache.ode.bpel.o.OXslSheet;
 import org.apache.ode.utils.NSContext;
+import org.apache.ode.utils.Namespaces;
 import org.apache.ode.utils.msg.MessageBundle;
 import org.apache.ode.utils.xsl.XslTransformHandler;
 
@@ -71,6 +72,11 @@
             } else {
                 throw new WrappedResolverException(__msgs.errUnknownBpelFunction(localName));
             }
+        } else if (functionName.getNamespaceURI().equals(Namespaces.ODE_EXTENSION_NS)) {
+            String localName = functionName.getLocalPart();
+            if (Constants.NON_STDRD_FUNCTION_SPLITTOELEMENTS.equals(localName)) {
+                return new SplitToElements();
+            }
         }
 
         return null;
@@ -121,6 +127,19 @@
             }
 
             _out.xslSheets.put(xslSheet.uri, xslSheet);
+            return "";
+        }
+    }
+
+    /**
+     * Compile time checking for the non standard ode:splitToElements function.
+     */
+    public class SplitToElements implements XPathFunction {
+        public Object evaluate(List params) throws XPathFunctionException {
+            if (params.size() < 3 || params.size() > 4) {
+                throw new CompilationException(
+                        __msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_SPLITTOELEMENTS));
+            }
             return "";
         }
     }

Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java?view=diff&rev=560025&r1=560024&r2=560025
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java Thu Jul 26 15:56:38 2007
@@ -39,6 +39,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.Text;
 import org.xml.sax.SAXException;
 
 import javax.xml.namespace.QName;
@@ -87,6 +88,11 @@
             } else {
                 throw new WrappedResolverException("Unknown BPEL function: " + functionName);
             }
+        } else if (functionName.getNamespaceURI().equals(Namespaces.ODE_EXTENSION_NS)) {
+            String localName = functionName.getLocalPart();
+            if (Constants.NON_STDRD_FUNCTION_SPLITTOELEMENTS.equals(localName)) {
+                return new SplitToElements();
+            }
         }
 
         return null;
@@ -282,4 +288,69 @@
         }
     }
 
+    /**
+     * Compile time checking for the non standard ode:splitToElements function.
+     */
+    public class SplitToElements implements XPathFunction {
+        public Object evaluate(List args) throws XPathFunctionException {
+            assert args.size() > 2;
+            assert args.size() < 5;
+            if (__log.isDebugEnabled()) {
+                __log.debug("splitToElements call(context=" + _ectx + " args=" + args + ")");
+            }
+
+            // Checking the first parameters, should be a proper element or a text node. Java verbosity at its best.
+            String strToSplit = null;
+            try {
+                Node firstParam = null;
+                if (args.get(0) instanceof List) {
+                    List elmts = (List)args.get(0);
+                    if (elmts.size() != 1) throw new XPathFunctionException(
+                            new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "splitInvalidSource"),
+                                    "First parameter of the ode:splitToElements function MUST point to a single " +
+                                            "element or text node."));
+                    firstParam = (Node) elmts.get(0);
+                } else  if (args.get(0) instanceof NodeWrapper) {
+                    firstParam = (Node) ((NodeWrapper)args.get(0)).getUnderlyingNode();
+                } else if (args.get(0) instanceof Node) {
+                    firstParam = (Node) args.get(0);
+                } else {
+                    strToSplit = (String) args.get(0);
+                }
+
+                if (strToSplit == null) {
+                    if (Node.ELEMENT_NODE == firstParam.getNodeType()) {
+                        strToSplit = firstParam.getTextContent().trim();
+                    } else if (Node.TEXT_NODE == firstParam.getNodeType()) {
+                        strToSplit = ((Text)firstParam).getWholeText().trim();
+                    }
+                }
+            } catch (ClassCastException e) {
+                throw new XPathFunctionException(
+                        new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "splitInvalidSource"),
+                                "First parameter of the ode:splitToElements function MUST point to a single " +
+                                        "element node."));
+            }
+
+            // Other parameters
+            String separator = (String) args.get(1);
+            String localName = (String) args.get(2);
+            String namespace = args.size() == 4 ? (String) args.get(3) : null;
+
+            // Preparing the result document
+            Document doc = DOMUtils.newDocument();
+            Element wrapper = doc.createElement("wrapper");
+            doc.appendChild(wrapper);
+
+            // Creating nodes for each string element of the split string and appending to result
+            String[] strElmts = strToSplit.split(separator);
+            for (String strElmt : strElmts) {
+                Element elmt = doc.createElementNS(namespace, localName);
+                elmt.setTextContent(strElmt.trim());
+                wrapper.appendChild(elmt);
+            }
+
+            return wrapper;
+        }
+    }
 }

Modified: incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/DataHandling20Test.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/DataHandling20Test.java?view=diff&rev=560025&r1=560024&r2=560025
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/DataHandling20Test.java (original)
+++ incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/DataHandling20Test.java Thu Jul 26 15:56:38 2007
@@ -47,5 +47,8 @@
     public void testXslTransform() throws Throwable {
         go("/bpel/2.0/TestXslTransform");
     }
-	
+    public void testSplit() throws Throwable {
+        go("/bpel/2.0/TestSplit");
+    }
+
 }

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.bpel
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.bpel?view=auto&rev=560025
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.bpel (added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.bpel Thu Jul 26 15:56:38 2007
@@ -0,0 +1,63 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<process name="TestSplit"
+    targetNamespace="http://ode/bpel/unit-test" 
+    xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+    xmlns="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+    xmlns:tns="http://ode/bpel/unit-test"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:ode="http://www.apache.org/ode/type/extension"
+    xmlns:test="http://ode/bpel/unit-test.wsdl"
+    queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+    expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">
+
+
+  <import location="TestSplit.wsdl"
+     namespace="http://ode/bpel/unit-test.wsdl"
+     importType="http://schemas.xmlsoap.org/wsdl/" />
+
+   <partnerLinks>
+      <partnerLink name="testSplitPartnerLink"
+         partnerLinkType="test:TestSplitPartnerLinkType"
+         myRole="me" />
+   </partnerLinks>
+    
+   <variables>
+     <variable name="myVar" messageType="test:TestSplitMessage"/>
+     <variable name="tmpVar" type="xsd:string"/>
+   </variables>
+        
+   <sequence>   
+       <receive name="start" partnerLink="testSplitPartnerLink" portType="test:TestSplitPortType"
+          operation="split" variable="myVar" createInstance="yes"/>
+
+      <assign name="assign1">
+         <copy>
+            <from variable="myVar" part="TestPart"/>
+            <to variable="tmpVar"/>
+         </copy>
+         <copy>
+             <from>ode:splitToElements($tmpVar, ',', 'chunk')</from>
+             <to variable="myVar" part="TestPart"/>
+         </copy>
+      </assign>
+       <reply name="end" partnerLink="testSplitPartnerLink" portType="test:TestSplitPortType"
+              operation="split" variable="myVar"/>
+   </sequence>
+</process>

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.wsdl
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.wsdl?view=auto&rev=560025
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.wsdl (added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/TestSplit.wsdl Thu Jul 26 15:56:38 2007
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<wsdl:definitions 
+    targetNamespace="http://ode/bpel/unit-test.wsdl"
+    xmlns="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:tns="http://ode/bpel/unit-test.wsdl"
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+    xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+    xmlns:plnk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/">
+    
+    <wsdl:message name="TestSplitMessage">
+        <wsdl:part name="TestPart" type="xsd:string"/>
+    </wsdl:message>
+    
+    <wsdl:portType name="TestSplitPortType">
+        <wsdl:operation name="split">
+            <wsdl:input message="tns:TestSplitMessage" name="TestIn"/>
+            <wsdl:output message="tns:TestSplitMessage" name="TestOut"/>
+        </wsdl:operation>    
+    </wsdl:portType>
+    
+     <wsdl:binding name="TestSplitSoapBinding" type="tns:TestSplitPortType">
+        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
+        <wsdl:operation name="split">
+            <soap:operation soapAction="" style="rpc"/>
+            <wsdl:input>
+                <soap:body
+                    namespace="http://ode/bpel/unit-test.wsdl"
+                    use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body
+                    namespace="http://ode/bpel/unit-test.wsdl" 
+                    use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="TestSplitService">
+		<wsdl:port name="TestSplitPort" binding="tns:TestSplitSoapBinding">
+     		<soap:address location="http://localhost:8080/ode/processes/testSplit"/>
+		</wsdl:port>
+    </wsdl:service>
+    
+   <plnk:partnerLinkType name="TestSplitPartnerLinkType">
+       <plnk:role name="me" portType="tns:TestSplitPortType"/>
+       <plnk:role name="you" portType="tns:TestSplitPortType"/>
+   </plnk:partnerLinkType>
+</wsdl:definitions>
+

Copied: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/deploy.xml (from r559618, incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/deploy.xml)
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/deploy.xml?view=diff&rev=560025&p1=incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/deploy.xml&r1=559618&p2=incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/deploy.xml&r2=560025
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/deploy.xml (original)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/deploy.xml Thu Jul 26 15:56:38 2007
@@ -21,10 +21,10 @@
 	xmlns:wns="http://ode/bpel/unit-test.wsdl">
 
 
-	<process name="pns:HelloWorld2">
+	<process name="pns:TestSplit">
 		<active>true</active>
-		<provide partnerLink="helloPartnerLink">
-			<service name="wns:HelloService" port="HelloPort"/>
+		<provide partnerLink="testSplitPartnerLink">
+			<service name="wns:TestSplitService" port="TestSplitPort"/>
 		</provide>
 	</process>
 </deploy>

Copied: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/test.properties (from r559618, incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/test.properties)
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/test.properties?view=diff&rev=560025&p1=incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/test.properties&r1=559618&p2=incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/test.properties&r2=560025
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/HelloWorld2/test.properties (original)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestSplit/test.properties Thu Jul 26 15:56:38 2007
@@ -16,8 +16,8 @@
 #
 
 namespace=http://ode/bpel/unit-test.wsdl
-service=HelloService
-operation=hello
-request1=<message><TestPart>Hello</TestPart></message>
-response1=.*Hello World.*
+service=TestSplitService
+operation=split
+request1=<message><TestPart>split,me,this,please</TestPart></message>
+response1=.*<chunk>split</chunk>.*<chunk>me</chunk>.*<chunk>this</chunk>.*