ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r697290 - in /ode/sandbox/simpel/src: main/antlr/org/apache/ode/simpel/antlr/ main/java/org/apache/ode/embed/ main/java/org/apache/ode/embed/messaging/ main/java/org/apache/ode/simpel/expr/ main/java/org/apache/ode/simpel/omodel/ test/java/...
Date Fri, 19 Sep 2008 23:53:50 GMT
Author: mriou
Date: Fri Sep 19 16:53:50 2008
New Revision: 697290

URL: http://svn.apache.org/viewvc?rev=697290&view=rev
Log:
Two-ways invokes. E4X expression runtime wrapping and unwrapping fix.

Modified:
    ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
    ode/sandbox/simpel/src/main/java/org/apache/ode/embed/MessageSender.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/embed/messaging/MessageExchangeContextImpl.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
    ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
    ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel

Modified: ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g (original)
+++ ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g Fri Sep 19
16:53:50 2008
@@ -109,7 +109,8 @@
 	:	^(SEQUENCE ID+
 		{ OBuilder.StructuredActivity seq = builder.build(OSequence.class, $BPELScope::oscope,
$Parent[-1]::activity); 
 		  $Parent::activity = seq;
-		  builder.setBlockParam($BPELScope::oscope, (OActivity) $Parent[-1]::activity.getOActivity(),
$ID.text); 
+		  //builder.setBlockParam($BPELScope::oscope, (OActivity) $Parent[-1]::activity.getOActivity(),
$ID.text);
+		  builder.setBlockParam($BPELScope::oscope, (OSequence)seq.getOActivity(), $ID.text); 
 		}
 		proc_stmt+);
 body	:	block | proc_stmt;

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/embed/MessageSender.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/embed/MessageSender.java?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/embed/MessageSender.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/embed/MessageSender.java Fri Sep 19 16:53:50
2008
@@ -1,8 +1,8 @@
 package org.apache.ode.embed;
 
-import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 public interface MessageSender {
 
-    Element send(String recipient, String operation, Element elmt);
+    Node send(String recipient, String operation, Node message);
 }

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/embed/messaging/MessageExchangeContextImpl.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/embed/messaging/MessageExchangeContextImpl.java?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/embed/messaging/MessageExchangeContextImpl.java
(original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/embed/messaging/MessageExchangeContextImpl.java
Fri Sep 19 16:53:50 2008
@@ -6,9 +6,11 @@
 import org.apache.log4j.Logger;
 import org.w3c.dom.Element;
 import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
 import javax.wsdl.Operation;
 import javax.wsdl.Fault;
+import javax.wsdl.Part;
 import javax.xml.namespace.QName;
 import java.util.Set;
 import java.util.HashSet;
@@ -33,10 +35,19 @@
 
         Operation invokedOp = partnerMex.getPortType().getOperation(partnerMex.getOperationName(),
null, null);
         try {
-            // We're placing ourselves in the doc/lit case for now, assuming a single part
+            // We're placing ourselves in the doc/lit case for now, assuming a single part
with a single root element
             Element message = partnerMex.getRequest().getMessage();
-            Element response = _sender.send(partnerMex.getPortType().getQName().getLocalPart(),
invokedOp.getName(), 
-                    DOMUtils.getFirstChildElement(DOMUtils.getFirstChildElement(message)));
+            Element root = DOMUtils.getFirstChildElement(DOMUtils.getFirstChildElement(message));
+            // TODO this assumption only works with SimPEL, in the general case we could
have a NodeList
+            // and should therefore send the whole part element
+            Node payload;
+            if (DOMUtils.getFirstChildElement(root) != null)
+                payload = DOMUtils.getFirstChildElement(root);
+            else {
+                Document doc = DOMUtils.newDocument();
+                payload = doc.createTextNode(DOMUtils.getTextContent(root));
+            }
+            Node response = _sender.send(partnerMex.getPortType().getQName().getLocalPart(),
invokedOp.getName(), payload);
 
             if (invokedOp.getOutput() != null) {
                 Document responseDoc = DOMUtils.newDocument();
@@ -46,10 +57,15 @@
                 String partName = (String) invokedOp.getOutput().getMessage().getParts().keySet().iterator().next();
                 Element partElmt = responseDoc.createElement(partName);
                 messageElmt.appendChild(partElmt);
-                if (response != null) partElmt.appendChild(responseDoc.importNode(response,
true));
+                // TODO same thing, simpel only wrapping
+                QName elmtName = ((Part)invokedOp.getOutput().getMessage().getParts().values().iterator().next()).getElementName();
+                Element partRootElmt = responseDoc.createElementNS(elmtName.getNamespaceURI(),
elmtName.getLocalPart());
+                partElmt.appendChild(partRootElmt);
+                if (response != null) partRootElmt.appendChild(responseDoc.importNode(response,
true));
 
                 Message responseMsg = partnerMex.createMessage(invokedOp.getOutput().getMessage().getQName());
                 responseMsg.setMessage(messageElmt);
+                partnerMex.reply(responseMsg);
             } else {
                 partnerMex.replyOneWayOk();
             }

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java Fri Sep
19 16:53:50 2008
@@ -16,6 +16,7 @@
 import org.mozilla.javascript.xml.XMLObject;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.Element;
 
 import javax.xml.namespace.QName;
 import java.util.*;
@@ -67,7 +68,11 @@
             resList.add(doc.createTextNode(res.toString()));
         } else if (res instanceof XMLObject) {
             try {
-                resList.add(XMLLibImpl.toDomNode(res));
+                // Only content is copied, need to wrap
+                Document doc = DOMUtils.newDocument();
+                Element wrapper = doc.createElement("assignWrapper");
+                wrapper.appendChild(doc.importNode(XMLLibImpl.toDomNode(res), true));
+                resList.add(wrapper);
             } catch (IllegalArgumentException e) {
                 // Rhino makes it pretty hard to use it sXML impl, XML and XMLList are package
level
                 // classes so I can't test on them but toDomNode doesn't accept XMLList
@@ -124,7 +129,12 @@
                 }
                 // Simple types
                 if (node.getNodeValue() != null) return node.getNodeValue();
-                
+                else if (node.getNodeType() == Node.ELEMENT_NODE) {
+                    Element nodeElmt = (Element) node;
+                    if (DOMUtils.getFirstChildElement(nodeElmt) == null) return nodeElmt.getTextContent();
+                    else node = DOMUtils.getFirstChildElement((Element)node);
+                }
+
                 // Have to remove the xml header otherwise it confuses Rhino
                 String[] xmlArr = DOMUtils.domToString(node).split("\n");
                 // Going back to the evaluation loop to get a Rhino XML object, their XML
API just doesn't have any
@@ -135,7 +145,7 @@
                 _env.put(name, xmlObj);
                 return xmlObj;
             } catch (Exception e) {
-                throw new RuntimeException("Error accessing variable " + name + ".");
+                throw new RuntimeException("Error accessing variable " + name + ".", e);
             }
         }
 

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java Fri Sep 19
16:53:50 2008
@@ -13,16 +13,17 @@
 import org.apache.ode.utils.GUID;
 
 import javax.wsdl.PortType;
+import javax.wsdl.Part;
 import javax.xml.namespace.QName;
 import java.lang.reflect.Method;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.HashSet;
+import java.util.*;
 
 /**
  * TODO foo = receive(...) expressions
  * TODO e4x templates
+ * TODO allow javascript blocks instead of just hooking on equal, otherwise you can't do
stuff like
+ *          operations.appendChild(<operand>2</operand>);
+ *          operations.appendChild(<operand>3</operand>);
  */
 public class OBuilder extends BaseCompiler {
     private static final Logger __log = Logger.getLogger(OBuilder.class);
@@ -153,7 +154,6 @@
 
     public SimpleActivity buildInvoke(OInvoke invoke, OScope oscope, String partnerLink,
                                       String operation, String incomingMsg) {
-
         invoke.partnerLink = buildPartnerLink(oscope, partnerLink, operation, false, incomingMsg
!= null);
         invoke.operation = invoke.partnerLink.partnerRolePortType.getOperation(operation,
null, null);
         if (incomingMsg != null) invoke.inputVar = resolveVariable(oscope, incomingMsg, operation,
true);
@@ -176,7 +176,6 @@
         OAssign.VariableRef vref = new OAssign.VariableRef(_oprocess);
         String lvar = lexpr.split("\\.")[0];
         vref.variable = resolveVariable(oscope, lvar);
-        ((OMessageVarType)vref.variable.type).parts.values().iterator();
         // Don't worry, it's all type safe, therefore it's correct
         vref.part = ((OMessageVarType)vref.variable.type).parts.values().iterator().next();
         ocopy.to = vref;
@@ -205,7 +204,7 @@
         return new SimpleActivity<OReply>(oreply);
     }
 
-    public void setBlockParam(OScope oscope, OActivity blockActivity, String varName) {
+    public void setBlockParam(OScope oscope, OSequence blockActivity, String varName) {
         // The AST for block activities is something like:
         //    (SEQUENCE (activity) (SEQUENCE varIds otherActivities))
         // The parent here is the first sequence so we just set the varIds on its first child
activity
@@ -213,13 +212,16 @@
             __log.warn("Can't set block parameter with block parent activity " + blockActivity);
             return;
         }
-        OActivity oact = ((OSequence)blockActivity).sequence.get(0);
+//        OActivity oact = ((OSequence)blockActivity).sequence.get(0);
+        List<OActivity> parentList = ((OSequence)blockActivity.getParent()).sequence;
+        OActivity oact = parentList.get(parentList.indexOf(blockActivity) - 1);
         if (oact instanceof OPickReceive) {
             OPickReceive.OnMessage rec = ((OPickReceive)oact).onMessages.get(0);
             rec.variable = resolveVariable(oscope, varName, rec.operation.getName(), true);
         } else if (oact instanceof OInvoke) {
             OInvoke inv = (OInvoke)oact;
             inv.outputVar = resolveVariable(oscope, varName, inv.operation.getName(), false);
+            buildPartnerLink(oscope, inv.partnerLink.name, inv.operation.getName(), false,
false);
         } else __log.warn("Can't set block parameter on activity " + oact);
     }
 
@@ -301,10 +303,18 @@
         // use a better naming for the part element.
         if (operation != null && !typedVariables.contains(name)) {
             String elmtName = operation + (request ? "Request" : "Response");
-            LinkedList<OMessageVarType.Part> parts = new LinkedList<OMessageVarType.Part>();
-            parts.add(new OMessageVarType.Part(_oprocess, elmtName,
-                    new OElementVarType(_oprocess, new QName(_processNS, elmtName))));
-            resolved.type = new OMessageVarType(_oprocess, new QName(_processNS, operation),
parts);
+            OMessageVarType varType = (OMessageVarType)resolved.type;
+            varType.messageType = new QName(_processNS, operation);
+            OMessageVarType.Part part = varType.parts.values().iterator().next();
+            part.name = elmtName;
+            part.type = new OElementVarType(_oprocess, new QName(_processNS, elmtName));
+            varType.parts.clear();
+            varType.parts.put(part.name, part);
+//
+//            LinkedList<OMessageVarType.Part> parts = new LinkedList<OMessageVarType.Part>();
+//            parts.add(new OMessageVarType.Part(_oprocess, elmtName,
+//                    new OElementVarType(_oprocess, new QName(_processNS, elmtName))));
+//            resolved.type = new OMessageVarType(_oprocess, new QName(_processNS, operation),
parts);
             typedVariables.add(name);
         }
         return resolved;

Modified: ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java (original)
+++ ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java Fri Sep
19 16:53:50 2008
@@ -6,6 +6,8 @@
 import org.apache.ode.utils.DOMUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import javax.xml.namespace.QName;
 
@@ -39,8 +41,8 @@
             "process XmlData {\n" +
             "    receive(dataPl, dataOp) { |msgIn|\n" +
             "        friendInfo = <friend></friend>;\n" +
-            "        friendInfo.name = msgIn.person.firstName + \" \" + msgIn.person.lastName;\n"
+
-            "        friendInfo.phone = msgIn.person.phone;\n" +
+            "        friendInfo.name = msgIn.firstName + \" \" + msgIn.lastName;\n" +
+            "        friendInfo.phone = msgIn.phone;\n" +
             "        reply(friendInfo);\n" +
             "    }\n" +
             "}";
@@ -61,6 +63,8 @@
         Element result = server.sendMessage("dataPl", "dataOp", wrapper);
         assertNotNull(result);
         System.out.println(DOMUtils.domToString(result));
+        // Eliminating the wrapper
+        result = DOMUtils.getFirstChildElement(result);
         assertNotNull(DOMUtils.findChildByName(result, new QName(null, "phone")));
         assertNotNull(DOMUtils.findChildByName(result, new QName(null, "name")));
         assertEquals("(999)999-9999", DOMUtils.findChildByName(result, new QName(null, "phone")).getTextContent());
@@ -111,8 +115,10 @@
 
         EmbeddedServer server = new  EmbeddedServer();
         server.options.setMessageSender(new MessageSender() {
-            public Element send(String recipient, String operation, Element elmt) {
-                received[0] = true;
+            public Node send(String recipient, String operation, Node message) {
+                if (recipient.equals("partnerPl") && operation.equals("partnerOp")
+                        && message.getNodeType() == Node.TEXT_NODE && message.getTextContent().equals("ok?"))
+                    received[0] = true;
                 return null;
             }
         });
@@ -127,4 +133,43 @@
         assertEquals("ok", result.getTextContent());
         assertTrue(received[0]);
     }
+
+    public static final String INVOKE_TWO_WAYS =
+            "process InvokeTwoWays {\n" +
+            "    receive(itwPl, itwOp) { |initial|\n" +
+            "        operands = <operands></operands>; \n"+
+            "        operands.op1 = initial; \n"+
+            "        operands.op2 = 3; \n"+
+            "        invoke(calculator, add, operands) { |result| \n" +
+            "           response = result; \n" +
+            "        }" +
+            "        reply(result);\n" +
+            "    }\n" +
+            "}";
+
+    public void testInvokeTwoWays() throws Exception {
+        EmbeddedServer server = new  EmbeddedServer();
+        server.options.setMessageSender(new MessageSender() {
+            public Node send(String recipient, String operation, Node elmt) {
+                if (recipient.equals("calculator") && operation.equals("add")) {
+                    Document doc = DOMUtils.newDocument();
+                    int result = 0;
+                    NodeList nl = elmt.getChildNodes();
+                    for (int m = 0; m < nl.getLength(); m++)
+                        if (nl.item(m).getNodeType() == Node.ELEMENT_NODE)
+                            result += Integer.parseInt(nl.item(m).getTextContent());
+                    return doc.createTextNode(""+result);
+                } else return null;
+            }
+        });
+        server.start();
+        server.deploy(INVOKE_TWO_WAYS);
+
+        Element wrapper = DOMUtils.stringToDOM(
+                "<xd:itwOpRequest xmlns:xd=\"http://ode.apache.org/simpel/1.0/definition/InvokeTwoWays\">7</xd:itwOpRequest>");
+        Element result = server.sendMessage("itwPl", "itwOp", wrapper);
+        assertNotNull(result);
+        System.out.println(DOMUtils.domToString(result));
+        assertEquals("10", result.getTextContent());
+    }
 }

Modified: ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel?rev=697290&r1=697289&r2=697290&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel (original)
+++ ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel Fri Sep 19 16:53:50 2008
@@ -197,17 +197,6 @@
 }
 
 #=============================================================
-# Compact process
-#
-
-process CompactProcess
-  while(count < 10)
-    receive(p, o) { |m|
-      count = count + 1;
-      if (count == 10) invoke(count_partner, count_done);
-    }
-
-#=============================================================
 # External Counter
 #
 



Mime
View raw message