You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2015/02/12 02:30:49 UTC

svn commit: r1659121 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml2/ test/java/org/apache/commons/scxml2/ test/java/org/apache/commons/scxml2/env/javascript/ test/java/org/apache/commons/scxml2/model/

Author: ate
Date: Thu Feb 12 01:30:48 2015
New Revision: 1659121

URL: http://svn.apache.org/r1659121
Log:
SCXML-101: initialize and store the global (scxml) datamodel in the GlobalContext instead of the RootContext
- this might have some impact on external usages which assumed and (mis)used the RootContext to access the global datamodel variables, like several scxml unit tests

Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/NamespacePrefixedXPathsTest.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CustomActionTest.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ParallelTest.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java?rev=1659121&r1=1659120&r2=1659121&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java Thu Feb 12 01:30:48 2015
@@ -176,7 +176,7 @@ public class SCInstance implements Seria
 
         // Clone root datamodel
         Datamodel rootdm = stateMachine.getDatamodel();
-        cloneDatamodel(rootdm, getRootContext(), evaluator, errorReporter);
+        cloneDatamodel(rootdm, getGlobalContext(), evaluator, errorReporter);
         initialized = true;
     }
 

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java?rev=1659121&r1=1659120&r2=1659121&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java Thu Feb 12 01:30:48 2015
@@ -198,6 +198,9 @@ public class SCXMLExecutor implements SC
 
     /**
      * Get the root context for the state machine execution.
+     * <p>
+     * The root context can be used for providing external data to the state machine
+     * </p>
      *
      * @return Context The root context.
      */
@@ -206,6 +209,18 @@ public class SCXMLExecutor implements SC
     }
 
     /**
+     * Get the global context for the state machine execution.
+     * <p>
+     * The global context is the top level context within the state machine itself and should be regarded and treated
+     * "read-only" from external usage.
+     * </p>
+     * @return Context The global context.
+     */
+    public Context getGlobalContext() {
+        return exctx.getScInstance().getGlobalContext();
+    }
+
+    /**
      * Set the root context for the state machine execution.
      * <b>NOTE:</b> Should only be used before the executor is set in motion.
      *

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/NamespacePrefixedXPathsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/NamespacePrefixedXPathsTest.java?rev=1659121&r1=1659120&r2=1659121&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/NamespacePrefixedXPathsTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/NamespacePrefixedXPathsTest.java Thu Feb 12 01:30:48 2015
@@ -51,7 +51,7 @@ public class NamespacePrefixedXPathsTest
         Assert.assertEquals("twenty", currentStates.iterator().next().getId());
 
         // This is set while exiting "ten"
-        Double retval = (Double) exec.getRootContext().get("retval");
+        Double retval = (Double) exec.getGlobalContext().get("retval");
         Assert.assertEquals(Double.valueOf("11"), retval);
 
         // On to "thirty"
@@ -61,7 +61,7 @@ public class NamespacePrefixedXPathsTest
         exec = SCXMLTestHelper.testInstanceSerializability(exec);
 
         // Tests XPath on SCXML actions, set while exiting "twenty"
-        String retvalstr = (String) exec.getRootContext().get("retval");
+        String retvalstr = (String) exec.getGlobalContext().get("retval");
         Assert.assertEquals("Equal to 20", retvalstr);
 
         // and so on ...

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java?rev=1659121&r1=1659120&r2=1659121&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java Thu Feb 12 01:30:48 2015
@@ -114,7 +114,7 @@ public class JSEvaluatorTest {
     public void setUp() throws Exception {
             fsm = SCXMLTestHelper.getExecutor(SCXMLReader.read(new StringReader(SCRIPT)));
             evaluator = fsm.getEvaluator();
-            context = fsm.getRootContext();
+            context = fsm.getGlobalContext();
             context.set(Context.NAMESPACES_KEY,null);
     }
 

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CustomActionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CustomActionTest.java?rev=1659121&r1=1659120&r2=1659121&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CustomActionTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CustomActionTest.java Thu Feb 12 01:30:48 2015
@@ -208,7 +208,7 @@ public class CustomActionTest {
                                 iterator().next()).getId());
         // (5) Verify datamodel variable is correct
         Assert.assertEquals("Missing helloName1 in root context", "custom04a",
-                     exec.getRootContext().get("helloName1"));
+                     exec.getGlobalContext().get("helloName1"));
 
         // The custom action defined by Hello.class should be called
         // to execute() exactly once at this point (by onentry in init state).
@@ -218,7 +218,7 @@ public class CustomActionTest {
         SCXMLTestHelper.fireEvent(exec, "custom.next");
         // (7) Verify correct end state
         Assert.assertEquals("Missing helloName1 in root context", "custom04b",
-                exec.getRootContext().get("helloName1"));
+                exec.getGlobalContext().get("helloName1"));
         Assert.assertEquals("Invalid final state",
                 "end", (exec.getStatus().getStates().
                 iterator().next()).getId());

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ParallelTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ParallelTest.java?rev=1659121&r1=1659120&r2=1659121&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ParallelTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ParallelTest.java Thu Feb 12 01:30:48 2015
@@ -43,13 +43,13 @@ public class ParallelTest {
         SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/parallel-03.xml");
         exec.go();
         SCXMLTestHelper.assertPostTriggerStates(exec, "dummy.event", new String[] { "para11", "para21" });
-        Object count = exec.getEvaluator().eval(exec.getRootContext(),"Data('string(root/root/count)')");
+        Object count = exec.getEvaluator().eval(exec.getGlobalContext(),"Data('string(root/root/count)')");
         Assert.assertEquals("5.0", count.toString());
         SCXMLTestHelper.assertPostTriggerStates(exec, "foo", new String[] { "para12", "para21" });
-        count = exec.getEvaluator().eval(exec.getRootContext(),"Data('string(root/root/count)')");
+        count = exec.getEvaluator().eval(exec.getGlobalContext(),"Data('string(root/root/count)')");
         Assert.assertEquals("7.0", count.toString());
         SCXMLTestHelper.assertPostTriggerState(exec, "bar", "end");
-        count = exec.getEvaluator().eval(exec.getRootContext(),"Data('string(root/root/count)')");
+        count = exec.getEvaluator().eval(exec.getGlobalContext(),"Data('string(root/root/count)')");
         Assert.assertEquals("14.0", count.toString());
     }
 }