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 2008/12/23 01:17:34 UTC
svn commit: r728828 - in /commons/proper/scxml/branches/J6/src:
main/java/org/apache/commons/scxml/
main/java/org/apache/commons/scxml/env/javascript/
main/java/org/apache/commons/scxml/env/jexl/
main/java/org/apache/commons/scxml/env/jsp/ main/java/or...
Author: rahul
Date: Mon Dec 22 16:17:33 2008
New Revision: 728828
URL: http://svn.apache.org/viewvc?rev=728828&view=rev
Log:
Add support for the SCXML Script Module:
* Added a evalScript(Context,String) method to the Evaluator interface
- Breaks backward compatibility, but cleaner than other solutions
* Added Commons JEXL and JavaScript Evaluator script implementations
- Improved JEXLEvaluator's processing of the effective context
* Given their nature, Commons EL and XPath implementations throw UnsupportedOperationException
- Can be moved to parse time error reporting with support for <scxml> "profile" attribute (low priority)
* Added parsing support for <script> SCXML element in executable content
* Added two new test cases
Added:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java (with props)
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java (with props)
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml (with props)
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml (with props)
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java (with props)
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/Evaluator.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSBindings.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSEvaluator.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/xpath/XPathEvaluator.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/Evaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/Evaluator.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/Evaluator.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/Evaluator.java Mon Dec 22 16:17:33 2008
@@ -62,6 +62,18 @@
throws SCXMLExpressionException;
/**
+ * Evaluate a script.
+ * Manifests as <script> element.
+ *
+ * @param ctx variable context
+ * @param script The script
+ * @return The result of the script execution.
+ * @throws SCXMLExpressionException A malformed script
+ */
+ Object evalScript(Context ctx, String script)
+ throws SCXMLExpressionException;
+
+ /**
* Create a new child context.
*
* @param parent parent context
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSBindings.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSBindings.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSBindings.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSBindings.java Mon Dec 22 16:17:33 2008
@@ -193,14 +193,27 @@
}
/**
- * Delegates to the wrapped Bindings <code>put</code> method i.e. does
- * not store variables in the SCXML context. Not entirely sure what it
- * should return if shadowing a variable name in the SCXML context though.
+ * The following delegation model is used to set values:
+ * <ol>
+ * <li>Delegates to {@link Context#set(String,Object)} if the
+ * {@link Context} contains the key (name), else</li>
+ * <li>Delegates to the wrapped {@link Bindings#put(String, Object)}
+ * if the {@link Bindings} contains the key (name), else</li>
+ * <li>Delegates to {@link Context#setLocal(String, Object)}</li>
+ * </ol>
*
*/
@Override
public Object put(String name, Object value) {
+ Object old = context.get(name);
+ if (context.has(name)) {
+ context.set(name, value);
+ } else if (bindings.containsKey(name)) {
return bindings.put(name,value);
+ } else {
+ context.setLocal(name, value);
+ }
+ return old;
}
/**
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSEvaluator.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSEvaluator.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSEvaluator.java Mon Dec 22 16:17:33 2008
@@ -198,6 +198,25 @@
}
/**
+ * Executes the script using a new Javascript engine obtained from
+ * factory instantiated in the constructor. The engine is supplied with
+ * a new JSBindings that includes the SCXML Context and
+ * <code>Data()</code> functions are replaced with an equivalent internal
+ * Javascript function.
+ *
+ * @param context SCXML context.
+ * @param script Script to execute.
+ *
+ * @return Result of script execution or <code>null</code>.
+ *
+ * @throws SCXMLExpressionException Thrown if the script was invalid.
+ */
+ public Object evalScript(Context ctx, String script)
+ throws SCXMLExpressionException {
+ return eval(ctx, script);
+ }
+
+ /**
* Implementation of Javascript function equivalent for the Data() function when
* used in an SCXML <code>expr</code> attribute.
* <p>
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java Mon Dec 22 16:17:33 2008
@@ -17,14 +17,16 @@
package org.apache.commons.scxml.env.jexl;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import java.util.AbstractMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.Script;
+import org.apache.commons.jexl.ScriptFactory;
import org.apache.commons.scxml.Context;
import org.apache.commons.scxml.Evaluator;
import org.apache.commons.scxml.SCXMLExpressionException;
@@ -147,6 +149,34 @@
}
/**
+ * @see Evaluator#evalScript(Context, String)
+ */
+ public Object evalScript(Context ctx, String script)
+ throws SCXMLExpressionException {
+ if (script == null) {
+ return null;
+ }
+ JexlContext jexlCtx = null;
+ if (ctx instanceof JexlContext) {
+ jexlCtx = (JexlContext) ctx;
+ } else {
+ throw new SCXMLExpressionException(ERR_CTX_TYPE);
+ }
+ Script jexlScript = null;
+ try {
+ String scriptStr = inFct.matcher(script).
+ replaceAll("_builtin.isMember(_ALL_STATES, ");
+ scriptStr = dataFct.matcher(scriptStr).
+ replaceAll("_builtin.data(_ALL_NAMESPACES, ");
+ jexlScript = ScriptFactory.createScript(scriptStr);
+ return jexlScript.execute(getEffectiveContext(jexlCtx));
+ } catch (Exception e) {
+ throw new SCXMLExpressionException("evalScript('" + script + "'):"
+ + e.getMessage(), e);
+ }
+ }
+
+ /**
* Create a new child context.
*
* @param parent parent context
@@ -167,19 +197,68 @@
* document root.
*/
private JexlContext getEffectiveContext(final JexlContext nodeCtx) {
- List<JexlContext> contexts = new ArrayList<JexlContext>();
- // trace path to root
- JexlContext currentCtx = nodeCtx;
- while (currentCtx != null) {
- contexts.add(currentCtx);
- currentCtx = (JexlContext) currentCtx.getParent();
- }
- Map<String, Object> vars = new HashMap<String, Object>();
- // summation of the contexts, parent first, child wins
- for (int i = contexts.size() - 1; i > -1; i--) {
- vars.putAll(contexts.get(i).getVars());
+ return new JexlContext(new EffectiveContextMap(nodeCtx));
+ }
+
+ /**
+ * The map that will back the effective context for the
+ * {@link JexlEvaluator}. The effective context enables the chaining of
+ * {@link Context}s all the way from the current state node to the root.
+ *
+ */
+ private static final class EffectiveContextMap extends AbstractMap<String, Object> {
+
+ /** The {@link Context} for the current state. */
+ final Context leaf;
+
+ /** Constructor. */
+ public EffectiveContextMap(JexlContext ctx) {
+ super();
+ this.leaf = ctx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Map.Entry<String, Object>> entrySet() {
+ Set<Map.Entry<String, Object>> entrySet = new HashSet<Map.Entry<String, Object>>();
+ Context current = leaf;
+ while (current != null) {
+ entrySet.addAll(current.getVars().entrySet());
+ current = current.getParent();
+ }
+ return entrySet;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object put(String key, Object value) {
+ Object old = leaf.get(key);
+ if (leaf.has(key)) {
+ leaf.set(key, value);
+ } else {
+ leaf.setLocal(key, value);
+ }
+ return old;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get(Object key) {
+ Context current = leaf;
+ while (current != null) {
+ if (current.getVars().containsKey(key)) {
+ return current.getVars().get(key);
+ }
+ current = current.getParent();
+ }
+ return null;
}
- return new JexlContext(vars);
}
}
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java Mon Dec 22 16:17:33 2008
@@ -37,8 +37,11 @@
import org.w3c.dom.Node;
/**
- * Evaluator implementation enabling use of EL expressions in
- * SCXML documents.
+ * <p>Evaluator implementation enabling use of EL expressions in
+ * SCXML documents.</p>
+ *
+ * <p>Does not support the <script> module, throws
+ * {@link UnsupportedOperationException} if attempted.</p>
*
*/
public class ELEvaluator implements Evaluator, Serializable {
@@ -180,6 +183,14 @@
}
/**
+ * @see Evaluator#evalScript(Context, String)
+ */
+ public Object evalScript(Context ctx, String script)
+ throws SCXMLExpressionException {
+ throw new UnsupportedOperationException("Scripts are not supported by the EL evaluators");
+ }
+
+ /**
* Create a new child context.
*
* @param parent parent context
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/xpath/XPathEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/xpath/XPathEvaluator.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/xpath/XPathEvaluator.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/xpath/XPathEvaluator.java Mon Dec 22 16:17:33 2008
@@ -39,8 +39,10 @@
import org.w3c.dom.Node;
/**
- * An {@link Evaluator} implementation for XPath environments.
+ * <p>An {@link Evaluator} implementation for XPath environments.</p>
*
+ * <p>Does not support the <script> module, throws
+ * {@link UnsupportedOperationException} if attempted.</p>
*/
public class XPathEvaluator implements Evaluator, Serializable {
@@ -123,6 +125,14 @@
}
/**
+ * @see Evaluator#evalScript(Context, String)
+ */
+ public Object evalScript(Context ctx, String script)
+ throws SCXMLExpressionException {
+ throw new UnsupportedOperationException("Scripts are not supported by the XPathEvaluator");
+ }
+
+ /**
* @see Evaluator#newContext(Context)
*/
@Override
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=728828&r1=728827&r2=728828&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java Mon Dec 22 16:17:33 2008
@@ -40,6 +40,7 @@
import org.apache.commons.scxml.env.URLResolver;
import org.apache.commons.scxml.model.Action;
import org.apache.commons.scxml.model.Assign;
+import org.apache.commons.scxml.model.BodyContainer;
import org.apache.commons.scxml.model.Cancel;
import org.apache.commons.scxml.model.CustomAction;
import org.apache.commons.scxml.model.Data;
@@ -65,6 +66,7 @@
import org.apache.commons.scxml.model.Param;
import org.apache.commons.scxml.model.PathResolverHolder;
import org.apache.commons.scxml.model.SCXML;
+import org.apache.commons.scxml.model.Script;
import org.apache.commons.scxml.model.Send;
import org.apache.commons.scxml.model.State;
import org.apache.commons.scxml.model.Transition;
@@ -622,6 +624,9 @@
/** <log> child element. */
private static final String XPF_LOG = "/log";
+ /** <script> child element. */
+ private static final String XPF_SCRIPT = "/script";
+
//// Other constants
// Error messages
/**
@@ -1073,6 +1078,9 @@
addSendRulesTuple(xp + XPF_SND, scxmlRules);
addActionRulesTuple(xp + XPF_CAN, scxmlRules, Cancel.class);
addActionRulesTuple(xp + XPF_LOG, scxmlRules, Log.class);
+ // Script
+ addActionRulesTuple(xp + XPF_SCRIPT, scxmlRules, Script.class);
+ scxmlRules.add(xp + XPF_SCRIPT, new SetBodyRule());
// Actions in Commons SCXML namespace
scxmlRules.setNamespaceURI(NAMESPACE_COMMONS_SCXML);
@@ -1713,5 +1721,22 @@
log.warn(sb.toString());
}
}
+
+ /**
+ * Custom digestion rule for saving the body content in the object model.
+ */
+ private static class SetBodyRule extends Rule {
+
+ /**
+ * @see Rule#body(String, String, String)
+ */
+ @Override
+ public final void body(final String namespace, final String name,
+ final String body) {
+ BodyContainer bc = (BodyContainer) getDigester().peek();
+ bc.setBody(body);
+ }
+ }
+
}
Added: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java?rev=728828&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java (added)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java Mon Dec 22 16:17:33 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.model;
+
+/**
+ * A <code>BodyContainer</code> is an entity that retains the element body
+ * text from the document.
+ *
+ */
+public interface BodyContainer {
+
+ /**
+ * Set the body content as a String.
+ *
+ * @param body The text content in the element body.
+ */
+ void setBody(String body);
+
+ /**
+ * Set the body content as a String.
+ *
+ * @return The text content in the element body.
+ */
+ String getBody();
+
+}
Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/BodyContainer.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java?rev=728828&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java (added)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java Mon Dec 22 16:17:33 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.model;
+
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.Context;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.Evaluator;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
+import org.apache.commons.scxml.TriggerEvent;
+
+/**
+ * The class in this SCXML object model that corresponds to the
+ * <script> SCXML element.
+ *
+ */
+public class Script extends Action implements BodyContainer {
+
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ private String body;
+
+ /**
+ * Constructor.
+ */
+ public Script() {
+ super();
+ }
+
+ @Override
+ public String getBody() {
+ return body;
+ }
+
+ @Override
+ public void setBody(String body) {
+ this.body = body;
+ }
+
+ /**
+ * Get the script to execute.
+ *
+ * @return The script to execute.
+ *
+ * @TODO src attribute support
+ */
+ public String getScript() {
+ return body;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void execute(final EventDispatcher evtDispatcher,
+ final ErrorReporter errRep, final SCInstance scInstance,
+ final Log appLog, final Collection<TriggerEvent> derivedEvents)
+ throws ModelException, SCXMLExpressionException {
+ Context ctx = scInstance.getContext(getParentTransitionTarget());
+ ctx.setLocal(getNamespacesKey(), getNamespaces());
+ Evaluator eval = scInstance.getEvaluator();
+ eval.evalScript(ctx, getScript());
+ ctx.setLocal(getNamespacesKey(), null);
+ }
+
+}
+
Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Script.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml?rev=728828&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml Mon Dec 22 16:17:33 2008
@@ -0,0 +1,43 @@
+<?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 xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ initial="script">
+
+ <datamodel>
+ <data name="x" expr="1"/>
+ </datamodel>
+
+ <state id="script">
+ <datamodel>
+ <data name="y" expr="2"/>
+ </datamodel>
+ <onentry>
+ <script>
+ x = y;
+ y = 3 * 4;
+ var z = 'foo';
+ </script>
+ <assign name="z" expr="'bar'"/> <!-- z is defined by script -->
+ </onentry>
+ <transition target="end" cond="x == 2 && y == 12 && z == 'bar'"/>
+ </state>
+
+ <final id="end"/>
+
+</scxml>
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/script-01.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml?rev=728828&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml Mon Dec 22 16:17:33 2008
@@ -0,0 +1,43 @@
+<?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 xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ initial="script">
+
+ <datamodel>
+ <data name="x" expr="1"/>
+ </datamodel>
+
+ <state id="script">
+ <datamodel>
+ <data name="y" expr="2"/>
+ </datamodel>
+ <onentry>
+ <script>
+ x = y;
+ y = 3 * 4;
+ z = 'foo';
+ </script>
+ <assign name="z" expr="'bar'"/> <!-- z is defined by script -->
+ </onentry>
+ <transition target="end" cond="x eq 2 and y eq 12 and z eq 'bar'"/>
+ </state>
+
+ <final id="end"/>
+
+</scxml>
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/script-01.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java?rev=728828&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java Mon Dec 22 16:17:33 2008
@@ -0,0 +1,82 @@
+/*
+ * 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.model;
+
+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.env.javascript.JSEvaluator;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+public class ScriptTest extends TestCase {
+
+ private URL script01jexl, script01js;
+
+ public ScriptTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(ScriptTest.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = {ScriptTest.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ script01jexl = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/env/jexl/script-01.xml");
+ script01js = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/env/javascript/script-01.xml");
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ script01jexl = script01js = null;
+ }
+
+ /**
+ * Test JEXL script execution.
+ */
+ public void testJexlScriptExecution() {
+ SCXMLExecutor exec = SCXMLTestHelper.getExecutor(script01jexl);
+ Set<TransitionTarget> currentStates = exec.getCurrentStatus().getStates();
+ assertEquals(1, currentStates.size());
+ assertEquals("end", currentStates.iterator().next().getId());
+ }
+
+ public void testJavaScriptExecution() {
+ SCXMLExecutor exec = SCXMLTestHelper.getExecutor(script01js, new JSEvaluator());
+ Set<TransitionTarget> currentStates = exec.getCurrentStatus().getStates();
+ assertEquals(1, currentStates.size());
+ assertEquals("end", currentStates.iterator().next().getId());
+ }
+
+}
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/model/ScriptTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL