commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r381008 - in /jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml: model/ semantics/
Date Sat, 25 Feb 2006 22:44:16 GMT
Author: rahul
Date: Sat Feb 25 14:44:13 2006
New Revision: 381008

URL: http://svn.apache.org/viewcvs?rev=381008&view=rev
Log:
Refactor processing of actions. Beyond the obvious benefit of a cleaner default SCXMLSemantics
implementation, this will make it easier for users to add custom actions (from other namespaces).

Modified:
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Assign.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Cancel.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/ElseIf.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Exit.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/If.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Log.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Var.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,14 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
 /**
  * An abstract base class for executable elements in SCXML,
  * such as <assign>, <log> etc.
@@ -74,5 +82,28 @@
                     + tt.getClass().getName());
         }
     }
+
+    /**
+     * Execute this action instance.
+     *
+     * @param evtDispatcher The EventDispatcher for this execution instance
+     * @param errRep        The ErrorReporter to broadcast any errors
+     *                      during execution.
+     * @param scInstance    The state machine execution instance information.
+     * @param appLog        The application Log.
+     * @param derivedEvents The collection to which any internal events
+     *                      arising from the execution of this action
+     *                      must be added.
+     *
+     * @throws ModelException If the execution causes the model to enter
+     *                        a non-deterministic state.
+     * @throws SCXMLExpressionException If the execution involves trying
+     *                        to evaluate an expression which is malformed.
+     */
+    public abstract void execute(final EventDispatcher evtDispatcher,
+        final ErrorReporter errRep, final SCInstance scInstance,
+        final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException;
+
 }
 

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Assign.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Assign.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Assign.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Assign.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,17 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+import org.apache.commons.scxml.TriggerEvent;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * <assign> SCXML element.
@@ -76,6 +87,28 @@
      */
     public void setName(final String name) {
         this.name = name;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        State parentState = getParentState();
+        Context ctx = scInstance.getContext(parentState);
+        Evaluator eval = scInstance.getEvaluator();
+        if (!ctx.has(name)) {
+            errRep.onError(ErrorReporter.UNDEFINED_VARIABLE, name
+                    + " = null", parentState);
+        } else {
+            Object varObj = eval.eval(ctx, expr);
+            ctx.set(name, varObj);
+            TriggerEvent ev = new TriggerEvent(name + ".change",
+                    TriggerEvent.CHANGE_EVENT);
+            derivedEvents.add(ev);
+        }
     }
 
 }

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Cancel.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Cancel.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Cancel.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Cancel.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,14 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * <cancel> SCXML element.
@@ -52,6 +60,16 @@
      */
     public void setSendid(final String sendid) {
         this.sendid = sendid;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        evtDispatcher.cancel(sendid);
     }
 
 }

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/ElseIf.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/ElseIf.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/ElseIf.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/ElseIf.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,14 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * <elseif> SCXML element.
@@ -52,6 +60,17 @@
      */
     public final void setCond(final String cond) {
         this.cond = cond;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        // nothing to do, the <if> container will take care of this
+        return;
     }
 
 }

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Exit.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Exit.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Exit.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Exit.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,14 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * &lt;exit&gt; SCXML element, which is a shorthand notation for
@@ -76,6 +84,17 @@
      */
     public final void setNamelist(final String namelist) {
         this.namelist = namelist;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        // we're done
+        return;
     }
 
 }

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/If.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/If.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/If.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/If.java
Sat Feb 25 14:44:13 2006
@@ -18,8 +18,18 @@
 package org.apache.commons.scxml.model;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * &lt;if&gt; SCXML element, which serves as a container for conditionally
@@ -42,11 +52,18 @@
     private List actions;
 
     /**
+     * The boolean value that dictates whether the particular child action
+     * should be executed.
+     */
+    private boolean execute;
+
+    /**
      * Constructor.
      */
     public If() {
         super();
         this.actions = new ArrayList();
+        this.execute = false;
     }
 
     /**
@@ -86,6 +103,36 @@
      */
     public final void setCond(final String cond) {
         this.cond = cond;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        State parentState = getParentState();
+        Context ctx = scInstance.getContext(parentState);
+        Evaluator eval = scInstance.getEvaluator();
+        execute = eval.evalCond(ctx, cond).booleanValue();
+        // The "if" statement is a "container"
+        for (Iterator ifiter = actions.iterator(); ifiter.hasNext();) {
+            Action aa = (Action) ifiter.next();
+            if (execute && !(aa instanceof ElseIf)
+                    && !(aa instanceof Else)) {
+                aa.execute(evtDispatcher, errRep, scInstance, appLog,
+                    derivedEvents);
+            } else if (execute
+                    && (aa instanceof ElseIf || aa instanceof Else)) {
+                break;
+            } else if (aa instanceof Else) {
+                execute = true;
+            } else if (aa instanceof ElseIf) {
+                execute = eval.evalCond(ctx, ((ElseIf) aa).getCond())
+                        .booleanValue();
+            }
+        }
     }
 
 }

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Log.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Log.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Log.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Log.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,15 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * &lt;log&gt; SCXML element.
@@ -78,5 +87,17 @@
         this.label = label;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final org.apache.commons.logging.Log appLog,
+            final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        Context ctx = scInstance.getContext(getParentState());
+        Evaluator eval = scInstance.getEvaluator();
+        appLog.info(label + ": " + String.valueOf(eval.eval(ctx, expr)));
+    }
 }
 

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
Sat Feb 25 14:44:13 2006
@@ -20,7 +20,20 @@
 //import java.io.IOException;
 //import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+import org.apache.commons.scxml.SCXMLHelper;
 
 //import org.apache.xml.serialize.OutputFormat;
 //import org.apache.xml.serialize.XMLSerializer;
@@ -254,6 +267,48 @@
         return buf.toString();
     }
     */
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        State parentState = getParentState();
+        Context ctx = scInstance.getContext(parentState);
+        Evaluator eval = scInstance.getEvaluator();
+        Object hintsValue = null;
+        if (!SCXMLHelper.isStringEmpty(hints)) {
+            hintsValue = eval.eval(ctx, hints);
+        }
+        Map params = null;
+        if (!SCXMLHelper.isStringEmpty(namelist)) {
+            StringTokenizer tkn = new StringTokenizer(namelist);
+            params = new HashMap(tkn.countTokens());
+            while (tkn.hasMoreTokens()) {
+                String varName = tkn.nextToken();
+                Object varObj = ctx.get(varName);
+                if (varObj == null) {
+                    //considered as a warning here
+                    errRep.onError(ErrorReporter.UNDEFINED_VARIABLE,
+                            varName + " = null", parentState);
+                }
+                params.put(varName, varObj);
+            }
+        }
+        long wait = 0L;
+        if (delay != null && delay.length() > 0) {
+            try {
+                wait = Long.parseLong(delay.trim());
+            } catch (NumberFormatException nfe) {
+                appLog.warn("Could not parse delay for <send>, "
+                    + "it will be treated as immediate", nfe);
+            }
+        }
+        evtDispatcher.send(sendid, target, targettype, event, params,
+            hintsValue, wait, externalNodes);
+    }
 
 }
 

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Var.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Var.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Var.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Var.java
Sat Feb 25 14:44:13 2006
@@ -17,6 +17,17 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+import org.apache.commons.scxml.TriggerEvent;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * &lt;var&gt; SCXML element.
@@ -77,6 +88,22 @@
      */
     public final void setName(final String name) {
         this.name = name;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute(final EventDispatcher evtDispatcher,
+            final ErrorReporter errRep, final SCInstance scInstance,
+            final Log appLog, final Collection derivedEvents)
+    throws ModelException, SCXMLExpressionException {
+        Context ctx = scInstance.getContext(getParentState());
+        Evaluator eval = scInstance.getEvaluator();
+        Object varObj = eval.eval(ctx, expr);
+        ctx.setLocal(name, varObj);
+        TriggerEvent ev = new TriggerEvent(name + ".change",
+                TriggerEvent.CHANGE_EVENT);
+        derivedEvents.add(ev);
     }
 
 }

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=381008&r1=381007&r2=381008&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
Sat Feb 25 14:44:13 2006
@@ -21,19 +21,14 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
-import java.util.StringTokenizer;
 
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.scxml.Context;
 import org.apache.commons.scxml.ErrorReporter;
-import org.apache.commons.scxml.Evaluator;
 import org.apache.commons.scxml.EventDispatcher;
 import org.apache.commons.scxml.NotificationRegistry;
 import org.apache.commons.scxml.SCInstance;
@@ -43,26 +38,17 @@
 import org.apache.commons.scxml.Step;
 import org.apache.commons.scxml.TriggerEvent;
 import org.apache.commons.scxml.model.Action;
-import org.apache.commons.scxml.model.Assign;
-import org.apache.commons.scxml.model.Cancel;
-import org.apache.commons.scxml.model.Else;
-import org.apache.commons.scxml.model.ElseIf;
-import org.apache.commons.scxml.model.Exit;
 import org.apache.commons.scxml.model.History;
-import org.apache.commons.scxml.model.If;
 import org.apache.commons.scxml.model.Initial;
-import org.apache.commons.scxml.model.Log;
 import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.OnEntry;
 import org.apache.commons.scxml.model.OnExit;
 import org.apache.commons.scxml.model.Parallel;
 import org.apache.commons.scxml.model.Path;
 import org.apache.commons.scxml.model.SCXML;
-import org.apache.commons.scxml.model.Send;
 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.model.Var;
 
 /**
  * <p>This class encapsulates a particular SCXML semantics, that is, a
@@ -139,151 +125,6 @@
     }
 
     /**
-     * @param actions
-     *            a list of actions to execute [in]
-     * @param derivedEvents
-     *            collection of internal events generated by the actions [out]
-     * @param evtDispatcher
-     *            the event dispatcher - EventDispatcher instance
-     * @param errRep
-     *            ErrorReporter callback [inout]
-     * @param scInstance
-     *            The state chart instance [inout]
-     * @throws ModelException
-     *             in case there is a fatal SCXML object model problem
-     * @throws SCXMLExpressionException
-     *             in case there is an problem evaluating an expression
-     *             within the SCXML document
-     * @see ErrorReporter
-     * @see NotificationRegistry
-     * @see EventDispatcher
-     * @see Context
-     * @see Evaluator
-     */
-    public void executeActionList(final List actions,
-            final Collection derivedEvents,
-            final EventDispatcher evtDispatcher, final ErrorReporter errRep,
-            final SCInstance scInstance)
-    throws ModelException, SCXMLExpressionException {
-        Evaluator eval = scInstance.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 = scInstance.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) {
-                Assign asgn = (Assign) a;
-                String varName = asgn.getName();
-                if (!ctx.has(varName)) {
-                    errRep.onError(ErrorReporter.UNDEFINED_VARIABLE, varName
-                            + " = null", parentState);
-                } else {
-                    Object varObj = eval.eval(ctx, asgn.getExpr());
-                    ctx.set(varName, varObj);
-                    TriggerEvent ev = new TriggerEvent(varName + ".change",
-                            TriggerEvent.CHANGE_EVENT);
-                    derivedEvents.add(ev);
-                }
-            } else if (a instanceof Cancel) {
-                Cancel cncl = (Cancel) a;
-                evtDispatcher.cancel(cncl.getSendid());
-            } else if (a instanceof Exit) {
-                // Ignore; Exit instance holds other information that might
-                // be needed, and is not transformed at parse time.
-                //throw new ModelException("The <exit/> tag must be "
-                //    + "transformed to an anonymous final state at "
-                //    + "the parse time!");
-                continue; //for checkstyle
-            } else if (a instanceof If) {
-                //determine elseif/else separators evaluate conditions
-                //extract a sub-list of If's actions and invoke
-                // executeActionList()
-                List todoList = new LinkedList();
-                If ifo = (If) a;
-                List subAct = ifo.getActions();
-                boolean cnd = eval.evalCond(ctx, ifo.getCond()).booleanValue();
-                for (Iterator ifiter = subAct.iterator(); ifiter.hasNext();) {
-                    Action aa = (Action) ifiter.next();
-                    if (cnd && !(aa instanceof ElseIf)
-                            && !(aa instanceof Else)) {
-                        todoList.add(aa);
-                    } else if (cnd
-                            && (aa instanceof ElseIf || aa instanceof Else)) {
-                        break;
-                    } else if (aa instanceof ElseIf) {
-                        cnd = eval.evalCond(ctx, ((ElseIf) aa).getCond())
-                                .booleanValue();
-                    } else if (aa instanceof Else) {
-                        cnd = true;
-                    } else {
-                        //skip
-                        continue; //for checkstyle
-                    }
-                }
-                if (!todoList.isEmpty()) {
-                    executeActionList(todoList, derivedEvents, evtDispatcher,
-                        errRep, scInstance);
-                }
-                todoList.clear();
-            } else if (a instanceof Log) {
-                Log lg = (Log) a;
-                Object exprRslt = eval.eval(ctx, lg.getExpr());
-                APP_LOG.info(lg.getLabel() + ": " + String.valueOf(exprRslt));
-            } else if (a instanceof Send) {
-                Send snd = (Send) a;
-                Object hints = null;
-                if (!SCXMLHelper.isStringEmpty(snd.getHints())) {
-                    hints = eval.eval(ctx, snd.getHints());
-                }
-                Map params = null;
-                if (!SCXMLHelper.isStringEmpty(snd.getNamelist())) {
-                    StringTokenizer tkn = new StringTokenizer(snd.
-                        getNamelist());
-                    params = new HashMap(tkn.countTokens());
-                    while (tkn.hasMoreTokens()) {
-                        String varName = tkn.nextToken();
-                        Object varObj = ctx.get(varName);
-                        if (varObj == null) {
-                            //considered as a warning here
-                            errRep.onError(ErrorReporter.UNDEFINED_VARIABLE,
-                                    varName + " = null", parentState);
-                        }
-                        params.put(varName, varObj);
-                    }
-                }
-                String delay = snd.getDelay();
-                long wait = 0L;
-                if (delay != null && delay.length() > 0) {
-                    try {
-                        wait = Long.parseLong(delay.trim());
-                    } catch (NumberFormatException nfe) {
-                        APP_LOG.warn("Could not parse delay for <send>, "
-                            + "it will be treated as immediate", nfe);
-                    }
-                }
-                evtDispatcher.send(snd.getSendid(),
-                        snd.getTarget(), snd.getTargettype(), snd.getEvent(),
-                        params, hints, wait, snd.getExternalNodes());
-            } else if (a instanceof Var) {
-                Var vr = (Var) a;
-                String varName = vr.getName();
-                Object varObj = eval.eval(ctx, vr.getExpr());
-                ctx.setLocal(varName, varObj);
-                TriggerEvent ev = new TriggerEvent(varName + ".change",
-                        TriggerEvent.CHANGE_EVENT);
-                derivedEvents.add(ev);
-            } else {
-                errRep.onError(ErrorReporter.UNKNOWN_ACTION,
-                        "unsupported executable statement", a);
-            }
-        }
-    }
-
-    /**
      * Executes all OnExit/Transition/OnEntry transitional actions.
      *
      * @param step
@@ -311,8 +152,11 @@
             TransitionTarget tt = (TransitionTarget) i.next();
             OnExit oe = tt.getOnExit();
             try {
-                executeActionList(oe.getActions(), internalEvents,
-                    evtDispatcher, errRep, scInstance);
+                for (Iterator onExitIter = oe.getActions().iterator();
+                        onExitIter.hasNext();) {
+                    ((Action) onExitIter.next()).execute(evtDispatcher,
+                        errRep, scInstance, APP_LOG, internalEvents);
+                }
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         oe);
@@ -327,8 +171,11 @@
         for (Iterator i = step.getTransitList().iterator(); i.hasNext();) {
             Transition t = (Transition) i.next();
             try {
-                executeActionList(t.getActions(), internalEvents,
-                    evtDispatcher, errRep, scInstance);
+                for (Iterator transitIter = t.getActions().iterator();
+                        transitIter.hasNext();) {
+                    ((Action) transitIter.next()).execute(evtDispatcher,
+                        errRep, scInstance, APP_LOG, internalEvents);
+                }
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR,
                     e.getMessage(), t);
@@ -342,8 +189,11 @@
             TransitionTarget tt = (TransitionTarget) i.next();
             OnEntry oe = tt.getOnEntry();
             try {
-                executeActionList(oe.getActions(), internalEvents,
-                    evtDispatcher, errRep, scInstance);
+                for (Iterator onEntryIter = oe.getActions().iterator();
+                        onEntryIter.hasNext();) {
+                    ((Action) onEntryIter.next()).execute(evtDispatcher,
+                        errRep, scInstance, APP_LOG, internalEvents);
+                }
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         oe);



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