Author: rahul
Date: Thu May 15 10:45:32 2008
New Revision: 656755
URL:
http://svn.apache.org/viewvc?rev=656755&view=revLog:
Javascript expression evaluator cannot evaluate _eventdatamap['event.name'].
Documentation and test improvements, no functional change.
Thanks to Tony Seebregts <tony at iveri dot com>
SCXML-71
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/javascript/JSEvaluator.java
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/JSExampleTest.java
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
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=656755&r1=656754&r2=656755&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 Thu May 15 10:45:32 2008
@@ -42,6 +42,16 @@
* is implemented in the same way as the JEXL expression evaluator i.e. using
* the Data() function, for example,
* <assign location="Data(hotelbooking,'hotel/rooms')" expr="2" />
+ * <p>
+ * NOTES:
+ * <ol>
+ * <li>To use _eventdatamap with the Javascript evaluator replace all
+ * _eventdatamap[event] operators with _eventdatamap.get(event) or
+ * _eventdatamap.put(event,data).<br/>
+ * (the SCXML _eventdatamap is implemented as a Java HashMap and the
+ * Rhino interpreter does not implement the [] operator on Java Maps).
+ * </li>
+ * </ol>
*
*/
Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/JSExampleTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/JSExampleTest.java?rev=656755&r1=656754&r2=656755&view=diff==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/JSExampleTest.java (original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/JSExampleTest.java Thu May 15 10:45:32 2008
@@ -18,17 +18,30 @@
package org.apache.commons.scxml.env.javascript;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+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.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLExpressionException;
import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.TriggerEvent;
+import org.apache.commons.scxml.model.Action;
+import org.apache.commons.scxml.model.CustomAction;
+import org.apache.commons.scxml.model.ModelException;
import org.apache.commons.scxml.model.SCXML;
+import org.apache.commons.scxml.model.State;
import org.apache.commons.scxml.model.TransitionTarget;
/**
@@ -69,8 +82,12 @@
// TEST METHODS
public void testExample01Sample() {
-
- SCXML scxml = SCXMLTestHelper.parse(example01);
+
+ List<CustomAction> actions = new ArrayList<CustomAction>();
+ actions.add(new CustomAction("
http://commons.apache.org/scxml",
+ "eventdatamaptest", EventDataMapTest.class));
+
+ SCXML scxml = SCXMLTestHelper.parse(example01,actions);
Evaluator evaluator = new JSEvaluator();
Context context = new JSContext();
exec = SCXMLTestHelper.getExecutor(scxml, context, evaluator);
@@ -79,11 +96,24 @@
try {
Set<TransitionTarget> currentStates = exec.getCurrentStatus().getStates();
assertEquals(1, currentStates.size());
- assertEquals("end", currentStates.iterator().next().getId());
+ assertEquals("end", ((State)currentStates.iterator().
+ next()).getId());
} catch (Exception e) {
fail(e.getMessage());
}
- }
+ }
+
+ // INNER CLASSES
+
+ public static class EventDataMapTest extends Action {
+ private static final long serialVersionUID = 1L;
+
+ public void execute(EventDispatcher dispatcher, ErrorReporter reporter,
+ SCInstance instance, Log log, Collection<TriggerEvent> events)
+ throws ModelException,SCXMLExpressionException {
+ events.add(new TriggerEvent("ok",TriggerEvent.SIGNAL_EVENT,"and its ok with me to"));
+ }
+ }
}
Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml?rev=656755&r1=656754&r2=656755&view=diff==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml (original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml Thu May 15 10:45:32 2008
@@ -133,11 +133,22 @@
debug("This is the Javascript println() function")' />
</onentry>
- <transition target='end' />
+ <transition target='javascript.eventdatamap.example' />
</state>
</state>
+ <!-- _eventdatamap USAGE -->
+
+ <state id='javascript.eventdatamap.example'>
+ <onentry>
+ <scxml:eventdatamaptest />
+ </onentry>
+ <transition target='end' event='ok' >
+ <log expr='"_eventdatamap[ok]=\"" + _eventdatamap.get("ok") + "\""' />
+ </transition>
+ </state>
+
<!-- DONE -->
<state id='end' final='true' >