commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r542582 - in /jakarta/commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/ main/java/org/apache/commons/scxml/model/ test/java/org/apache/commons/scxml/ test/java/org/apache/commons/scxml/env/jexl/
Date Tue, 29 May 2007 16:31:03 GMT
Author: rahul
Date: Tue May 29 09:31:02 2007
New Revision: 542582

URL: http://svn.apache.org/viewvc?view=rev&rev=542582
Log:
SCXML-45
Payload of events sent to current scxml session using <send> tag not injected into engine

This has been implemented (with a test case), however note the following caveat --

The spec doesn't clarify how multiple <send> elements that create derived events should
be handled, so for example:

<onentry>
  <send event="ev.foo" namelist="alpha beta"/>
  <send event="ev.bar" namelist="gamma delta"/>
</onentry>

I think they should be processed together (this makes sense to leverage parallel regions for
example), and due to that '_eventdata' becomes ambiguous in this scenario. The Commons SCXML
implementation introduces an implicit variable '_eventdatamap' for such scenarios wherein
the event datas are stored keyed by event name.

So, the two <send> events above could be processed by two regions like so:

<parallel>

  <state id="region1">

     <transition event="ev.foo" cond="_eventdatamap['ev.foo'].alpha eq 'somevalue'"
                 target="..." />

     <!-- ... -->

  </state>

  <state id="region2">

     <transition event="ev.bar" cond="_eventdatamap['ev.bar'].delta eq 'othervalue'"
                 target="..." />

     <!-- ... -->

  </state>

  <!-- ... -->

</parallel>

To summarize, the _eventdatamap variable needs to be used in association with "derived" (such
as <send> being discussed here) events. Also note that this behavior may change if there
is clarity in the specification at some point.

Added:
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml
  (with props)
Modified:
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java?view=diff&rev=542582&r1=542581&r2=542582
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
Tue May 29 09:31:02 2007
@@ -536,6 +536,8 @@
         currentStatus = step.getAfterStatus();
         scInstance.getRootContext().setLocal("_ALL_STATES",
             SCXMLHelper.getAncestorClosure(currentStatus.getStates(), null));
+        setEventData((TriggerEvent[]) currentStatus.getEvents().
+            toArray(new TriggerEvent[0]));
     }
 
     /**

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java?view=diff&rev=542582&r1=542581&r2=542582
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
Tue May 29 09:31:02 2007
@@ -328,7 +328,7 @@
                             + "' with no delay");
                     }
                     derivedEvents.add(new TriggerEvent(event,
-                        TriggerEvent.SIGNAL_EVENT));
+                        TriggerEvent.SIGNAL_EVENT, params));
                     return;
                 }
             } else {

Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java?view=diff&rev=542582&r1=542581&r2=542582
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java
Tue May 29 09:31:02 2007
@@ -45,7 +45,7 @@
     }
 
     // Test data
-    private URL eventdata01, eventdata02;
+    private URL eventdata01, eventdata02, eventdata03;
     private SCXMLExecutor exec;
 
     /**
@@ -56,13 +56,15 @@
             getResource("org/apache/commons/scxml/env/jexl/eventdata-01.xml");
         eventdata02 = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/env/jexl/eventdata-02.xml");
+        eventdata03 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/env/jexl/eventdata-03.xml");
     }
 
     /**
      * Tear down instance variables required by this test case.
      */
     public void tearDown() {
-        eventdata01 = eventdata02 = null;
+        eventdata01 = eventdata02 = eventdata03 = null;
     }
 
     /**
@@ -120,6 +122,25 @@
             currentStates = SCXMLTestHelper.fireEvent(exec, te2);
             assertEquals(1, currentStates.size());
             assertEquals("state4", ((State)currentStates.iterator().
+                next()).getId());
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
+    public void testEventdata03Sample() {
+        exec = SCXMLTestHelper.getExecutor(eventdata03);
+        assertNotNull(exec);
+        try {
+            Set currentStates = exec.getCurrentStatus().getStates();
+            assertEquals(1, currentStates.size());
+            assertEquals("ten", ((State)currentStates.iterator().
+                next()).getId());
+            TriggerEvent te = new TriggerEvent("event.foo",
+                TriggerEvent.SIGNAL_EVENT);
+            currentStates = SCXMLTestHelper.fireEvent(exec, te);
+            assertEquals(1, currentStates.size());
+            assertEquals("thirty", ((State)currentStates.iterator().
                 next()).getId());
         } catch (Exception e) {
             fail(e.getMessage());

Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml?view=auto&rev=542582
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml
(added)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml
Tue May 29 09:31:02 2007
@@ -0,0 +1,48 @@
+<?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.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+      version="1.0"
+      initialstate="ten">
+
+    <datamodel>
+        <data name="rootdata">
+            <root xmlns="">
+                <one>1</one>
+                <two>2</two>
+            </root>
+        </data>
+    </datamodel>
+
+    <state id="ten">
+        <transition event="event.foo" target="twenty"/>
+    </state>
+
+    <state id="twenty">
+        <onentry>
+            <var name="one" expr="Data(rootdata,'root/one')"/>
+            <var name="two" expr="Data(rootdata,'root/two')"/>
+            <send event="event.bar" namelist="one two"/>
+        </onentry>
+        <transition event="event.bar"
+            cond="_eventdatamap['event.bar'].one + _eventdatamap['event.bar'].two eq 3"
+            target="thirty"/>
+    </state>
+
+    <state id="thirty" final="true"/>
+
+</scxml>

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-03.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message