You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2010/01/16 00:01:17 UTC

svn commit: r899839 - in /commons/proper/scxml/branches/J6/src: main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java test/java/org/apache/commons/scxml/history-parallel-01.xml test/java/org/apache/commons/scxml/model/HistoryTest.java

Author: rahul
Date: Fri Jan 15 23:01:17 2010
New Revision: 899839

URL: http://svn.apache.org/viewvc?rev=899839&view=rev
Log:
Add support for <history> in <parallel> states. Also added a corresponding test case from a recent user list posting.

Added:
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/history-parallel-01.xml   (with props)
Modified:
    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/HistoryTest.java

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=899839&r1=899838&r2=899839&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 Fri Jan 15 23:01:17 2010
@@ -583,19 +583,18 @@
             final ErrorReporter errRep, final SCInstance scInstance) {
         Set<TransitionTarget> oldStates = step.getBeforeStatus().getStates();
         for (TransitionTarget tt : step.getExitList()) {
-            if (tt instanceof State) {
-                State s = (State) tt;
-                if (s.hasHistory()) {
+            if (tt instanceof State || tt instanceof Parallel) {
+                if (tt.hasHistory()) {
                     Set<TransitionTarget> shallow = null;
                     Set<TransitionTarget> deep = null;
-                    for (History h : s.getHistory()) {
+                    for (History h : tt.getHistory()) {
                         if (h.isDeep()) {
                             if (deep == null) {
                                 //calculate deep history for a given state once
                                 deep = new HashSet<TransitionTarget>();
                                 for (TransitionTarget ott : oldStates) {
                                     State os = (State) ott;
-                                    if (SCXMLHelper.isDescendant(os, s)) {
+                                    if (SCXMLHelper.isDescendant(os, tt)) {
                                         deep.add(os);
                                     }
                                 }
@@ -606,7 +605,15 @@
                                 //calculate shallow history for a given state
                                 // once
                                 shallow = new HashSet<TransitionTarget>();
-                                shallow.addAll(s.getChildren().values());
+                                Collection<TransitionTarget> children =
+                                    new HashSet<TransitionTarget>();
+                                if (tt instanceof State) {
+                                    children = ((State) tt).getChildren().
+                                        values();
+                                } else if (tt instanceof Parallel) {
+                                    children = ((Parallel) tt).getChildren();
+                                }
+                                shallow.addAll(children);
                                 shallow.retainAll(SCXMLHelper
                                         .getAncestorClosure(oldStates, null));
                             }

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/history-parallel-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/history-parallel-01.xml?rev=899839&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/history-parallel-01.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/history-parallel-01.xml Fri Jan 15 23:01:17 2010
@@ -0,0 +1,76 @@
+<?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.
+-->
+<!--
+   This document is an example of using history in parallel
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
+        initial="off_call">
+
+    <state id="off_call">
+        <transition event="dial" target="call_active"/>
+    </state>
+
+    <parallel id="call_active">
+
+        <state id="talk_status" initial="talking">
+            <state id="talking">
+                <transition event="hold"      target="held" />
+            </state>
+            <state id="held">
+                <transition event="retrieve"  target="talking" />
+            </state>
+        </state>
+
+        <state id="call_status" initial="on_call">
+            <state id="on_call">
+                <transition event="hangup"    target="off_call"/>
+                <transition event="consult"   target="consult_active"/>
+            </state>                
+            <state id="on_call_consult">
+                <transition event="hangup"    target="off_call"/>
+                <transition event="alternate" target="resume_consult"/>
+            </state>
+        </state>
+
+        <history id="resume_call" type="deep"/>
+
+    </parallel>
+
+    <parallel id="consult_active">
+
+        <state id="consult_talk_status" initial="consult_talking">
+            <state id="consult_talking">
+                <transition event="hold"      target="consult_held" />
+            </state>
+            <state id="consult_held">
+                <transition event="retrieve"  target="consult_talking" />
+            </state>
+        </state>
+
+        <state id="consult_status" initial="on_consult">
+            <state id="on_consult">
+                <transition event="hangup"    target="resume_call"/>
+                <transition event="alternate" target="resume_call"/>
+            </state>
+        </state>
+
+        <history id="resume_consult" type="deep"/>
+
+    </parallel>
+
+</scxml>

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/history-parallel-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/HistoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/HistoryTest.java?rev=899839&r1=899838&r2=899839&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/HistoryTest.java (original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/HistoryTest.java Fri Jan 15 23:01:17 2010
@@ -46,7 +46,7 @@
 
     // Test data
     private History history;
-    private URL shallow01, deep01, defaults01;
+    private URL shallow01, deep01, defaults01, parallel01;
     private SCXMLExecutor exec;
 
     /**
@@ -61,6 +61,8 @@
             getResource("org/apache/commons/scxml/history-deep-01.xml");
         defaults01 = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/history-default-01.xml");
+        parallel01 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/history-parallel-01.xml");
     }
 
     /**
@@ -69,7 +71,7 @@
     @Override
     public void tearDown() {
         history = null;
-        shallow01 = deep01 = defaults01 = null;
+        shallow01 = deep01 = defaults01 = parallel01 = null;
         exec = null;
     }
 
@@ -111,6 +113,22 @@
         assertEquals("state31", currentStates.iterator().next().getId());
     }
 
+    public void testHistoryParallel01() throws Exception {
+        exec = SCXMLTestHelper.getExecutor(parallel01);
+        Set<TransitionTarget> currentStates = exec.getCurrentStatus().getStates();
+        assertEquals(1, currentStates.size());
+        SCXMLTestHelper.assertState(exec, "off_call");
+        SCXMLTestHelper.assertPostTriggerStates(exec, "dial", new String[] { "talking", "on_call" });
+        SCXMLTestHelper.assertPostTriggerStates(exec, "consult", new String[] { "consult_talking", "on_consult" });
+        // Next line uses history to go back to on call and talking
+        SCXMLTestHelper.assertPostTriggerStates(exec, "alternate", new String[] { "talking", "on_call" });
+        // Hold
+        SCXMLTestHelper.assertPostTriggerStates(exec, "hold", new String[] { "held", "on_call" });
+        SCXMLTestHelper.assertPostTriggerStates(exec, "consult", new String[] { "consult_talking", "on_consult" });
+        // Next line uses history to go back to on call and on hold
+        SCXMLTestHelper.assertPostTriggerStates(exec, "alternate", new String[] { "held", "on_call" });
+    }
+
     private void runHistoryFlow() throws Exception {
         Set<TransitionTarget> currentStates = exec.getCurrentStatus().getStates();
         assertEquals(1, currentStates.size());