commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r373328 - in /jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml: NotificationRegistry.java Registry.java SCXMLExecutor.java SCXMLSemantics.java semantics/SCXMLSemanticsImpl.java
Date Sun, 29 Jan 2006 17:39:43 GMT
Author: rahul
Date: Sun Jan 29 09:39:39 2006
New Revision: 373328

URL: http://svn.apache.org/viewcvs?rev=373328&view=rev
Log:
In a stateless model, the state of execution focuses around a "registry" maintained by the
SCXMLExecutor, which performs book-keeping functions concerning a particular execution instance
of the state machine.

The NotificationRegistry and SCXMLExecutor have to deal with the absence of the Observable
interface in the Commons SCXML object model, and therefore, what was earlier effectively:

 addListener(Observable, SCXMLListener)

now becomes (effectively):

 * addListener(SCXML, SCXMLListener)
 * addListener(TransitionTarget, SCXMLListener)
 * addListener(Transition, SCXMLListener)

since listeners may be attached to o.a.c.s.m.{SCXML,TransitionTarget,Transition} which are
the interesting elements for tracking execution.

Some qualifiers and access modifiers have been appropriately constrained in this commit.


Added:
    jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java
  (with props)
Modified:
    jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
    jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
    jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java
    jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java

Modified: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/NotificationRegistry.java?rev=373328&r1=373327&r2=373328&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
(original)
+++ jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
Sun Jan 29 09:39:39 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.Transition;
 import org.apache.commons.scxml.model.TransitionTarget;
 
@@ -32,7 +33,7 @@
  * all listeners of the events of interest.
  *
  */
-public class NotificationRegistry {
+public final class NotificationRegistry {
 
     /**
      * The Map of all listeners keyed by Observable.
@@ -52,7 +53,7 @@
      * @param source The observable this listener wants to listen to
      * @param lst The listener
      */
-    public final void addListener(final Observable source,
+    void addListener(final Object source,
             final SCXMLListener lst) {
         Set entries = (Set) regs.get(source);
         if (entries == null) {
@@ -68,7 +69,7 @@
      * @param source The observable this listener wants to stop listening to
      * @param lst The listener
      */
-    public final void removeListener(final Observable source,
+    void removeListener(final Object source,
             final SCXMLListener lst) {
         Set entries = (Set) regs.get(source);
         if (entries != null) {
@@ -83,10 +84,36 @@
      * Inform all relevant listeners that a TransitionTarget has been
      * entered.
      *
+     * @param observable The Observable
+     * @param state The TransitionTarget that was entered
+     */
+    public void fireOnEntry(final TransitionTarget observable,
+            final TransitionTarget state) {
+        Object source = observable;
+        fireOnEntry(source, state);
+    }
+
+    /**
+     * Inform all relevant listeners that a TransitionTarget has been
+     * entered.
+     *
+     * @param observable The Observable
+     * @param state The TransitionTarget that was entered
+     */
+    public void fireOnEntry(final SCXML observable,
+            final TransitionTarget state) {
+        Object source = observable;
+        fireOnEntry(source, state);
+    }
+
+    /**
+     * Inform all relevant listeners that a TransitionTarget has been
+     * entered.
+     *
      * @param source The Observable
      * @param state The TransitionTarget that was entered
      */
-    public final void fireOnEntry(final Observable source,
+    private void fireOnEntry(final Object source,
             final TransitionTarget state) {
         Set entries = (Set) regs.get(source);
         if (entries != null) {
@@ -101,10 +128,36 @@
      * Inform all relevant listeners that a TransitionTarget has been
      * exited.
      *
+     * @param observable The Observable
+     * @param state The TransitionTarget that was exited
+     */
+    public void fireOnExit(final TransitionTarget observable,
+            final TransitionTarget state) {
+        Object source = observable;
+        fireOnExit(source, state);
+    }
+
+    /**
+     * Inform all relevant listeners that a TransitionTarget has been
+     * exited.
+     *
+     * @param observable The Observable
+     * @param state The TransitionTarget that was exited
+     */
+    public void fireOnExit(final SCXML observable,
+            final TransitionTarget state) {
+        Object source = observable;
+        fireOnExit(source, state);
+    }
+
+    /**
+     * Inform all relevant listeners that a TransitionTarget has been
+     * exited.
+     *
      * @param source The Observable
      * @param state The TransitionTarget that was exited
      */
-    public final void fireOnExit(final Observable source,
+    private void fireOnExit(final Object source,
             final TransitionTarget state) {
         Set entries = (Set) regs.get(source);
         if (entries != null) {
@@ -118,12 +171,42 @@
     /**
      * Inform all relevant listeners of a transition that has occured.
      *
+     * @param observable The Observable
+     * @param from The source TransitionTarget
+     * @param to The destination TransitionTarget
+     * @param transition The Transition that was taken
+     */
+    public void fireOnTransition(final Transition observable,
+            final TransitionTarget from, final TransitionTarget to,
+            final Transition transition) {
+        Object source = observable;
+        fireOnTransition(source, from, to, transition);
+    }
+
+    /**
+     * Inform all relevant listeners of a transition that has occured.
+     *
+     * @param observable The Observable
+     * @param from The source TransitionTarget
+     * @param to The destination TransitionTarget
+     * @param transition The Transition that was taken
+     */
+    public void fireOnTransition(final SCXML observable,
+            final TransitionTarget from, final TransitionTarget to,
+            final Transition transition) {
+        Object source = observable;
+        fireOnTransition(source, from, to, transition);
+    }
+
+    /**
+     * Inform all relevant listeners of a transition that has occured.
+     *
      * @param source The Observable
      * @param from The source TransitionTarget
      * @param to The destination TransitionTarget
      * @param transition The Transition that was taken
      */
-    public final void fireOnTransition(final Observable source,
+    private void fireOnTransition(final Object source,
             final TransitionTarget from, final TransitionTarget to,
             final Transition transition) {
         Set entries = (Set) regs.get(source);
@@ -134,5 +217,6 @@
             }
         }
     }
+
 }
 

Added: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java?rev=373328&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java
(added)
+++ jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java
Sun Jan 29 09:39:39 2006
@@ -0,0 +1,230 @@
+/*
+ *
+ *   Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed 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.
+ *
+ */
+package org.apache.commons.scxml;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.scxml.model.History;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+/**
+ * The <code>Registry</code> performs book-keeping functions for
+ * a particular execution of a state machine represented by the
+ * a <code>SCXML</code> object.
+ */
+public class Registry {
+
+    /**
+     * The notification registry.
+     */
+    private NotificationRegistry notificationRegistry;
+
+    /**
+     * The <code>Map</code> of <code>Context</code>s per
+     * <code>TransitionTarget</code>.
+     */
+    private Map contexts;
+
+    /**
+     * The <code>Map</code> of last known configurations per
+     * <code>History</code>.
+     */
+    private Map histories;
+
+    /**
+     * The evaluator for expressions.
+     */
+    private Evaluator evaluator;
+
+    /**
+     * The root context.
+     */
+    private Context rootContext;
+
+    /**
+     * Constructor.
+     */
+    Registry() {
+        this.notificationRegistry = new NotificationRegistry();
+        this.contexts = new HashMap();
+        this.histories = new HashMap();
+        this.evaluator = null;
+        this.rootContext = null;
+    }
+
+    /**
+     * Get the <code>Evaluator</code>.
+     *
+     * @return The evaluator.
+     */
+    public Evaluator getEvaluator() {
+        return evaluator;
+    }
+
+    /**
+     * Set the <code>Evaluator</code>.
+     *
+     * @param evaluator The evaluator.
+     */
+    void setEvaluator(final Evaluator evaluator) {
+        this.evaluator = evaluator;
+    }
+
+    /**
+     * Get the root context.
+     *
+     * @return The root context.
+     */
+    public Context getRootContext() {
+        if (rootContext == null && evaluator != null) {
+            rootContext = evaluator.newContext(null);
+        }
+        return rootContext;
+    }
+
+    /**
+     * Set the root context.
+     *
+     * @param context The root context.
+     */
+    void setRootContext(final Context context) {
+        this.rootContext = context;
+    }
+
+    /**
+     * Get the notification registry.
+     *
+     * @return The notification registry.
+     */
+    public NotificationRegistry getNotificationRegistry() {
+        return notificationRegistry;
+    }
+
+    /**
+     * Set the notification registry.
+     *
+     * @param notifRegistry The notification registry.
+     */
+    void setNotificationRegistry(final NotificationRegistry notifRegistry) {
+        this.notificationRegistry = notifRegistry;
+    }
+
+    /**
+     * Get the <code>Context</code> for this <code>TransitionTarget</code>.
+     * If one is not available it is created.
+     *
+     * @param transitionTarget The TransitionTarget.
+     * @return The Context.
+     */
+    public Context getContext(final TransitionTarget transitionTarget) {
+        Context context = (Context) contexts.get(transitionTarget);
+        if (context == null) {
+            TransitionTarget parent = transitionTarget.getParent();
+            if (parent == null) {
+                // docroot
+                context = evaluator.newContext(getRootContext());
+            } else {
+                context = evaluator.newContext(getContext(parent));
+            }
+            contexts.put(transitionTarget, context);
+        }
+        return context;
+    }
+
+    /**
+     * Get the <code>Context</code> for this <code>TransitionTarget</code>.
+     * May return <code>null</code>.
+     *
+     * @param transitionTarget The <code>TransitionTarget</code>.
+     * @return The Context.
+     */
+    Context lookupContext(final TransitionTarget transitionTarget) {
+        return (Context) contexts.get(transitionTarget);
+    }
+
+    /**
+     * Set the <code>Context</code> for this <code>TransitionTarget</code>.
+     *
+     * @param transitionTarget The TransitionTarget.
+     * @param context The Context.
+     */
+    void setContext(final TransitionTarget transitionTarget,
+            final Context context) {
+        contexts.put(transitionTarget, context);
+    }
+
+    /**
+     * Get the last configuration for this history.
+     *
+     * @param history The history.
+     * @return Returns the lastConfiguration.
+     */
+    public Set getLastConfiguration(final History history) {
+        Set lastConfiguration = (Set) histories.get(history);
+        if (lastConfiguration == null) {
+            lastConfiguration = new HashSet();
+            histories.put(history, lastConfiguration);
+        }
+        return lastConfiguration;
+    }
+
+    /**
+     * Set the last configuration for this history.
+     *
+     * @param history The history.
+     * @param lc The lastConfiguration to set.
+     */
+    public void setLastConfiguration(final History history,
+            final Set lc) {
+        Set lastConfiguration = getLastConfiguration(history);
+        lastConfiguration.clear();
+        lastConfiguration.addAll(lc);
+    }
+
+    /**
+     * Check whether we have prior history.
+     *
+     * @param history The history.
+     * @return Whether we have a non-empty last configuration
+     */
+    public boolean isEmpty(final History history) {
+        Set lastConfiguration = (Set) histories.get(history);
+        if (lastConfiguration == null || lastConfiguration.isEmpty()) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Resets the history state.
+     *
+     * @param history The history.
+     * @see org.apache.commons.scxml.SCXMLExecutor#reset()
+     */
+    public void reset(final History history) {
+        Set lastConfiguration = (Set) histories.get(history);
+        if (lastConfiguration != null) {
+            lastConfiguration.clear();
+        }
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/Registry.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java?rev=373328&r1=373327&r2=373328&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
(original)
+++ jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
Sun Jan 29 09:39:39 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
 import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.Transition;
 import org.apache.commons.scxml.model.TransitionTarget;
 import org.apache.commons.scxml.semantics.SCXMLSemanticsImpl;
 
@@ -53,11 +54,6 @@
     private SCXML stateMachine;
 
     /**
-     * The evaluator for expressions.
-     */
-    private Evaluator evaluator;
-
-    /**
      * The current status of the stateMachine.
      */
     private Status currentStatus;
@@ -83,6 +79,11 @@
     private SCXMLSemantics semantics;
 
     /**
+     * The Registry.
+     */
+    private Registry registry;
+
+    /**
      * The worker method.
      * Re-evaluates current status whenever any events are triggered.
      *
@@ -102,14 +103,14 @@
             semantics.enumerateReachableTransitions(stateMachine, step,
                     errorReporter);
             // FilterTransitionSet
-            semantics.filterTransitionsSet(step, evaluator, errorReporter);
+            semantics.filterTransitionsSet(step, errorReporter, registry);
             // FollowTransitions
-            semantics.followTransitions(step, errorReporter);
+            semantics.followTransitions(step, errorReporter, registry);
             // UpdateHistoryStates
-            semantics.updateHistoryStates(step, errorReporter);
+            semantics.updateHistoryStates(step, errorReporter, registry);
             // ExecuteActions
-            semantics.executeActions(step, stateMachine, evaluator,
-                    eventdispatcher, errorReporter);
+            semantics.executeActions(step, stateMachine, eventdispatcher,
+                    errorReporter, registry);
             // AssignCurrentStatus
             updateStatus(step);
             // ***Cleanup external events if superStep
@@ -129,7 +130,8 @@
      */
     public SCXMLExecutor(final Evaluator expEvaluator,
             final EventDispatcher evtDisp, final ErrorReporter errRep) {
-        this(expEvaluator, evtDisp, errRep, null);    }
+        this(expEvaluator, evtDisp, errRep, null);
+    }
 
     /**
      * Convenience constructor.
@@ -149,7 +151,6 @@
     public SCXMLExecutor(final Evaluator expEvaluator,
             final EventDispatcher evtDisp, final ErrorReporter errRep,
             final SCXMLSemantics semantics) {
-        this.evaluator = expEvaluator;
         this.eventdispatcher = evtDisp;
         this.errorReporter = errRep;
         this.currentStatus = null;
@@ -162,6 +163,8 @@
         }
         this.currentStatus = null;
         this.stateMachine = null;
+        this.registry = new Registry();
+        this.registry.setEvaluator(expEvaluator);
     }
 
     /**
@@ -173,15 +176,18 @@
      */
     public void reset() throws ModelException {
         // Reset all variable contexts
-        stateMachine.getRootContext().reset();
-        // all states and parallels, only states have var. contexts
+        registry.getRootContext().reset();
+        // all states and parallels, only states have variable contexts
         for (Iterator i = stateMachine.getTargets().values().iterator();
                 i.hasNext();) {
             TransitionTarget tt = (TransitionTarget) i.next();
             if (tt instanceof State) {
-                ((State) tt).getContext().reset();
+                Context context = registry.lookupContext(tt);
+                if (context != null) {
+                    context.reset();
+                }
             } else if (tt instanceof History) {
-                ((History) tt).reset();
+                registry.reset((History) tt);
             }
         }
         // CreateEmptyStatus
@@ -190,10 +196,10 @@
         // DetermineInitialStates
         semantics.determineInitialStates(stateMachine,
                 step.getAfterStatus().getStates(),
-                step.getEntryList(), errorReporter);
+                step.getEntryList(), errorReporter, registry);
         // ExecuteActions
-        semantics.executeActions(step, stateMachine, evaluator,
-                eventdispatcher, errorReporter);
+        semantics.executeActions(step, stateMachine, eventdispatcher,
+                errorReporter, registry);
         // AssignCurrentStatus
         updateStatus(step);
         // Execute Immediate Transitions
@@ -214,19 +220,17 @@
     }
 
     /**
-     * Get the expression evaluator.
-     *
-     * @return Returns the evaluator.
+     * @param evaluator The evaluator to set.
      */
-    public Evaluator getEvaluator() {
-        return evaluator;
+    public void setEvaluator(final Evaluator evaluator) {
+        this.registry.setEvaluator(evaluator);
     }
 
     /**
-     * @param evaluator The evaluator to set.
+     * @param rootContext The Context that ties to the host environment.
      */
-    public void setEvaluator(final Evaluator evaluator) {
-        this.evaluator = evaluator;
+    public void setRootContext(final Context rootContext) {
+        this.registry.setRootContext(rootContext);
     }
 
     /**
@@ -242,17 +246,23 @@
      * Set the state machine to be executed.
      *
      * @param stateMachine The stateMachine to set.
-     * @throws ModelException in case there is a fatal SCXML object
-     *  model problem.
      */
-    public void setStateMachine(final SCXML stateMachine)
-            throws ModelException {
+    public void setStateMachine(final SCXML stateMachine) {
         // NormalizeStateMachine
         SCXML sm = semantics.normalizeStateMachine(stateMachine,
                 errorReporter);
         // StoreStateMachine
         this.stateMachine = sm;
-        // reset
+    }
+
+    /**
+     * Initiate state machine execution.
+     *
+     * @throws ModelException in case there is a fatal SCXML object
+     *  model problem.
+     */
+    public void go() throws ModelException {
+        // same as reset
         this.reset();
     }
 
@@ -319,6 +329,80 @@
     }
 
     /**
+     * Add a listener to the document root.
+     *
+     * @param scxml The document root to attach listener to.
+     * @param listener The SCXMLListener.
+     */
+    public void addListener(final SCXML scxml, final SCXMLListener listener) {
+        Object observable = scxml;
+        registry.getNotificationRegistry().addListener(observable, listener);
+    }
+
+    /**
+     * Remove this listener from the document root.
+     *
+     * @param scxml The document root.
+     * @param listener The SCXMLListener to be removed.
+     */
+    public void removeListener(final SCXML scxml,
+            final SCXMLListener listener) {
+        Object observable = scxml;
+        registry.getNotificationRegistry().removeListener(observable, listener);
+    }
+
+    /**
+     * Add a listener to this transition target.
+     *
+     * @param transitionTarget The <code>TransitionTarget</code> to
+     *                         attach listener to.
+     * @param listener The SCXMLListener.
+     */
+    public void addListener(final TransitionTarget transitionTarget,
+            final SCXMLListener listener) {
+        Object observable = transitionTarget;
+        registry.getNotificationRegistry().addListener(observable, listener);
+    }
+
+    /**
+     * Remove this listener for this transition target.
+     *
+     * @param transitionTarget The <code>TransitionTarget</code>.
+     * @param listener The SCXMLListener to be removed.
+     */
+    public void removeListener(final TransitionTarget transitionTarget,
+            final SCXMLListener listener) {
+        Object observable = transitionTarget;
+        registry.getNotificationRegistry().removeListener(observable,
+            listener);
+    }
+
+    /**
+     * Add a listener to this transition.
+     *
+     * @param transition The <code>Transition</code> to attach listener to.
+     * @param listener The SCXMLListener.
+     */
+    public void addListener(final Transition transition,
+            final SCXMLListener listener) {
+        Object observable = transition;
+        registry.getNotificationRegistry().addListener(observable, listener);
+    }
+
+    /**
+     * Remove this listener for this transition.
+     *
+     * @param transition The <code>Transition</code>.
+     * @param listener The SCXMLListener to be removed.
+     */
+    public void removeListener(final Transition transition,
+            final SCXMLListener listener) {
+        Object observable = transition;
+        registry.getNotificationRegistry().removeListener(observable,
+            listener);
+    }
+
+    /**
      * Log the current set of active states.
      */
     private void logState() {
@@ -341,8 +425,10 @@
      * @param step The most recent Step
      */
     private void updateStatus(final Step step) {
-        this.currentStatus = step.getAfterStatus();
-        stateMachine.getRootContext().setLocal("_ALL_STATES",
+        currentStatus = step.getAfterStatus();
+        registry.getRootContext().setLocal("_ALL_STATES",
             SCXMLHelper.getAncestorClosure(currentStatus.getStates(), null));
     }
+
 }
+

Modified: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java?rev=373328&r1=373327&r2=373328&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java
(original)
+++ jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java
Sun Jan 29 09:39:39 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -68,11 +68,15 @@
      *            a list of States and Parallels to enter
      * @param errRep
      *            ErrorReporter callback
+     * @param registry
+     *            The registry
+     *
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
     void determineInitialStates(final SCXML input, final Set states,
-            final List entryList, final ErrorReporter errRep)
+            final List entryList, final ErrorReporter errRep,
+            final Registry registry)
     throws ModelException;
 
     /**
@@ -83,18 +87,19 @@
      *            updated its AfterStatus/Events
      * @param stateMachine
      *            state machine - SCXML instance
-     * @param eval
-     *            the expression evaluator - Evaluator instance
      * @param evtDispatcher
      *            the event dispatcher - EventDispatcher instance
      * @param errRep
      *            error reporter
+     * @param registry
+     *            The registry
+     *
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
     void executeActions(final Step step, final SCXML stateMachine,
-            final Evaluator eval, final EventDispatcher evtDispatcher,
-            final ErrorReporter errRep)
+            final EventDispatcher evtDispatcher, final ErrorReporter errRep,
+            final Registry registry)
     throws ModelException;
 
     /**
@@ -116,13 +121,13 @@
      *
      * @param step
      *            with current status
-     * @param evaluator
-     *            guard condition evaluator
      * @param errRep
      *            ErrorReporter callback
+     * @param registry
+     *            The registry
      */
-    void filterTransitionsSet(final Step step, final Evaluator evaluator,
-            final ErrorReporter errRep);
+    void filterTransitionsSet(final Step step, final ErrorReporter errRep,
+            final Registry registry);
 
     /**
      * Follow the candidate transitions for this execution Step, and update the
@@ -130,11 +135,13 @@
      *
      * @param step The current Step
      * @param errorReporter The ErrorReporter for the current environment
+     * @param registry The registry
      *
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
-    void followTransitions(final Step step, final ErrorReporter errorReporter)
+    void followTransitions(final Step step, final ErrorReporter errorReporter,
+            final Registry registry)
     throws ModelException;
 
     /**
@@ -145,7 +152,11 @@
      *            The current Step
      * @param errRep
      *            ErrorReporter callback
+     * @param registry
+     *            The registry
      */
-    void updateHistoryStates(final Step step, final ErrorReporter errRep);
+    void updateHistoryStates(final Step step, final ErrorReporter errRep,
+            final Registry registry);
 
 }
+

Modified: jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=373328&r1=373327&r2=373328&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
(original)
+++ jakarta/commons/sandbox/scxml/branches/STATELESS_MODEL/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
Sun Jan 29 09:39:39 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
 import org.apache.commons.scxml.Evaluator;
 import org.apache.commons.scxml.EventDispatcher;
 import org.apache.commons.scxml.NotificationRegistry;
+import org.apache.commons.scxml.Registry;
 import org.apache.commons.scxml.SCXMLExpressionException;
 import org.apache.commons.scxml.SCXMLHelper;
 import org.apache.commons.scxml.SCXMLSemantics;
@@ -107,11 +108,14 @@
      *            a list of States and Parallels to enter [out]
      * @param errRep
      *            ErrorReporter callback [inout]
+     * @param registry
+     *            The registry [in]
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
     public void determineInitialStates(final SCXML input, final Set states,
-            final List entryList, final ErrorReporter errRep)
+            final List entryList, final ErrorReporter errRep,
+            final Registry registry)
             throws ModelException {
         State tmp = input.getInitialState();
         if (tmp == null) {
@@ -119,7 +123,7 @@
                     "SCXML initialstate is missing!", input);
         } else {
             states.add(tmp);
-            determineTargetStates(states, errRep);
+            determineTargetStates(states, errRep, registry);
             //set of ALL entered states (even if initialState is a jump-over)
             Set onEntry = SCXMLHelper.getAncestorClosure(states, null);
             // sort onEntry according state hierarchy
@@ -139,12 +143,12 @@
      *            a list of actions to execute [in]
      * @param derivedEvents
      *            collection of internal events generated by the actions [out]
-     * @param eval
-     *            the expression evaluator - Evaluator instance
      * @param evtDispatcher
      *            the event dispatcher - EventDispatcher instance
      * @param errRep
      *            ErrorReporter callback [inout]
+     * @param registry
+     *            The registry [inout]
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem
      * @throws SCXMLExpressionException
@@ -157,16 +161,18 @@
      * @see Evaluator
      */
     public void executeActionList(final List actions,
-            final Collection derivedEvents, final Evaluator eval,
-            final EventDispatcher evtDispatcher, final ErrorReporter errRep)
-            throws ModelException, SCXMLExpressionException {
+            final Collection derivedEvents,
+            final EventDispatcher evtDispatcher, final ErrorReporter errRep,
+            final Registry registry)
+    throws ModelException, SCXMLExpressionException {
+        Evaluator eval = registry.getEvaluator();
         // NOTE: "if" statement is a container - we may need to call this method
         // recursively and pass a sub-list of actions embedded in a particular
         // "if"
         for (Iterator i = actions.iterator(); i.hasNext();) {
             Action a = (Action) i.next();
             State parentState = a.getParentState();
-            Context ctx = parentState.getContext();
+            Context ctx = registry.getContext(parentState);
             // NOTE: "elseif" and "else" do not appear here, since they are
             // always handled as a part of "if" as a container
             if (a instanceof Assign) {
@@ -219,8 +225,8 @@
                     }
                 }
                 if (!todoList.isEmpty()) {
-                    executeActionList(todoList, derivedEvents, eval,
-                        evtDispatcher, errRep);
+                    executeActionList(todoList, derivedEvents, evtDispatcher,
+                        errRep, registry);
                 }
                 todoList.clear();
             } else if (a instanceof Log) {
@@ -285,27 +291,28 @@
      *            updated its AfterStatus/Events
      * @param stateMachine
      *            state machine - SCXML instance
-     * @param eval
-     *            the expression evaluator - Evaluator instance
      * @param evtDispatcher
      *            the event dispatcher - EventDispatcher instance
      * @param errRep
      *            error reporter
+     * @param registry
+     *            The registry
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
     public void executeActions(final Step step, final SCXML stateMachine,
-            final Evaluator eval, final EventDispatcher evtDispatcher,
-            final ErrorReporter errRep) throws ModelException {
-        NotificationRegistry nr = stateMachine.getNotificationRegistry();
+            final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final Registry registry)
+    throws ModelException {
+        NotificationRegistry nr = registry.getNotificationRegistry();
         Collection internalEvents = step.getAfterStatus().getEvents();
         // ExecutePhaseActions / OnExit
         for (Iterator i = step.getExitList().iterator(); i.hasNext();) {
             TransitionTarget tt = (TransitionTarget) i.next();
             OnExit oe = tt.getOnExit();
             try {
-                executeActionList(oe.getActions(), internalEvents, eval,
-                    evtDispatcher, errRep);
+                executeActionList(oe.getActions(), internalEvents,
+                    evtDispatcher, errRep, registry);
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         oe);
@@ -320,8 +327,8 @@
         for (Iterator i = step.getTransitList().iterator(); i.hasNext();) {
             Transition t = (Transition) i.next();
             try {
-                executeActionList(t.getActions(), internalEvents, eval,
-                    evtDispatcher, errRep);
+                executeActionList(t.getActions(), internalEvents,
+                    evtDispatcher, errRep, registry);
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR,
                     e.getMessage(), t);
@@ -335,8 +342,8 @@
             TransitionTarget tt = (TransitionTarget) i.next();
             OnEntry oe = tt.getOnEntry();
             try {
-                executeActionList(oe.getActions(), internalEvents, eval,
-                    evtDispatcher, errRep);
+                executeActionList(oe.getActions(), internalEvents,
+                    evtDispatcher, errRep, registry);
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         oe);
@@ -431,13 +438,13 @@
     /**
      * @param step
      *            [inout]
-     * @param evaluator
-     *            guard condition evaluator
      * @param errRep
      *            ErrorReporter callback [inout]
+     * @param registry
+     *            The registry [in]
      */
     public void filterTransitionsSet(final Step step,
-            final Evaluator evaluator, final ErrorReporter errRep) {
+            final ErrorReporter errRep, final Registry registry) {
         /*
          * - filter transition set by applying events
          * (step/beforeStatus/events + step/externalEvents) (local check)
@@ -479,8 +486,8 @@
                 rslt = Boolean.TRUE;
             } else {
                 try {
-                    rslt = evaluator.evalCond(((State) t.getParent())
-                            .getContext(), t.getCond());
+                    rslt = registry.getEvaluator().evalCond(registry.
+                            getContext(t.getParent()), t.getCond());
                 } catch (SCXMLExpressionException e) {
                     rslt = Boolean.FALSE;
                     errRep.onError(ErrorReporter.EXPRESSION_ERROR, e
@@ -597,11 +604,14 @@
      *            a set seeded in previous step [inout]
      * @param errRep
      *            ErrorReporter callback [inout]
+     * @param registry
+     *            The registry [in]
      * @throws ModelException On illegal configuration
      * @see #seedTargetSet(Set, List, ErrorReporter)
      */
     public void determineTargetStates(final Set states,
-            final ErrorReporter errRep) throws ModelException {
+            final ErrorReporter errRep, final Registry registry)
+    throws ModelException {
         LinkedList wrkSet = new LinkedList(states);
         // clear the seed-set - will be populated by leaf states
         states.clear();
@@ -653,10 +663,10 @@
                 }
             } else if (tt instanceof History) {
                 History h = (History) tt;
-                if (h.isEmpty()) {
+                if (registry.isEmpty(h)) {
                     wrkSet.addLast(h.getTransition().getRuntimeTarget());
                 } else {
-                    wrkSet.addAll(h.getLastConfiguration());
+                    wrkSet.addAll(registry.getLastConfiguration(h));
                 }
             } else {
                 throw new ModelException("Unknown TransitionTarget subclass:"
@@ -673,9 +683,11 @@
      *            [inout]
      * @param errRep
      *            ErrorReporter callback [inout]
+     * @param registry
+     *            The registry [inout]
      */
     public void updateHistoryStates(final Step step,
-            final ErrorReporter errRep) {
+            final ErrorReporter errRep, final Registry registry) {
         Set oldState = step.getBeforeStatus().getStates();
         for (Iterator i = step.getExitList().iterator(); i.hasNext();) {
             Object o = i.next();
@@ -699,7 +711,7 @@
                                     }
                                 }
                             }
-                            h.setLastConfiguration(deep);
+                            registry.setLastConfiguration(h, deep);
                         } else {
                             if (shallow == null) {
                                 //calculate shallow history for a given state
@@ -709,7 +721,7 @@
                                 shallow.retainAll(SCXMLHelper
                                         .getAncestorClosure(oldState, null));
                             }
-                            h.setLastConfiguration(shallow);
+                            registry.setLastConfiguration(h, shallow);
                         }
                     }
                     shallow = null;
@@ -755,12 +767,14 @@
      *
      * @param step The current Step
      * @param errorReporter The ErrorReporter for the current environment
+     * @param registry The registry
      *
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
     public void followTransitions(final Step step,
-            final ErrorReporter errorReporter) throws ModelException {
+            final ErrorReporter errorReporter, final Registry registry)
+    throws ModelException {
         Set currentStates = step.getBeforeStatus().getStates();
         List transitions = step.getTransitList();
         // DetermineExitedStates (currentStates, transitList) -> exitedStates
@@ -778,7 +792,7 @@
         // DetermineTargetStates (initialTargetSet) -> targetSet
         Set targetSet = step.getAfterStatus().getStates();
         targetSet.addAll(seedSet); //copy to preserve seedSet
-        determineTargetStates(targetSet, errorReporter);
+        determineTargetStates(targetSet, errorReporter, registry);
         // BuildOnEntryList (targetSet, seedSet) -> entryList
         Set entered = SCXMLHelper.getAncestorClosure(targetSet, seedSet);
         seedSet.clear();



---------------------------------------------------------------------
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