You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2009/07/13 00:25:50 UTC

svn commit: r793421 - in /commons/proper/scxml/branches/J6: ./ src/main/java/org/apache/commons/scxml/env/rhino/ src/main/java/org/apache/commons/scxml/test/ src/test/java/org/apache/commons/scxml/env/rhino/

Author: rahul
Date: Sun Jul 12 22:25:49 2009
New Revision: 793421

URL: http://svn.apache.org/viewvc?rev=793421&view=rev
Log:
Add ECMAScript + E4X support via Rhino (optional feature, binary dependency). Allows leveraging the XML datamodel with ECMAScript in a sane fashion.
Highly modified version of a patch submitted thanks to Ingmar Kliche <ingmar dot kliche at googlemail dot com>.
SCXML-108

Added:
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java   (with props)
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java   (with props)
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java   (with props)
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java   (with props)
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java   (with props)
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java   (with props)
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java   (with props)
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml   (with props)
Modified:
    commons/proper/scxml/branches/J6/build.xml
    commons/proper/scxml/branches/J6/pom.xml
    commons/proper/scxml/branches/J6/project.xml

Modified: commons/proper/scxml/branches/J6/build.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/build.xml?rev=793421&r1=793420&r2=793421&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/build.xml (original)
+++ commons/proper/scxml/branches/J6/build.xml Sun Jul 12 22:25:49 2009
@@ -133,6 +133,8 @@
           </include>
           <include name="org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java">
           </include>
+          <include name="org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java">
+          </include>
           <include name="org/apache/commons/scxml/env/servlet/EnvServletTestSuite.java">
           </include>
           <include name="org/apache/commons/scxml/env/xpath/EnvXPathTestSuite.java">
@@ -217,6 +219,10 @@
     </get>
     <get dest="${libdir}/commons-logging-1.1.1.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar">
     </get>
+    <get dest="${libdir}/js-1.6R7.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven2/rhino/js/1.6R7/js-1.6R7.jar">
+    </get>
+    <get dest="${libdir}/xmlbeans-2.3.0.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven2/org/apache/xmlbeans/xmlbeans/2.3.0/xmlbeans-2.3.0.jar">
+    </get>
     <get dest="${libdir}/servletapi-2.4.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven2/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar">
     </get>
     <get dest="${libdir}/jsp-api-2.0.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven2/javax/servlet/jsp-api/2.0/jsp-api-2.0.jar">

Modified: commons/proper/scxml/branches/J6/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/pom.xml?rev=793421&r1=793420&r2=793421&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/pom.xml (original)
+++ commons/proper/scxml/branches/J6/pom.xml Sun Jul 12 22:25:49 2009
@@ -158,6 +158,18 @@
       <optional>true</optional>
     </dependency>
     <dependency>
+      <groupId>rhino</groupId>
+      <artifactId>js</artifactId>
+      <version>1.6R7</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlbeans</groupId>
+      <artifactId>xmlbeans</artifactId>
+      <version>2.3.0</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.4</version>
@@ -224,6 +236,7 @@
             <include>org/apache/commons/scxml/env/j*avascript/EnvJavaScriptTestSuite.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/rhino/EnvRhinoTestSuite.java</include>
             <include>org/apache/commons/scxml/env/servlet/EnvServletTestSuite.java</include>
             <include>org/apache/commons/scxml/env/xpath/EnvXPathTestSuite.java</include>
             <include>org/apache/commons/scxml/invoke/InvokeTestSuite.java</include>

Modified: commons/proper/scxml/branches/J6/project.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/project.xml?rev=793421&r1=793420&r2=793421&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/project.xml (original)
+++ commons/proper/scxml/branches/J6/project.xml Sun Jul 12 22:25:49 2009
@@ -238,6 +238,28 @@
       </properties>
     </dependency>
     <dependency>
+      <groupId>rhino</groupId>
+      <artifactId>js</artifactId>
+      <version>1.6R7</version>
+      <url>http://www.mozilla.org/rhino/</url>
+      <properties>
+        <comment>&lt;b&gt;Usecases&lt;/b&gt;
+        (Rhino/E4X environments)</comment>
+        <optional>true</optional>
+      </properties>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlbeans</groupId>
+      <artifactId>xmlbeans</artifactId>
+      <version>2.3.0</version>
+      <url>http://xmlbeans.apache.org/</url>
+      <properties>
+        <comment>&lt;b&gt;Usecases&lt;/b&gt;
+        (Rhino/E4X environments)</comment>
+        <optional>true</optional>
+      </properties>
+    </dependency>
+    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.4</version>
@@ -311,6 +333,7 @@
         <include>org/apache/commons/scxml/env/javascript/EnvJavaScriptTestSuite.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/rhino/EnvRhinoTestSuite.java</include>
         <include>org/apache/commons/scxml/env/servlet/EnvServletTestSuite.java</include>
         <include>org/apache/commons/scxml/env/xpath/EnvXPathTestSuite.java</include>
         <include>org/apache/commons/scxml/invoke/InvokeTestSuite.java</include>

Added: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java (added)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.rhino;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.scxml.env.SimpleContext;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+import org.w3c.dom.Node;
+
+/**
+ * @see org.apache.commons.scxml.Context
+ */
+public class RhinoContext extends SimpleContext {
+
+    /** Serial Version UID. */
+    private static final long serialVersionUID = 1L;
+
+    /** Rhino scope for saving variables. */
+    private Scriptable scope;
+
+    //// Constants
+    private static final String SCOPE_LOCAL = "local";
+    private static final String SCOPE_PARENT = "parent";
+    private static final String SCOPE_GLOBAL = "global";
+
+    private static final String _ALL_NAMESPACES = "_ALL_NAMESPACES";
+
+    /**
+     * Default constructor.
+     */
+    public RhinoContext() {
+        this(null);
+    }
+
+    /**
+     * Creates new rhino scope. If parent is not null it will be set to new scope's parent.
+     *
+     * @param parent Parent context.
+     */
+    public RhinoContext(org.apache.commons.scxml.Context parent) {
+        super(parent);
+        initContext();
+    }
+
+    /**
+     * @see org.apache.commons.scxml.Context#set(String, Object)
+     */
+    public void set(String name, Object value) {
+        org.apache.commons.scxml.Context parent = getParent();
+        // if variable is local => override it
+        if (scope.has(name, scope)) {
+            setLocal(name, value);
+        }
+        // iterate over all parents until variable is found
+        else if (parent != null && parent.has(name)) {
+            parent.set(name, value);
+        }
+        // no parent contains that variable => create it in local scope
+        else {
+            setLocal(name, value);
+        }
+    }
+
+    /**
+     * @see org.apache.commons.scxml.Context#setLocal(String, Object)
+     */
+    @SuppressWarnings("unchecked")
+    public void setLocal(String name, Object value) {
+        Context cx = Context.enter();
+        try {
+            if (_ALL_NAMESPACES.equals(name)) {
+                Map<String, String> namespaceMap = (Map<String, String>) value;
+                setNamespaces(cx, namespaceMap);
+                if (value != null) {
+                    scope.put(_ALL_NAMESPACES, scope, value);
+                }
+            } else {
+                addVarToScope(cx, scope, name, value);
+            }
+            // output for set variables
+            if (!name.startsWith("_") && !String.valueOf(value).startsWith("<")) {
+                if (value != null) {
+                    getLog().debug(name + " = " + String.valueOf(value) + " (" + value.getClass() + ")");
+                } else {
+                    getLog().debug(name + " = (NULL)");
+                }
+            } else if (!name.startsWith("_") && String.valueOf(value).startsWith("<")) {
+                getLog().info(name + " =\n" + String.valueOf(value));
+            }
+        } catch (Exception e) {
+            getLog().error(e.getMessage(), e);
+        } finally {
+            Context.exit();
+        }
+    }
+
+    /**
+     * @see org.apache.commons.scxml.Context#has(String)
+     */
+    public boolean has(String name) {
+        org.apache.commons.scxml.Context parent = getParent();
+        Context.enter();
+        try {
+            // search local
+            if (scope.has(name, null)) {
+                return true;
+            }
+            // search in parent
+            else if (parent != null && parent.has(name)) {
+                return true;
+            }
+            return false;
+        } catch (Exception e) {
+            getLog().error(e.getMessage(), e);
+            return false;
+        } finally {
+            Context.exit();
+        }
+    }
+
+    /**
+     * @see org.apache.commons.scxml.Context#get(String)
+     */
+    public Object get(String name) {
+        org.apache.commons.scxml.Context parent = getParent();
+        Context.enter();
+        try {
+            // get local
+            Object var = scope.get(name, null);
+
+            if (var != Scriptable.NOT_FOUND) {
+                return var;
+            }
+            // get from parent
+            else if (parent != null) {
+                var = parent.get(name);
+                if (var != Scriptable.NOT_FOUND) {
+                    return var;
+                }
+            }
+            return null;
+        } catch (Exception e) {
+            getLog().error(e.getMessage(), e);
+            return null;
+        } finally {
+            Context.exit();
+        }
+    }
+
+    /**
+     * Get the variable map for this Rhino context's scope.
+     *
+     * @see org.apache.commons.scxml.Context#getVars()
+     */
+    public Map<String, Object> getVars() {
+        Map<String, Object> vars = new HashMap<String, Object>();
+        Object[] ids = scope.getIds();
+        for (int i = ids.length - 1; i >= 0; i--) {
+            String name = ids[i].toString();
+            Object value = scope.get(name, null);
+            // Put all "user defined" objects in the map
+            if (value instanceof String) {
+                vars.put(name, value);
+            }
+        }
+        getLog().warn("RhinoContext::getVars() was called, which returns Strings only.");
+        return vars;
+    }
+
+    /**
+     * @see org.apache.commons.scxml.Context#reset()
+     */
+    public void reset() {
+        initContext();
+    }
+
+    /**
+     * Get the Rhino scope for executing expressions.
+     *
+     * @return Scriptable Rhino scope.
+     */
+    public Scriptable getScope() {
+        return scope;
+    }
+
+    /**
+     * Initializes the Rhino context.
+     */
+    private void initContext() {
+        // create new rhino scope (necessary for evaluator)
+        Context cx = Context.enter();
+        if (getParent() == null) {
+            // the root scope gets the standard objects and constructors
+            scope = cx.initStandardObjects();
+        } else {
+            // get the root scope...
+            org.apache.commons.scxml.Context rootContext = getParent();
+            while (rootContext.getParent() != null) {
+                rootContext = rootContext.getParent();
+            }
+            // ...to search for the constructor to evaluate this scope against
+            scope = cx.newObject(((RhinoContext) rootContext).getScope());
+        }
+        setScopeAttributes();
+        Context.exit();
+    }
+
+    /**
+     * Puts scopes as variables into the scope of this context according to the scope chain.
+     */
+    private void setScopeAttributes() {
+        org.apache.commons.scxml.Context parent = getParent();
+
+        // set itself as "local"
+        scope.put(SCOPE_LOCAL, scope, scope);
+
+        // set parent scope as "parent"
+        if (parent != null) {
+            Scriptable parentscope = ((RhinoContext) parent).getScope();
+            scope.setParentScope(parentscope);
+            scope.put(SCOPE_PARENT, scope, parentscope);
+        } else {
+            scope.setParentScope(null);
+            scope.put(SCOPE_PARENT, scope, null);
+        }
+
+        // set root scope as "global"
+        Scriptable rootscope = scope;
+        while (rootscope.getParentScope() != null) {
+            rootscope = rootscope.getParentScope();
+        }
+        scope.put(SCOPE_GLOBAL, scope, rootscope);
+    }
+
+    /**
+     * Adds the given variable into the scope.
+     *
+     * @param context
+     * @param scope
+     * @param name
+     * @param value
+     */
+    @SuppressWarnings("unchecked")
+    private void addVarToScope(Context context, Scriptable scope, String name, Object value) {
+
+        if (value == null) {
+
+            scope.delete(name);
+
+        } else if (value instanceof Map) {
+
+            Map<String, Object> mapValue = (Map<String, Object>) value;
+            Scriptable mapJSObject = convertMapToJS(context, scope, mapValue);
+            scope.put(name, scope, mapJSObject);
+
+        } else if (value instanceof String) {
+
+            String stringValue = (String) value;
+            // check for a XML string
+            if (stringValue.startsWith("<")) {
+                XmlObject xmlObject = null;
+                try {
+                    XmlOptions options = new XmlOptions();
+                    options.setLoadStripWhitespace();
+                    options.setLoadStripComments();
+                    xmlObject = XmlObject.Factory.parse(stringValue, options);
+                } catch (XmlException e) {
+                    getLog().error(e.getMessage(), e);
+                    return;
+                }
+                Scriptable xmlJSObject = context.newObject(scope, "XML",
+                    new Object[] { Context.javaToJS(xmlObject, scope) });
+                scope.put(name, scope, xmlJSObject);
+            } else {
+                scope.put(name, scope, stringValue);
+            }
+
+        } else if (value instanceof Node) {
+
+            Node nodeValue = (Node) value;
+            XmlObject xml = null;
+            try {
+                XmlOptions options = new XmlOptions();
+                options.setLoadStripWhitespace();
+                options.setLoadStripComments();
+                xml = XmlObject.Factory.parse(nodeValue, options);
+            } catch (XmlException e) {
+                getLog().error(e.getMessage(), e);
+                return;
+            }
+            Scriptable xmlObject = context.newObject(scope, "XML", new Object[] { Context.javaToJS(xml, scope) });
+            scope.put(name, scope, xmlObject);
+
+        } else {
+
+            scope.put(name, scope, value);
+
+        }
+    }
+
+    /**
+     * Converts a {@link Map} to an JavaScript object.
+     *
+     * @param cx
+     *            Context to evaluate new XMLObject
+     * @param scope
+     *            Rhino scope to evaluate new XMLObject in
+     * @param map
+     *            Map to convert into an XMLObject
+     * @return Returns the converted Map.
+     *
+     */
+    private Scriptable convertMapToJS(Context cx, Scriptable scope, Map<String, Object> map) {
+        Scriptable newJSObject = cx.newObject(scope);
+        for (String key : map.keySet()) {
+            Object value = map.get(key);
+            addVarToScope(cx, newJSObject, key, value);
+        }
+        return newJSObject;
+    }
+
+    /**
+     * Sets a specified map of namespaces in RhinoContext.
+     *
+     * @param cx
+     *            Context to evaluate namespaces
+     * @param value
+     *            Map of namespaces
+     */
+    private void setNamespaces(Context cx, Map<String, String> namespaceMap) {
+        if (namespaceMap == null) {
+            return;
+        }
+        for (String nsPrefix : namespaceMap.keySet()) {
+            String nsURI = namespaceMap.get(nsPrefix);
+            // ignore the default namespace
+            if (!"".equals(nsPrefix)) {
+                Scriptable nsObject = cx.newObject(scope, "Namespace", new Object[] { nsPrefix, nsURI });
+                scope.put(nsPrefix, scope, nsObject);
+            }
+        }
+    }
+
+}
+

Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java (added)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.rhino;
+
+import java.io.Serializable;
+import java.util.regex.Pattern;
+
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.SCXMLExpressionException;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Script;
+import org.w3c.dom.Node;
+
+/**
+ * @see Evaluator
+ */
+public class RhinoEvaluator implements Evaluator, Serializable {
+
+    /** Serial Version UID. */
+    private static final long serialVersionUID = 1L;
+
+    /** Pattern for recognizing the SCXML In() special predicate. */
+    private static final Pattern IN_FN = Pattern.compile("In\\(");
+    // And E4X over Data()
+
+    /**
+     * Constructor.
+     */
+    public RhinoEvaluator() {
+        super();
+    }
+
+    /**
+     * @see Evaluator#eval(org.apache.commons.scxml.Context, String)
+     */
+    public Object eval(final org.apache.commons.scxml.Context ctx, final String expr)
+            throws SCXMLExpressionException {
+        if(expr == null) {
+            return null;
+        }
+
+        RhinoContext rhinocx = getRhinoContext(ctx);
+        Context cx = Context.enter();
+        String jsExpression = IN_FN.matcher(expr).
+            replaceAll("Packages.org.apache.commons.scxml.Builtin.isMember(_ALL_STATES, ");
+
+        try {
+            Script compliedScript = cx.compileString(jsExpression, "RhinoEvaluator", 1, null);
+            return compliedScript.exec(cx, rhinocx.getScope());
+        } catch(Exception e) {
+            throw new SCXMLExpressionException("eval('" + expr + "'):" + jsExpression + ":" + e.getMessage(), e);
+        } finally {
+            Context.exit();
+        }
+
+    }
+
+    /**
+     * @see Evaluator#evalCond(org.apache.commons.scxml.Context, String)
+     */
+    public Boolean evalCond(final org.apache.commons.scxml.Context ctx,
+            final String expr)
+            throws SCXMLExpressionException {
+        if(expr == null) {
+            return null;
+        }
+
+        RhinoContext rhinocx = getRhinoContext(ctx);
+        Context cx = Context.enter();
+        String jsExpression = IN_FN.matcher(expr).
+            replaceAll("Packages.org.apache.commons.scxml.Builtin.isMember(_ALL_STATES, ");
+
+        try {
+            Script compliedScript = cx.compileString(jsExpression, "RhinoEvaluator", 1, null);
+            return (Boolean) compliedScript.exec(cx, rhinocx.getScope());
+        } catch(Exception e) {
+            throw new SCXMLExpressionException("evalCond('" + expr + "'):" + e.getMessage(), e);
+        } finally {
+            Context.exit();
+        }
+    }
+
+    /**
+     * @see Evaluator#evalLocation(org.apache.commons.scxml.Context, String)
+     * @deprecated because of E4X availability of Rhino
+     */
+    public Node evalLocation(final org.apache.commons.scxml.Context ctx, final String expr)
+    throws SCXMLExpressionException {
+        if(expr == null) {
+            return null;
+        }
+
+        // We cannot convert back the child elements, so location will not work!
+        throw new SCXMLExpressionException("evalLocation('" + expr
+            + "'): You should use E4X in script tag instead of location.");
+    }
+
+    /**
+     * @see Evaluator#evalScript(org.apache.commons.scxml.Context, String)
+     */
+    public Object evalScript(org.apache.commons.scxml.Context ctx, String script)
+            throws SCXMLExpressionException {
+        return eval(ctx, script);
+    }
+
+    /**
+     * @see Evaluator#newContext(org.apache.commons.scxml.Context)
+     */
+    public org.apache.commons.scxml.Context newContext(
+            final org.apache.commons.scxml.Context parent) {
+        return new RhinoContext(parent);
+    }
+
+    /**
+     * Gets the RhinoContext.
+     *
+     * @param ctx The Context
+     * @return RhinoContext
+     * @throws SCXMLExpressionException If Context is not an instance of RhinoContext
+     */
+    private RhinoContext getRhinoContext(org.apache.commons.scxml.Context ctx)
+            throws SCXMLExpressionException {
+        if(ctx instanceof RhinoContext) {
+            return (RhinoContext)ctx;
+        } else {
+            throw new SCXMLExpressionException("Error evaluating Rhino expression. "
+                + "Context must be a org.apache.commons.scxml.env.rhino.RhinoContext");
+        }
+    }
+
+}
+

Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/rhino/RhinoEvaluator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java (added)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.test;
+
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.env.rhino.RhinoEvaluator;
+
+/**
+ * Standalone SCXML interpreter, useful for command-line testing and
+ * debugging, where expressions are ECMA script expressions.
+ *
+ * <p>USAGE:</p>
+ * <p><code>java org.apache.commons.scxml.test.StandaloneRhinoExpressions
+ *          url</code></p>
+ * <p>or</p>
+ * <p><code>java org.apache.commons.scxml.test.StandaloneRhinoExpressions
+ *          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 StandaloneRhinoExpressions {
+
+    /**
+     * 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 "
+                    + StandaloneRhinoExpressions.class.getName()
+                    + "<url|filename>");
+            System.exit(-1);
+        }
+        Evaluator evaluator = new RhinoEvaluator();
+        StandaloneUtils.execute(args[0], evaluator);
+    }
+
+    /**
+     * Discourage instantiation since this is a utility class.
+     */
+    private StandaloneRhinoExpressions() {
+        super();
+    }
+
+}
+

Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/test/StandaloneRhinoExpressions.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.rhino;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+
+/**
+ * Test suite for SCXML env Rhino package.
+ *
+ */
+public class EnvRhinoTestSuite extends TestCase {
+
+    /**
+     * Construct a new instance.
+     */
+    public EnvRhinoTestSuite(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 Rhino Environment Tests");
+        suite.addTest(RhinoEvaluatorTest.suite());
+        suite.addTest(RhinoExampleTest.suite());
+        suite.addTest(RhinoContextTest.suite());
+        return suite;
+    }
+}
+

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/EnvRhinoTestSuite.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.rhino;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.env.rhino.RhinoContext;
+import org.apache.commons.scxml.env.rhino.RhinoEvaluator;
+import org.mozilla.javascript.Script;
+import org.mozilla.javascript.Scriptable;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Tests for class {@link RhinoContext}.
+ */
+public class RhinoContextTest extends TestCase {
+
+    /**
+     * Constructs a test case with the given name.
+     *
+     * @param name
+     *            The name of the test case.
+     */
+    public RhinoContextTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(RhinoContextTest.class);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testSetStringValue() throws Exception {
+        Context context = new RhinoContext();
+        context.set("myVar", "stringValue");
+        Object returnObject = context.get("myVar");
+        Assert.assertTrue(returnObject instanceof String);
+        Assert.assertEquals("stringValue", returnObject);
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testSetIntValue() throws Exception {
+        Context context = new RhinoContext();
+        context.set("myVar", new Integer(27));
+        Object returnObject = context.get("myVar");
+        Assert.assertTrue(returnObject instanceof Integer);
+        Assert.assertEquals(27, ((Integer)returnObject).intValue());
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testSetXMLValue() throws Exception {
+        Context context = new RhinoContext();
+        String xmlString = "<foo><bar>bar</bar></foo>";
+        context.set("root", xmlString);
+        Object returnObject = context.get("root");
+        Assert.assertTrue(returnObject instanceof Scriptable);
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testSetMapValueWithStringEntry() throws Exception {
+        Context context = new RhinoContext();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("myVar", "stringValue");
+        context.set("theMap", map);
+        Object returnObject = context.get("theMap");
+        Assert.assertTrue(returnObject instanceof Scriptable);
+        Assert.assertEquals("stringValue", ((Scriptable)returnObject).get("myVar", null));
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testSetMapValueWithMapEntry() throws Exception {
+        Context context = new RhinoContext();
+        Map<String, Map<String, String>> map1 = new HashMap<String, Map<String, String>>();
+        Map<String, String> map2 = new HashMap<String, String>();
+        map2.put("myVar", "stringValue");
+        map1.put("map2", map2);
+        context.set("map1", map1);
+        Object returnObject = context.get("map1");
+        Assert.assertTrue(returnObject instanceof Scriptable);
+        returnObject = ((Scriptable)returnObject).get("map2", null);
+        Assert.assertTrue(returnObject instanceof Scriptable);
+        Assert.assertEquals("stringValue", ((Scriptable)returnObject).get("myVar", null));
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testSetMapValueWithXMLStringEntry() throws Exception {
+        RhinoContext context = new RhinoContext();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("myVar", "<a xmlns:e='http://foo.bar.de'><b><e:c>foo</e:c></b></a>");
+        Map<String, String> namespaceMap = new HashMap<String, String>();
+        namespaceMap.put("e", "http://foo.bar.de");
+        context.set("_ALL_NAMESPACES", namespaceMap);
+        context.set("theMap", map);
+        org.mozilla.javascript.Context cx = org.mozilla.javascript.Context.enter();
+        Script s = cx.compileString("theMap.myVar..e::c.toString()", "", 1, null);
+        Object returnObject = s.exec(cx, context.getScope());
+        org.mozilla.javascript.Context.exit();
+        Assert.assertTrue(returnObject instanceof String);
+        Assert.assertEquals("foo", returnObject.toString());
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testCompileStringWithNodeValue() throws Exception {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        Document doc = builder.newDocument();
+
+        Element fooElement = doc.createElement("foo");
+        Element barElement = doc.createElement("bar");
+        fooElement.appendChild(barElement);
+        barElement.appendChild(doc.createTextNode("blub"));
+
+        RhinoContext context = new RhinoContext();
+        context.set("foobar", fooElement);
+
+        org.mozilla.javascript.Context cx = org.mozilla.javascript.Context.enter();
+        Script s = cx.compileString("var test = foobar.bar.toString()", "", 1, null);
+        s.exec(cx, context.getScope());
+        org.mozilla.javascript.Context.exit();
+
+        Object returnValue = context.get("test");
+        Assert.assertTrue( returnValue instanceof String);
+        Assert.assertEquals("blub", returnValue);
+    }
+
+    public void testSetLocalWithMap() throws Exception {
+        Evaluator evaluator = new RhinoEvaluator();
+        Context ctx = evaluator.newContext(null);
+        Map<String, Object> m = new HashMap<String, Object>();
+        m.put("name", "theEventName");
+        m.put("data", new Integer(4711));
+        ctx.setLocal("_event", m);
+        Object eventname = evaluator.eval(ctx, "_event.name");
+        assertTrue(eventname instanceof String);
+        assertEquals("theEventName", eventname);
+        Object evateData = evaluator.eval(ctx, "_event.data");
+        assertTrue(evateData instanceof Integer);
+        assertEquals(new Integer(4711), evateData);
+    }
+
+    public void testSetLocalWithMapInMap() throws Exception {
+        Evaluator evaluator = new RhinoEvaluator();
+        Context ctx = evaluator.newContext(null);
+        Map<String, Object> m1 = new HashMap<String, Object>();
+        m1.put("name", "theEventName");
+        Map<String, String> m2 = new HashMap<String, String>();
+        m2.put("foo", "bar");
+        m1.put("data", m2);
+        ctx.setLocal("_event", m1);
+        Object eventname = evaluator.eval(ctx, "_event.name");
+        assertTrue(eventname instanceof String);
+        assertEquals("theEventName", eventname);
+        Object foo = evaluator.eval(ctx, "_event.data.foo");
+        assertEquals("bar", foo);
+    }
+
+    public void testSetLocalWithNullValue() throws Exception {
+        Context context = new RhinoContext();
+        context.set("myVar", "stringValue");
+        Object returnObject = context.get("myVar");
+        Assert.assertTrue(returnObject instanceof String);
+        Assert.assertEquals("stringValue", returnObject);
+        context.set("myVar", null);
+        returnObject = context.get("myVar");
+        Assert.assertNull(returnObject);
+    }
+
+}
+

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoContextTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.rhino;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.SCXMLExpressionException;
+import org.apache.commons.scxml.env.rhino.RhinoContext;
+import org.apache.commons.scxml.env.rhino.RhinoEvaluator;
+
+public class RhinoEvaluatorTest extends TestCase {
+
+    private String BAD_EXPRESSION = ">";
+    private Context ctx = new RhinoContext();
+
+    public RhinoEvaluatorTest(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(RhinoEvaluatorTest.class);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = {RhinoEvaluatorTest.class.getName()};
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public void testPristine() throws SCXMLExpressionException {
+        Evaluator eval = new RhinoEvaluator();
+        assertNotNull(eval);
+        assertTrue(eval.evalCond(ctx, "1+1 == 2").booleanValue());
+    }
+
+    public void testErrorMessage() {
+        Evaluator eval = new RhinoEvaluator();
+        assertNotNull(eval);
+        try {
+            eval.eval(ctx, BAD_EXPRESSION);
+            fail("RhinoEvaluator should throw SCXMLExpressionException");
+        } catch (SCXMLExpressionException e) {
+            assertTrue("RhinoEvaluator: Incorrect error message",
+                e.getMessage().startsWith("eval('" + BAD_EXPRESSION + "'):"));
+        }
+    }
+
+}
+

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoEvaluatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java Sun Jul 12 22:25:49 2009
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.rhino;
+
+import java.net.URL;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.scxml.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+public class RhinoExampleTest extends TestCase {
+
+    public RhinoExampleTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(RhinoExampleTest.class);
+        suite.setName("SCXML Rhino Environment Example Tests");
+        return suite;
+    }
+
+    // Test data
+    private URL example01;
+    private SCXMLExecutor exec;
+
+    protected void setUp() throws Exception {
+        example01 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/env/rhino/example-01.xml");
+    }
+
+    protected void tearDown() throws Exception {
+        example01 = null;
+    }
+
+    // TEST METHODS
+
+    public void testExample01Sample() throws Exception {
+        exec = SCXMLTestHelper.getExecutor(example01, new RhinoEvaluator());
+        assertNotNull(exec);
+        Set<TransitionTarget> currentStates = exec.getCurrentStatus().getStates();
+        assertEquals(1, currentStates.size());
+        assertEquals("ten", ((State)currentStates.iterator().next()).getId());
+        SCXMLTestHelper.assertPostTriggerState(exec, "ten.done", "twenty");
+        SCXMLTestHelper.assertPostTriggerState(exec, "twenty.done", "thirty");
+        SCXMLTestHelper.assertPostTriggerState(exec, "thirty.done", "forty");
+    }
+
+}
+

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/RhinoExampleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml?rev=793421&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml Sun Jul 12 22:25:49 2009
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+<!--
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You 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.
+-->
+<!-- SCXML Rhino (ECMA / E4X) environment: example script -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="main">
+
+    <!-- Root or document datamodel -->
+    <datamodel>
+        <data id="docdata">
+            <root xmlns="">
+                <foo>foo</foo>
+            </root>
+        </data>
+    </datamodel>
+
+    <state id="main">
+        <initial>
+            <transition target="ten" />
+        </initial>
+
+        <!-- datamodel scoped to state "main" -->
+        <datamodel>
+            <data id="mainvar" expr="0" />
+            <data id="maindata">
+                <root xmlns="">
+                    <foo>
+                        <bar>bar</bar>
+                    </foo>
+                </root>
+            </data>
+        </datamodel>
+
+        <state id="ten">
+            <onentry>
+                <assign name="mainvar" expr="10" />
+            </onentry>
+            <transition event="ten.done" cond="mainvar == 10 &amp;&amp; maindata.root.foo.bar == 'bar'" target="twenty" />
+            <onexit>
+                <script>maindata.root.foo.bar.* = 'baz';</script>
+            </onexit>
+        </state>
+        <state id="twenty">
+            <onentry>
+                <assign name="mainvar" expr="20" />
+            </onentry>
+            <transition event="twenty.done" cond="mainvar == 20 &amp;&amp; maindata.root.foo.bar == 'baz'" target="thirty" />
+            <onexit>
+                <script> docdata.root.foo.* = maindata.root.foo; docdata.root.foo.bar.* = 10; </script>
+                <log label="datamodel01" expr="docdata.toString()" />
+            </onexit>
+        </state>
+        <state id="thirty">
+            <transition event="thirty.done" cond="docdata.root.foo.bar &gt; 5" target="forty" />
+        </state>
+        <state id="forty" final="true" />
+
+    </state>
+
+</scxml>
+

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/rhino/example-01.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL