You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ra...@apache.org on 2006/01/08 23:39:23 UTC

svn commit: r367112 - in /jakarta/commons/sandbox/scxml/trunk: ./ src/main/java/org/apache/commons/scxml/env/ src/main/java/org/apache/commons/scxml/env/jexl/ src/main/java/org/apache/commons/scxml/env/jsp/ src/test/java/org/apache/commons/scxml/env/je...

Author: rahul
Date: Sun Jan  8 14:39:15 2006
New Revision: 367112

URL: http://svn.apache.org/viewcvs?rev=367112&view=rev
Log:
Added JEXL support for SCXML documents.

The SCXML specification allows implementations to support multiple expression languages so SCXML documents can be used in varying environments. Commons SCXML already supports the use of EL, using Commons EL. That is useful in servlet container environments and web frameworks, indeed the first use cases for Commons SCXML have been such that the JSP/EL APIs have come in via the "provided" maven scope. However since Commons EL 1.0 implements the EL portions of the JSP 2.0 specification, the inherent tie-in between the EL and JSP APIs leaves Commons EL an undesirable choice outside the realm of web applications. JEXL expressions provide an alternative for using Commons SCXML in desktop applications, some compound document formats and server managed code. The implementation consists of implementations of the Commons SCXML Context and Evaluator interfaces which serve as adapters to the JEXL APIs.

Some minor refactorings have been made to reuse any common code into utility classes and some classes not available in the public Commons SCXML API now have better names, IMO.

Adding Commons JEXL 1.0 to the dependency list in the project POM and updating the ant build file as well.

Added:
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml   (with props)
Modified:
    jakarta/commons/sandbox/scxml/trunk/build.xml
    jakarta/commons/sandbox/scxml/trunk/project.xml
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleContext.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/Standalone.java
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-01.xml
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-02.xml

Modified: jakarta/commons/sandbox/scxml/trunk/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/build.xml?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/build.xml (original)
+++ jakarta/commons/sandbox/scxml/trunk/build.xml Sun Jan  8 14:39:15 2006
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-   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.
@@ -15,7 +15,7 @@
    limitations under the License.
 -->
 <!--build.xml generated by maven from project.xml version 1.0-SNAPSHOT
-  on date October 9 2005, time 0108-->
+  on date January 8 2006, time 1636-->
 
 <project default="jar" name="commons-scxml" basedir=".">
   <property name="defaulttargetdir" value="target">
@@ -124,6 +124,8 @@
           </include>
           <include name="org/apache/commons/scxml/env/EnvTestSuite.java">
           </include>
+          <include name="org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java">
+          </include>
           <include name="org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java">
           </include>
           <include name="org/apache/commons/scxml/env/faces/EnvFacesTestSuite.java">
@@ -193,6 +195,8 @@
     <get dest="${libdir}/commons-beanutils-1.7.0.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-beanutils/jars/commons-beanutils-1.7.0.jar">
     </get>
     <get dest="${libdir}/commons-el-1.0.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-el/jars/commons-el-1.0.jar">
+    </get>
+    <get dest="${libdir}/commons-jexl-1.0.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-jexl/jars/commons-jexl-1.0.jar">
     </get>
     <get dest="${libdir}/commons-logging-1.0.4.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.0.4.jar">
     </get>

Modified: jakarta/commons/sandbox/scxml/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/project.xml?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/project.xml (original)
+++ jakarta/commons/sandbox/scxml/trunk/project.xml Sun Jan  8 14:39:15 2006
@@ -136,6 +136,15 @@
         <scope>provided</scope>
       </properties>
     </dependency>
+    <dependency> 
+      <groupId>commons-jexl</groupId>
+      <artifactId>commons-jexl</artifactId>
+      <version>1.0</version> 
+      <properties>
+        <comment>&lt;b&gt;Usecases&lt;/b&gt;
+        (JEXL environments)</comment>
+      </properties>
+    </dependency>
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId> 
@@ -184,6 +193,7 @@
       <includes>
         <include>org/apache/commons/scxml/SCXMLTestSuite.java</include>
         <include>org/apache/commons/scxml/env/EnvTestSuite.java</include>
+        <include>org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java</include>
         <include>org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java</include>
         <include>org/apache/commons/scxml/env/faces/EnvFacesTestSuite.java</include>
         <include>org/apache/commons/scxml/model/ModelTestSuite.java</include>

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleContext.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleContext.java?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleContext.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleContext.java Sun Jan  8 14:39:15 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.
@@ -173,6 +173,15 @@
         if (LOG.isDebugEnabled() && !name.equals("_ALL_STATES")) {
             LOG.debug(name + " = " + String.valueOf(value));
         }
+    }
+
+    /**
+     * Set the variables map.
+     *
+     * @param vars The new Map of variables.
+     */
+    protected void setVars(final Map vars) {
+        this.vars = vars;
     }
 
     /**

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java Sun Jan  8 14:39:15 2006
@@ -0,0 +1,169 @@
+/*
+ *
+ *   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.env;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.StringTokenizer;
+
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCXMLDigester;
+import org.apache.commons.scxml.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLHelper;
+import org.apache.commons.scxml.SCXMLSerializer;
+import org.apache.commons.scxml.TriggerEvent;
+import org.apache.commons.scxml.model.ModelException;
+import org.apache.commons.scxml.model.SCXML;
+import org.xml.sax.SAXException;
+
+/**
+ * Utility methods used by command line SCXML execution, useful for
+ * debugging.
+ *
+ * The following expression languages are supported in SCXML documents:
+ * <ol>
+ *  <li>JEXL - Using Commons JEXL</li>
+ *  <li>EL - Using Commons EL</li>
+ * </ol>
+ *
+ * @see org.apache.commons.scxml.env.jexl
+ * @see org.apache.commons.scxml.env.jsp
+ */
+public final class StandaloneUtils {
+
+    /**
+     * Command line utility method for executing the state machine defined
+     * using the SCXML document described by the specified URI and using
+     * the specified expression evaluator.
+     *
+     * @param uri The URI or filename of the SCXML document
+     * @param evaluator The expression evaluator for the expression language
+     *                  used in the specified SCXML document
+     *
+     * <p>RUNNING:</p>
+     * <ul>
+     *  <li>Enter a space-separated list of "events"</li>
+     *  <li>To quit, enter "quit"</li>
+     *  <li>To populate a variable in the current context,
+     *      type "name=value"</li>
+     *  <li>To reset state machine, enter "reset"</li>
+     * </ul>
+     */
+    public static void execute(final String uri, final Evaluator evaluator) {
+        try {
+            String documentURI = getCanonicalURI(uri);
+            Context rootCtx = evaluator.newContext(null);
+            EventDispatcher ed = new SimpleDispatcher();
+            Tracer trc = new Tracer();
+            SCXML doc = SCXMLDigester.digest(new URL(documentURI), trc,
+                rootCtx, evaluator);
+            if (doc == null) {
+                System.err.println("The SCXML document " + uri
+                        + " can not be parsed!");
+                System.exit(-1);
+            }
+            System.out.println(SCXMLSerializer.serialize(doc));
+            SCXMLExecutor exec = new SCXMLExecutor(evaluator, ed, trc);
+            doc.addListener(trc);
+            exec.setSuperStep(true);
+            exec.setStateMachine(doc);
+            BufferedReader br = new BufferedReader(new
+                InputStreamReader(System.in));
+            String event = null;
+            while ((event = br.readLine()) != null) {
+                event = event.trim();
+                if (event.equalsIgnoreCase("help") || event.equals("?")) {
+                    System.out.println("Enter a space-separated list of "
+                        + "events");
+                    System.out.println("To populate a variable in the "
+                        + "current context, type \"name=value\"");
+                    System.out.println("To quit, enter \"quit\"");
+                    System.out.println("To reset state machine, enter "
+                        + "\"reset\"");
+                } else if (event.equalsIgnoreCase("quit")) {
+                    break;
+                } else if (event.equalsIgnoreCase("reset")) {
+                    exec.reset();
+                } else if (event.indexOf('=') != -1) {
+                    int marker = event.indexOf('=');
+                    String name = event.substring(0, marker);
+                    String value = event.substring(marker + 1);
+                    rootCtx.setLocal(name, value);
+                    System.out.println("Set variable " + name + " to "
+                        + value);
+                } else if (SCXMLHelper.isStringEmpty(event)
+                           || event.equalsIgnoreCase("null")) {
+                    TriggerEvent[] evts = {new TriggerEvent(null,
+                        TriggerEvent.SIGNAL_EVENT, null)};
+                    exec.triggerEvents(evts);
+                    if (exec.getCurrentStatus().isFinal()) {
+                        System.out.println("A final configuration reached.");
+                    }
+                } else {
+                    StringTokenizer st = new StringTokenizer(event);
+                    int tkns = st.countTokens();
+                    TriggerEvent[] evts = new TriggerEvent[tkns];
+                    for (int i = 0; i < tkns; i++) {
+                        evts[i] = new TriggerEvent(st.nextToken(),
+                                TriggerEvent.SIGNAL_EVENT, null);
+                    }
+                    exec.triggerEvents(evts);
+                    if (exec.getCurrentStatus().isFinal()) {
+                        System.out.println("A final configuration reached.");
+                    }
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (ModelException e) {
+            e.printStackTrace();
+        } catch (SAXException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * @param uri an absolute or relative URL
+     * @return java.lang.String canonical URL (absolute)
+     * @throws java.io.IOException if a relative URL can not be resolved
+     *         to a local file
+     */
+    private static String getCanonicalURI(final String uri)
+    throws IOException {
+        if (uri.toLowerCase().startsWith("http://")
+            || uri.toLowerCase().startsWith("file://")) {
+                return uri;
+        }
+        File in = new File(uri);
+        return "file:///" + in.getCanonicalPath();
+    }
+
+    /**
+     * Discourage instantiation since this is a utility class.
+     */
+    private StandaloneUtils() {
+        super();
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/StandaloneUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java Sun Jan  8 14:39:15 2006
@@ -0,0 +1,86 @@
+/*
+ *
+ *   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.env.jexl;
+
+import java.util.Map;
+
+import org.apache.commons.scxml.Builtin;
+import org.apache.commons.scxml.env.SimpleContext;
+
+/**
+ * JEXL Context implementation for Commons SCXML.
+ *
+ */
+public class JexlContext extends SimpleContext
+    implements org.apache.commons.jexl.JexlContext {
+
+    /**
+     * Constructor.
+     */
+    public JexlContext() {
+        super();
+        getVars().put("_builtin", new Builtin());
+    }
+
+    /**
+     * Constructor with initial vars.
+     *
+     * @param initialVars The initial set of variables.
+     */
+    public JexlContext(final Map initialVars) {
+        super(initialVars);
+        getVars().put("_builtin", new Builtin());
+    }
+
+    /**
+     * Get the variables map.
+     *
+     * @param vars The new variables map.
+     *
+     * @see org.apache.commons.jexl.JexlContext#setVars(Map)
+     * @see org.apache.commons.scxml.env.SimpleContext#setVars(Map)
+     */
+    public void setVars(final Map vars) {
+        super.setVars(vars);
+        getVars().put("_builtin", new Builtin());
+    }
+
+    /**
+     * Get the variables map.
+     *
+     * @return Returns the vars.
+     *
+     * @see org.apache.commons.jexl.JexlContext#getVars()
+     * @see org.apache.commons.scxml.env.SimpleContext#getVars()
+     */
+    public Map getVars() {
+        return super.getVars();
+    }
+
+    /**
+     * Clear this Context.
+     *
+     * @see org.apache.commons.scxml.Context#reset()
+     */
+    public void reset() {
+        super.reset();
+        getVars().put("_builtin", new Builtin());
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java Sun Jan  8 14:39:15 2006
@@ -0,0 +1,116 @@
+/*
+ *
+ *   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.env.jexl;
+
+import java.util.regex.Pattern;
+
+import org.apache.commons.jexl.Expression;
+import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.SCXMLExpressionException;
+
+/**
+ * Evaluator implementation enabling use of JEXL expressions in
+ * SCXML documents.
+ *
+ */
+public class JexlEvaluator implements Evaluator {
+
+    /** Error message if evaluation context is not a JexlContext. */
+    private static final String ERR_CTX_TYPE = "Error evaluating JEXL "
+        + "expression, Context must be a org.apache.commons.jexl.JexlContext";
+
+    /** Pattern for recognizing the SCXML In() special predicate. */
+    private static Pattern inFct = Pattern.compile("In\\(");
+
+    /** Constructor. */
+    public JexlEvaluator() {
+        super();
+    }
+
+    /**
+     * Evaluate an expression.
+     *
+     * @param ctx variable context
+     * @param expr expression
+     * @return a result of the evaluation
+     * @throws SCXMLExpressionException For a malformed expression
+     * @see Evaluator#eval(Context, String)
+     */
+    public Object eval(final Context ctx, final String expr)
+    throws SCXMLExpressionException {
+        JexlContext jexlCtx = null;
+        if (ctx instanceof JexlContext) {
+            jexlCtx = (JexlContext) ctx;
+        } else {
+            throw new SCXMLExpressionException(ERR_CTX_TYPE);
+        }
+        Expression exp = null;
+        try {
+            String evalExpr = inFct.matcher(expr).
+                replaceAll("_builtin.isMember(_ALL_STATES, ");
+            exp = ExpressionFactory.createExpression(evalExpr);
+            return exp.evaluate(jexlCtx);
+        } catch (Exception e) {
+            throw new SCXMLExpressionException(e);
+        }
+    }
+
+    /**
+     * Create a new child context.
+     *
+     * @param parent parent context
+     * @return new child context
+     * @see Evaluator#newContext(Context)
+     */
+    public Context newContext(final Context parent) {
+        //for now, we do not support nested variable contexts
+        //world is flat ;)
+        if (parent != null) {
+            return parent;
+        } else {
+            return new org.apache.commons.scxml.env.jexl.JexlContext();
+        }
+    }
+
+    /**
+     * @see Evaluator#evalCond(Context, String)
+     */
+    public Boolean evalCond(final Context ctx, final String expr)
+    throws SCXMLExpressionException {
+        JexlContext jexlCtx = null;
+        if (ctx instanceof JexlContext) {
+            jexlCtx = (JexlContext) ctx;
+        } else {
+            throw new SCXMLExpressionException(ERR_CTX_TYPE);
+        }
+        Expression exp = null;
+        try {
+            String evalExpr = inFct.matcher(expr).
+                replaceAll("_builtin.isMember(_ALL_STATES, ");
+            exp = ExpressionFactory.createExpression(evalExpr);
+            return (Boolean) exp.evaluate(jexlCtx);
+        } catch (Exception e) {
+            throw new SCXMLExpressionException(e);
+        }
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java Sun Jan  8 14:39:15 2006
@@ -0,0 +1,68 @@
+/*
+ *
+ *   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.env.jexl;
+
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.env.StandaloneUtils;
+
+/**
+ * Standalone SCXML interpreter, useful for command-line testing and
+ * debugging, where expressions are JEXL expressions.
+ *
+ * <p>USAGE:</p>
+ * <p><code>java org.apache.commons.scxml.env.jexl.Standalone url</code></p>
+ * <p>or</p>
+ * <p><code>java org.apache.commons.scxml.env.jexl.Standalone filename</code>
+ * </p>
+ *
+ * <p>RUNNING:</p>
+ * <ul>
+ *  <li>Enter a space-separated list of "events"</li>
+ *  <li>To quit, enter "quit"</li>
+ *  <li>To populate a variable in the current context,
+ *      type "name=value"</li>
+ *  <li>To reset state machine, enter "reset"</li>
+ * </ul>
+ *
+ */
+public final class Standalone {
+
+    /**
+     * Launcher.
+     * @param args The arguments, one expected, the URI or filename of the
+     *             SCXML document
+     */
+    public static void main(final String[] args) {
+        if (args.length < 1) {
+            System.out.println("USAGE: java " + Standalone.class.getName()
+                    + "<url|filename>");
+            System.exit(-1);
+        }
+        Evaluator evaluator = new JexlEvaluator();
+        StandaloneUtils.execute(args[0], evaluator);
+    }
+
+    /**
+     * Discourage instantiation since this is a utility class.
+     */
+    private Standalone() {
+        super();
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/Standalone.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html Sun Jan  8 14:39:15 2006
@@ -0,0 +1,30 @@
+<html>
+<!-- 
+ *
+ *    
+ *   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.
+ *
+ *
+ *
+-->
+<head>
+</head>
+<body>
+
+  <p>A collection of classes that allow JEXL to be used in expressions
+     within SCXML documents.</p>
+
+</body>
+</html>

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java Sun Jan  8 14:39:15 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.
@@ -18,7 +18,6 @@
 package org.apache.commons.scxml.env.jsp;
 
 import java.lang.reflect.Method;
-import java.util.Iterator;
 import java.util.Set;
 import java.util.regex.Pattern;
 
@@ -30,13 +29,14 @@
 import org.apache.commons.el.ExpressionEvaluatorImpl;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.scxml.Builtin;
 import org.apache.commons.scxml.Context;
 import org.apache.commons.scxml.Evaluator;
 import org.apache.commons.scxml.SCXMLExpressionException;
-import org.apache.commons.scxml.model.TransitionTarget;
 
 /**
- * EL engine interface for SCXML Interpreter.
+ * Evaluator implementation enabling use of EL expressions in
+ * SCXML documents.
  *
  */
 public class ELEvaluator implements Evaluator {
@@ -44,7 +44,7 @@
     /** Implementation independent log category. */
     protected static final Log LOG = LogFactory.getLog(Evaluator.class);
     /** Function Mapper for SCXML expressions. */
-    private FunctionMapper functionMapper = new FunctWrapper();
+    private FunctionMapper functionMapper = new BuiltinFunctionWrapper();
     /** Pattern for recognizing the SCXML In() special predicate. */
     private static Pattern inFct = Pattern.compile("In\\(");
 
@@ -73,7 +73,7 @@
         if (ctx instanceof VariableResolver) {
             vr = (VariableResolver) ctx;
         } else {
-            vr = new CtxWrapper(ctx);
+            vr = new ContextWrapper(ctx);
         }
         try {
             String evalExpr = inFct.matcher(expr).
@@ -115,7 +115,7 @@
         if (ctx instanceof VariableResolver) {
             vr = (VariableResolver) ctx;
         } else {
-            vr = new CtxWrapper(ctx);
+            vr = new ContextWrapper(ctx);
         }
         try {
             String evalExpr = inFct.matcher(expr).
@@ -134,14 +134,14 @@
     /**
      * A Context wrapper that implements VariableResolver.
      */
-    static class CtxWrapper implements VariableResolver {
+    static class ContextWrapper implements VariableResolver {
         /** Context to be wrapped. */
         private Context ctx = null;
         /**
          * Constructor.
          * @param ctx The Context to be wrapped.
          */
-        CtxWrapper(final Context ctx) {
+        ContextWrapper(final Context ctx) {
             this.ctx = ctx;
         }
         /** @see VariableResolver#resolveVariable(String) */
@@ -157,7 +157,7 @@
     /**
      * A simple function mapper for SCXML defined functions.
      */
-    static class FunctWrapper implements FunctionMapper {
+    static class BuiltinFunctionWrapper implements FunctionMapper {
 
         /**
          * @see FunctionMapper#resolveFunction(String, String)
@@ -167,7 +167,7 @@
             if (localName.equals("In")) {
                 Class[] attrs = new Class[] {Set.class, String.class};
                 try {
-                    return ELEvaluator.class.getMethod("isMember", attrs);
+                    return Builtin.class.getMethod("isMember", attrs);
                 } catch (SecurityException e) {
                     LOG.error("resolving isMember(Set, String)", e);
                 } catch (NoSuchMethodException e) {
@@ -176,25 +176,6 @@
             }
             return null;
         }
-    }
-
-    /**
-     * Does this state belong to the Set of these States.
-     * Simple ID based comparator
-     *
-     * @param allStates The Set of State objects to look in
-     * @param state The State to compare with
-     * @return Whether this State belongs to this Set
-     */
-    public static final boolean isMember(final Set allStates,
-            final String state) {
-        for (Iterator i = allStates.iterator(); i.hasNext();) {
-            TransitionTarget tt = (TransitionTarget) i.next();
-            if (state.equals(tt.getId())) {
-                return true;
-            }
-        }
-        return false;
     }
 
     /**

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/Standalone.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/Standalone.java?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/Standalone.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/Standalone.java Sun Jan  8 14:39:15 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.
@@ -17,42 +17,27 @@
  */
 package org.apache.commons.scxml.env.jsp;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.StringTokenizer;
-
-import org.apache.commons.scxml.Context;
 import org.apache.commons.scxml.Evaluator;
-import org.apache.commons.scxml.EventDispatcher;
-import org.apache.commons.scxml.SCXMLDigester;
-import org.apache.commons.scxml.SCXMLExecutor;
-import org.apache.commons.scxml.SCXMLHelper;
-import org.apache.commons.scxml.SCXMLSerializer;
-import org.apache.commons.scxml.TriggerEvent;
-import org.apache.commons.scxml.env.SimpleDispatcher;
-import org.apache.commons.scxml.env.Tracer;
-import org.apache.commons.scxml.model.ModelException;
-import org.apache.commons.scxml.model.SCXML;
-import org.xml.sax.SAXException;
+import org.apache.commons.scxml.env.StandaloneUtils;
 
 /**
  * Standalone SCXML interpreter, useful for command-line testing and
- * debugging.
+ * debugging, where expressions are JSP 2.0 EL expressions.
  *
- * <p><b>USAGE:</b></p>
+ * <p>USAGE:</p>
  * <p><code>java org.apache.commons.scxml.env.jsp.Standalone url</code></p>
  * <p>or</p>
  * <p><code>java org.apache.commons.scxml.env.jsp.Standalone filename</code>
  * </p>
  *
- * <p><b>RUNNING:</b></p>
- * <p>Enter a space-separated list of "events"</p>
- * <p>To quit, enter "quit"</p>
- * <p>To populate a variable in the current context, type "name=value"</p>
- * <p>To reset state machine, enter "reset"</p>
+ * <p>RUNNING:</p>
+ * <ul>
+ *  <li>Enter a space-separated list of "events"</li>
+ *  <li>To quit, enter "quit"</li>
+ *  <li>To populate a variable in the current context,
+ *      type "name=value"</li>
+ *  <li>To reset state machine, enter "reset"</li>
+ * </ul>
  *
  */
 public final class Standalone {
@@ -63,99 +48,13 @@
      *             SCXML document
      */
     public static void main(final String[] args) {
-        if (args.length != 1) {
+        if (args.length < 1) {
             System.out.println("USAGE: java " + Standalone.class.getName()
                     + "<url|filename>");
             System.exit(-1);
         }
-        try {
-            String uri = getCanonicalURI(args[0]);
-            Evaluator engine = new ELEvaluator();
-            Context rootCtx = engine.newContext(null);
-            EventDispatcher ed = new SimpleDispatcher();
-            Tracer trc = new Tracer();
-            SCXML doc = SCXMLDigester.digest(new URL(uri), trc, rootCtx,
-                engine);
-            if (doc == null) {
-                System.err.println("The SCXML document " + uri
-                        + " can not be parsed!");
-                System.exit(-1);
-            }
-            System.out.println(SCXMLSerializer.serialize(doc));
-            SCXMLExecutor exec = new SCXMLExecutor(engine, ed, trc);
-            doc.addListener(trc);
-            exec.setSuperStep(true);
-            exec.setStateMachine(doc);
-            BufferedReader br = new BufferedReader(new
-                InputStreamReader(System.in));
-            String event = null;
-            while ((event = br.readLine()) != null) {
-                event = event.trim();
-                if (event.equalsIgnoreCase("help") || event.equals("?")) {
-                    System.out.println("Enter a space-separated list of "
-                        + "events");
-                    System.out.println("To populate a variable in the "
-                        + "current context, type \"name=value\"");
-                    System.out.println("To quit, enter \"quit\"");
-                    System.out.println("To reset state machine, enter "
-                        + "\"reset\"");
-                } else if (event.equalsIgnoreCase("quit")) {
-                    break;
-                } else if (event.equalsIgnoreCase("reset")) {
-                    exec.reset();
-                } else if (event.indexOf('=') != -1) {
-                    int marker = event.indexOf('=');
-                    String name = event.substring(0, marker);
-                    String value = event.substring(marker + 1);
-                    rootCtx.setLocal(name, value);
-                    System.out.println("Set variable " + name + " to "
-                        + value);
-                } else if (SCXMLHelper.isStringEmpty(event)
-                           || event.equalsIgnoreCase("null")) {
-                    TriggerEvent[] evts = {new TriggerEvent(null,
-                        TriggerEvent.SIGNAL_EVENT, null)};
-                    exec.triggerEvents(evts);
-                    if (exec.getCurrentStatus().isFinal()) {
-                        System.out.println("A final configuration reached.");
-                    }
-                } else {
-                    StringTokenizer st = new StringTokenizer(event);
-                    int tkns = st.countTokens();
-                    TriggerEvent[] evts = new TriggerEvent[tkns];
-                    for (int i = 0; i < tkns; i++) {
-                        evts[i] = new TriggerEvent(st.nextToken(),
-                                TriggerEvent.SIGNAL_EVENT, null);
-                    }
-                    exec.triggerEvents(evts);
-                    if (exec.getCurrentStatus().isFinal()) {
-                        System.out.println("A final configuration reached.");
-                    }
-                }
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } catch (ModelException e) {
-            e.printStackTrace();
-        } catch (SAXException e) {
-            e.printStackTrace();
-        }
-
-    }
-
-    /**
-     * @param uri an absolute or relative URL
-     * @return java.lang.String canonical URL (absolute)
-     * @throws java.io.IOException if a relative URL can not be resolved
-     *         to a local file
-     */
-    private static String getCanonicalURI(final String uri)
-    throws IOException {
-        if (uri.toLowerCase().startsWith("http://")
-            || uri.toLowerCase().startsWith("file://")) {
-                return uri;
-        }
-        File in = new File(uri);
-        return "file:///" + in.getCanonicalPath();
+        Evaluator evaluator = new ELEvaluator();
+        StandaloneUtils.execute(args[0], evaluator);
     }
 
     /**

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java Sun Jan  8 14:39:15 2006
@@ -0,0 +1,53 @@
+/*
+ * 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.env.jexl;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+
+/**
+ * Test suite for SCXML JEXL Environment package.
+ *
+ */
+public class EnvJexlTestSuite extends TestCase {
+    
+    /**
+     * Construct a new instance.
+     */
+    public EnvJexlTestSuite(String name) {
+        super(name);
+    }
+
+    /**
+     * Command-line interface.
+     */
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+    /**
+     * Get the suite of tests
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.setName("Commons-SCXML JEXL Environment Tests");
+        return suite;
+    }
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml Sun Jan  8 14:39:15 2006
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<!--
+   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.
+-->
+<!--
+   This document uses Commons JEXL as the expressions language.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/SCXML"
+       version="1.0"
+       initialstate="off">
+  
+  <!--  trivial microwave oven example -->
+  <state id="off">
+    <!-- off state -->
+    <transition event="turn_on">
+      <target next="on"/>
+    </transition>
+  </state>
+
+  <state id="on">
+    <initial>
+      <transition>
+        <target next="idle"/>
+      </transition>
+    </initial>
+
+    <!-- on/pause state -->
+    <onentry>
+      <!-- we assume the cook_time is passed in as a context parameter -->
+      <if cond="empty(cook_time)">
+        <!-- default setting -->
+        <var name="cook_time" expr="5"/>
+      </if>
+      <!-- again, door_closed should be a part of a global context -->
+      <if cond="empty(door_closed)">
+        <!-- default setting -->
+        <var name="door_closed" expr="true"/>
+      </if>
+      <!-- timer variable -->
+      <var name="timer" expr="0"/>
+    </onentry>
+
+    <transition event="turn_off">
+        <target next="off"/>
+    </transition>
+
+    <transition cond="timer ge cook_time">
+        <target next="off"/>
+    </transition>
+
+    <state id="idle">
+      <transition cond="door_closed">
+        <!-- default immediate transition -->
+        <target next="cooking"/>
+      </transition>  
+      <transition event="door_close">
+        <assign name="door_closed" expr="true"/>
+        <!-- start cooking -->
+        <target next="cooking"/>
+      </transition>
+    </state>
+
+    <state id="cooking">
+      <transition event="door_open">
+        <assign name="door_closed" expr="false"/>
+        <target next="idle"/>
+      </transition> 
+      <transition event="time">
+        <assign name="timer" expr="timer + 1"/>
+        <target next="cooking"/>
+      </transition>
+    </state>
+
+  </state>
+
+</scxml>

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-01.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml?rev=367112&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml Sun Jan  8 14:39:15 2006
@@ -0,0 +1,107 @@
+<?xml version="1.0"?>
+<!--
+   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.
+-->
+<!--
+   This document uses Commons JEXL as the expressions language.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/SCXML" version="1.0"  
+       initialstate="oven"> 
+
+  <!--  trivial microwave oven example -->
+  <!-- using parallel and In() predicate -->
+
+  <state id="oven">
+    <parallel id="parts">
+      <state id="engine">
+        <initial>
+          <transition>
+            <target next="off"/>
+          </transition>
+        </initial>
+
+        <state id="off">
+          <!-- off state -->
+          <transition event="turn_on">
+            <target next="on"/>
+          </transition>
+        </state>
+        
+        <state id="on">
+          <initial>
+            <transition>
+              <target next="idle"/>
+            </transition>
+          </initial>
+
+          <!-- on/pause state -->
+          <onentry>
+            <!-- we assume the cook_time is passed in as a context parameter -->
+            <if cond="empty(cook_time)">
+              <!-- default setting -->
+              <var name="cook_time" expr="5"/>
+            </if>
+            <!-- timer variable -->
+            <var name="timer" expr="0"/>
+          </onentry>
+          
+          <transition event="turn_off">
+              <target next="off"/>
+          </transition>
+
+          <transition cond="timer ge cook_time">
+              <target next="off"/>
+          </transition>
+          
+          <state id="idle">
+            <transition cond="In('closed')">
+              <target next="cooking"/>
+            </transition>
+          </state>
+          
+          <state id="cooking">
+            <transition cond="not In('closed')">
+                <target next="idle"/>
+            </transition>
+            <transition event="time">
+              <assign name="timer" expr="timer + 1"/>
+              <target next="cooking"/>
+            </transition>
+          </state>
+        </state>
+      </state>
+
+      <state id="door">
+        <initial>
+          <transition>
+            <target next="closed"/>
+          </transition>
+        </initial>
+        <state id="closed">
+          <transition event="door_open">
+              <target next="open"/>
+          </transition>
+        </state>
+        <state id="open">
+          <transition event="door_close">
+              <target next="closed"/>
+          </transition>
+        </state>
+      </state>
+    </parallel>
+  </state>
+
+
+</scxml>

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/microwave-02.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-01.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-01.xml?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-01.xml (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-01.xml Sun Jan  8 14:39:15 2006
@@ -14,6 +14,9 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
+<!--
+   This document uses JSP 2.0 EL as the expressions language.
+-->
 <scxml xmlns="http://www.w3.org/2005/07/SCXML"
        version="1.0"
        initialstate="off">

Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-02.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-02.xml?rev=367112&r1=367111&r2=367112&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-02.xml (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/microwave-02.xml Sun Jan  8 14:39:15 2006
@@ -14,6 +14,9 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
+<!--
+   This document uses JSP 2.0 EL as the expressions language.
+-->
 <scxml xmlns="http://www.w3.org/2005/07/SCXML" version="1.0"  
        initialstate="oven"> 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org