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/11 23:51:56 UTC

svn commit: r1659105 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml2/SCInstance.java main/java/org/apache/commons/scxml2/SCXMLExecutor.java test/java/org/apache/commons/scxml2/w3c/W3CTests.java

Author: ate
Date: Wed Feb 11 22:51:56 2015
New Revision: 1659105

URL: http://svn.apache.org/r1659105
Log:
SCXML-101: add support for using a 'single' global Context, required for some of the (datamodel specific) IRP tests of the W3C specification.

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/w3c/W3CTests.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=1659105&r1=1659104&r2=1659105&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 Wed Feb 11 22:51:56 2015
@@ -129,6 +129,11 @@ public class SCInstance implements Seria
     private Context globalContext;
 
     /**
+     * Flag indicating if the globalContext is shared between all states (a single flat context, default false)
+     */
+    private boolean singleContext;
+
+    /**
      * Constructor
      * @param internalIOProcessor The I/O Processor for the internal event queue
      * @param evaluator The evaluator
@@ -259,6 +264,17 @@ public class SCInstance implements Seria
         initialize();
     }
 
+    public void setSingleContext(boolean singleContext) throws ModelException {
+        if (initialized) {
+            throw new ModelException("SCInstance: already initialized");
+        }
+        this.singleContext = singleContext;
+    }
+
+    public boolean isSingleContext() {
+        return singleContext;
+    }
+
     /**
      * Clone data model.
      *
@@ -438,12 +454,17 @@ public class SCInstance implements Seria
     public Context getContext(final EnterableState state) {
         Context context = contexts.get(state);
         if (context == null) {
-            EnterableState parent = state.getParent();
-            if (parent == null) {
-                // docroot
-                context = evaluator.newContext(getGlobalContext());
-            } else {
-                context = evaluator.newContext(getContext(parent));
+            if (singleContext) {
+                context = getGlobalContext();
+            }
+            else {
+                EnterableState parent = state.getParent();
+                if (parent == null) {
+                    // docroot
+                    context = evaluator.newContext(getGlobalContext());
+                } else {
+                    context = evaluator.newContext(getContext(parent));
+                }
             }
             if (state instanceof TransitionalState) {
                 Datamodel datamodel = ((TransitionalState)state).getDatamodel();

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=1659105&r1=1659104&r2=1659105&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 Wed Feb 11 22:51:56 2015
@@ -191,6 +191,14 @@ public class SCXMLExecutor implements SC
         exctx.getScInstance().setRootContext(rootContext);
     }
 
+    public void setSingleContext(boolean singleContext) throws ModelException {
+        getSCInstance().setSingleContext(singleContext);
+    }
+
+    public boolean isSingleContext() {
+        return getSCInstance().isSingleContext();
+    }
+
     /**
      * Get the state machine that is being executed.
      * <b>NOTE:</b> This is the state machine definition or model used by this

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/w3c/W3CTests.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/w3c/W3CTests.java?rev=1659105&r1=1659104&r2=1659105&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/w3c/W3CTests.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/w3c/W3CTests.java Wed Feb 11 22:51:56 2015
@@ -728,6 +728,7 @@ public class W3CTests {
                 return false;
             }
             final SCXMLExecutor exec = new SCXMLExecutor(null, null, trc);
+            exec.setSingleContext(true);
             exec.setStateMachine(doc);
             exec.addListener(doc, trc);
             exec.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);