commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r719076 - in /commons/proper/scxml/branches/J6/src: main/java/org/apache/commons/scxml/io/ main/java/org/apache/commons/scxml/model/ main/java/org/apache/commons/scxml/semantics/ test/java/org/apache/commons/scxml/model/
Date Wed, 19 Nov 2008 21:21:51 GMT
Author: rahul
Date: Wed Nov 19 13:21:50 2008
New Revision: 719076

URL: http://svn.apache.org/viewvc?rev=719076&view=rev
Log:
Porting r719073 from trunk.
Support executable content in <transition> child of <initial> as specified in
the latest WD:
 * with the exception of <cs:exit>
 * added a related test case.

Added:
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml
  (with props)
Modified:
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Action.java
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionTest.java
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionsTest.java
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java

Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=719076&r1=719075&r2=719076&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
(original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
Wed Nov 19 13:21:50 2008
@@ -1010,9 +1010,17 @@
         scxmlRules.add(xp + XPF_EXT, new Rule() {
             public void end(final String namespace, final String name) {
                 Transition t = (Transition) getDigester().peek(1);
-                State exitState = new State();
-                exitState.setFinal(true);
-                t.getTargets().add(exitState);
+                TransitionTarget tt = (TransitionTarget) getDigester().
+                    peek(2);
+                if (tt instanceof Initial) {
+                    org.apache.commons.logging.Log log = LogFactory.
+                        getLog(SCXMLParser.class);
+                    log.warn("Ignored <exit> action in <initial>");
+                } else {
+                    State exitState = new State();
+                    exitState.setFinal(true);
+                    t.getTargets().add(exitState);
+                }
             }
         });
         scxmlRules.setNamespaceURI(NAMESPACE_SCXML);

Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Action.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Action.java?rev=719076&r1=719075&r2=719076&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Action.java
(original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Action.java
Wed Nov 19 13:21:50 2008
@@ -111,7 +111,7 @@
         TransitionTarget tt = parent.getParent();
         if (tt instanceof State || tt instanceof Parallel) {
             return tt;
-        } else if (tt instanceof History) {
+        } else if (tt instanceof History || tt instanceof Initial) {
             return tt.getParent();
         } else {
             throw new ModelException("Unknown TransitionTarget subclass:"

Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=719076&r1=719075&r2=719076&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
(original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
Wed Nov 19 13:21:50 2008
@@ -48,6 +48,7 @@
 import org.apache.commons.scxml.model.Action;
 import org.apache.commons.scxml.model.Finalize;
 import org.apache.commons.scxml.model.History;
+import org.apache.commons.scxml.model.Initial;
 import org.apache.commons.scxml.model.Invoke;
 import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.OnEntry;
@@ -249,9 +250,22 @@
             TriggerEvent te = new TriggerEvent(tt.getId() + ".entry",
                     TriggerEvent.CHANGE_EVENT);
             internalEvents.add(te);
-            //3.2.1 and 3.4 (.done events)
+            // actions in initial transition (if any) and .done events
             if (tt instanceof State) {
                 State ts = (State) tt;
+                Initial ini = ts.getInitial();
+                if (ts.isComposite() && ini != null) {
+                    try {
+                        for (Action initialAct : ini.getTransition().
+                                getActions()) {
+                            initialAct.execute(evtDispatcher,
+                                errRep, scInstance, appLog, internalEvents);
+                        }
+                    } catch (SCXMLExpressionException e) {
+                        errRep.onError(ErrorConstants.EXPRESSION_ERROR,
+                            e.getMessage(), ini);
+                    }
+                }
                 if (ts.isFinal()) {
                     State parent = (State) ts.getParent();
                     String prefix = "";

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionTest.java?rev=719076&r1=719075&r2=719076&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionTest.java
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionTest.java
Wed Nov 19 13:21:50 2008
@@ -71,7 +71,7 @@
 
         TransitionTarget returnValue = action.getParentTransitionTarget();
         
-        assertEquals("off", returnValue.getId());
+        assertEquals("on", returnValue.getId());
     }
     
     public void testGetParentStateIsHistory() throws Exception {
@@ -93,21 +93,22 @@
         assertEquals("off", returnValue.getId());
     }
 
-    public void testGetParentStateIsInitial() {
+    public void testGetParentStateIsInitial() throws Exception {
         Transition transition = new Transition();
         
         Initial initial = new Initial();
         initial.setId("on");
- 
+
+        State state = new State();
+        state.setId("off");
+
+        initial.setParent(state);
+
         transition.setParent(initial);
         action.setParent(transition);
 
-        try{
-            action.getParentTransitionTarget();
-            fail("Unknown TransitionTarget subclass:Initial");
-        }
-        catch( ModelException e ){
-        	//ignore
-        }
+        TransitionTarget returnValue = action.getParentTransitionTarget();
+
+        assertEquals("off", returnValue.getId());
     }
 }

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionsTest.java?rev=719076&r1=719075&r2=719076&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionsTest.java
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ActionsTest.java
Wed Nov 19 13:21:50 2008
@@ -54,7 +54,7 @@
     }
 
     // Test data
-    private URL actionsSample01, actionsSample02;
+    private URL actionsSample01, actionsSample02, actionsSample03;
     private ELEvaluator evaluator;
     private ELContext ctx;
     private SCXMLExecutor exec;
@@ -67,6 +67,8 @@
             getResource("org/apache/commons/scxml/model/actions-state-test.xml");
         actionsSample02 = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/model/actions-parallel-test.xml");
+        actionsSample03 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/model/actions-initial-test.xml");
         evaluator = new ELEvaluator();
         ctx = new ELContext();
     }
@@ -75,7 +77,7 @@
      * Tear down instance variables required by this test case.
      */
     public void tearDown() {
-        actionsSample01 = actionsSample02 = null;
+        actionsSample01 = actionsSample02 = actionsSample03 = null;
         evaluator = null;
         ctx = null;
         exec = null;
@@ -86,16 +88,20 @@
      */
     public void testStateActions() {
         SCXML scxml = SCXMLTestHelper.parse(actionsSample01);
-        exec = SCXMLTestHelper.getExecutor(scxml, ctx, evaluator);
-        ELContext ctx = (ELContext) SCXMLTestHelper.lookupContext(exec,
-            "actionsTest");
-        assertEquals((String) ctx.get("foo"), "foobar");
-        assertEquals("Missed event transition",
-            "true", (String) ctx.get("eventsent"));
+        runTest(scxml);
     }
 
     public void testParallelActions() {
         SCXML scxml = SCXMLTestHelper.parse(actionsSample02);
+        runTest(scxml);
+    }
+
+    public void testInitialActions() {
+        SCXML scxml = SCXMLTestHelper.parse(actionsSample03);
+        runTest(scxml);
+    }
+
+    private void runTest(SCXML scxml) {
         exec = SCXMLTestHelper.getExecutor(scxml, ctx, evaluator);
         ELContext ctx = (ELContext) SCXMLTestHelper.lookupContext(exec,
             "actionsTest");

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java?rev=719076&r1=719075&r2=719076&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
Wed Nov 19 13:21:50 2008
@@ -54,6 +54,7 @@
         suite.addTest(CustomActionTest.suite());
         suite.addTest(DatamodelTest.suite());
         suite.addTest(HistoryTest.suite());
+        suite.addTest(ParallelTest.suite());
         suite.addTest(PathTest.suite());
         suite.addTest(StateTest.suite());
         suite.addTest(StatelessModelTest.suite());

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml?rev=719076&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml
(added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml
Wed Nov 19 13:21:50 2008
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<!--
+ * 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"
+       xmlns:cs="http://commons.apache.org/scxml"
+       version="1.0"
+       initial="actionsTest">
+  
+  <state id="actionsTest">
+    <initial>
+      <transition target="child1">
+        <cs:var name="foo"/>
+        <cs:var name="delta" expr="${1+2+3}" />
+        <cs:var name="eventsent"/>
+        <if cond="${delta le 3}">
+          <assign name="foo" expr="bar" />
+        <elseif cond="${delta eq 3}"/>
+          <assign name="foo" expr="fubar" />
+        <else/>
+          <assign name="foo" expr="foobar" />
+        </if>
+        <cs:var name="drink" expr="water" />
+        <cs:var name="eat" expr="flies" />
+        <send sendid="send12345" target="freddy" targettype="frog"
+         event="croak" namelist="drink eat" hints="h2o bzz"
+         delay="${1000+500}" />
+        <cancel sendId="send12345"/>
+        <log expr="leaving" label="entry001" />
+        <event name="event.test"/>
+        <!-- exit will be ignored, makes little sense in initial -->
+        <cs:exit expr="later" namelist="freddy" />
+      </transition>
+    </initial>
+
+    <transition event="event.test">
+      <assign name="eventsent" expr="true"/>
+    </transition>
+
+    <state id="child1"/>
+
+  </state>
+
+</scxml>

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/actions-initial-test.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message