You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by wo...@apache.org on 2013/12/05 05:25:55 UTC
svn commit: r1548010 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml2/
main/java/org/apache/commons/scxml2/system/
test/java/org/apache/commons/scxml2/
Author: woonsan
Date: Thu Dec 5 04:25:55 2013
New Revision: 1548010
URL: http://svn.apache.org/r1548010
Log:
SCXML-100: initial basic support for _event system variable. _event.name and _event.data are supported now.
TODOs: determine type, sendid, origin and origintype based on context
Added:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/system/
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/system/EventVariable.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/transitions-event-variable.xml
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLExecutorTest.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java?rev=1548010&r1=1548009&r2=1548010&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java Thu Dec 5 04:25:55 2013
@@ -34,6 +34,7 @@ import org.apache.commons.scxml2.model.S
import org.apache.commons.scxml2.model.State;
import org.apache.commons.scxml2.model.TransitionTarget;
import org.apache.commons.scxml2.semantics.SCXMLSemanticsImpl;
+import org.apache.commons.scxml2.system.EventVariable;
/**
* <p>The SCXML "engine" that executes SCXML documents. The
@@ -496,11 +497,11 @@ public class SCXMLExecutor implements Se
*/
private Object[] setEventData(final TriggerEvent[] evts) {
Context rootCtx = scInstance.getRootContext();
- Object[] oldData = {rootCtx.get(EVENT_DATA),
- rootCtx.get(EVENT_DATA_MAP)};
+ Object[] oldData = { rootCtx.get(EVENT_DATA), rootCtx.get(EVENT_DATA_MAP), rootCtx.get(EVENT_VARIABLE) };
int len = evts.length;
if (len > 0) { // 0 has retry semantics (eg: see usage in reset())
Object eventData = null;
+ EventVariable eventVar = null;
Map<String, Object> payloadMap = new HashMap<String, Object>();
for (TriggerEvent te : evts) {
payloadMap.put(te.getName(), te.getPayload());
@@ -508,9 +509,12 @@ public class SCXMLExecutor implements Se
if (len == 1) {
// we have only one event
eventData = evts[0].getPayload();
+ // TODO: determine type, sendid, origin, originType and invokeid based on context.
+ eventVar = new EventVariable(evts[0].getName(), EventVariable.TYPE_INTERNAL, null, null, null, null, eventData);
}
rootCtx.setLocal(EVENT_DATA, eventData);
rootCtx.setLocal(EVENT_DATA_MAP, payloadMap);
+ rootCtx.setLocal(EVENT_VARIABLE, eventVar);
}
return oldData;
}
@@ -521,10 +525,12 @@ public class SCXMLExecutor implements Se
private void restoreEventData(final Object[] oldData) {
scInstance.getRootContext().setLocal(EVENT_DATA, oldData[0]);
scInstance.getRootContext().setLocal(EVENT_DATA_MAP, oldData[1]);
+ scInstance.getRootContext().setLocal(EVENT_VARIABLE, oldData[2]);
}
/**
* The special variable for storing single event data / payload.
+ * @deprecated
*/
private static final String EVENT_DATA = "_eventdata";
@@ -532,9 +538,15 @@ public class SCXMLExecutor implements Se
* The special variable for storing event data / payload,
* when multiple events are triggered, keyed by event name.
*/
+ // TODO: is _eventdatamap really being used somewhere?
private static final String EVENT_DATA_MAP = "_eventdatamap";
/**
+ * The special variable for storing single event data / payload.
+ */
+ private static final String EVENT_VARIABLE = "_event";
+
+ /**
* SCXMLExecutor put into motion without setting a model (state machine).
*/
private static final String ERR_NO_STATE_MACHINE =
Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/system/EventVariable.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/system/EventVariable.java?rev=1548010&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/system/EventVariable.java (added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/system/EventVariable.java Thu Dec 5 04:25:55 2013
@@ -0,0 +1,108 @@
+/*
+ * 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.scxml2.system;
+
+import java.io.Serializable;
+
+/**
+ * Event system variable holding a structure containing the current event's name and any data contained in the event
+ */
+public class EventVariable implements Serializable {
+
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ public static final String TYPE_PLATFORM = "platform";
+ public static final String TYPE_INTERNAL = "internal";
+ public static final String TYPE_EXTERNAL = "external";
+
+ /**
+ * The name of the event.
+ */
+ private final String name;
+
+ /**
+ * The event type
+ */
+ private final String type;
+
+ /**
+ * The sendid in case the sending entity has specified a value for this.
+ */
+ private final String sendid;
+
+ /**
+ * The URI string of the originating entity in an external event.
+ */
+ private final String origin;
+
+ /**
+ * The type in an external event.
+ */
+ private final String originType;
+
+ /**
+ * The invoke id of the invocation that triggered the child process.
+ */
+ private final String invokeId;
+
+ /**
+ * Whatever data the sending entity chose to include in the event
+ */
+ private final Object data;
+
+ public EventVariable(final String name, final String type, final String sendid, final String origin, final String originType, final String invokeId, final Object data) {
+ this.name = name;
+ this.type = type;
+ this.sendid = sendid;
+ this.origin = origin;
+ this.originType = originType;
+ this.invokeId = invokeId;
+ this.data = data;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getSendid() {
+ return sendid;
+ }
+
+ public String getOrigin() {
+ return origin;
+ }
+
+ public String getOriginType() {
+ return originType;
+ }
+
+ public String getInvokeId() {
+ return invokeId;
+ }
+
+ public Object getData() {
+ return data;
+ }
+}
+
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLExecutorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLExecutorTest.java?rev=1548010&r1=1548009&r2=1548010&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLExecutorTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLExecutorTest.java Thu Dec 5 04:25:55 2013
@@ -40,7 +40,7 @@ public class SCXMLExecutorTest {
private URL microwave01jsp, microwave02jsp, microwave01jexl,
microwave02jexl, microwave03jexl, microwave04jexl, microwave05jexl, transitions01,
transitions02, transitions03, transitions04, transitions05, transitions06, prefix01, send01, send02,
- transitionsWithCond01;
+ transitionsWithCond01, transitionsEventVar;
private SCXMLExecutor exec;
/**
@@ -82,6 +82,8 @@ public class SCXMLExecutorTest {
getResource("org/apache/commons/scxml2/send-02.xml");
transitionsWithCond01 = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml2/transitions-with-cond-01.xml");
+ transitionsEventVar = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml2/transitions-event-variable.xml");
}
/**
@@ -92,7 +94,7 @@ public class SCXMLExecutorTest {
microwave01jsp = microwave02jsp = microwave01jexl = microwave02jexl =
microwave04jexl = microwave05jexl = transitions01 = transitions02 = transitions03 =
transitions04 = transitions05 = transitions06 = prefix01 = send01 = send02 =
- transitionsWithCond01 = null;
+ transitionsWithCond01 = transitionsEventVar = null;
}
/**
@@ -314,6 +316,18 @@ public class SCXMLExecutorTest {
SCXMLTestHelper.assertPostTriggerState(exec, "unlock", null, "locked");
}
+ @Test
+ public void testSCXMLExecutorSystemEventVariable() throws Exception {
+ SCXML scxml = SCXMLTestHelper.parse(transitionsEventVar);
+ Assert.assertNotNull(scxml);
+ exec = SCXMLTestHelper.getExecutor(scxml);
+ Assert.assertNotNull(exec);
+
+ Map<String, Object> payload = new HashMap<String, Object>();
+ payload.put("keyed", Boolean.TRUE);
+ SCXMLTestHelper.assertPostTriggerState(exec, "open", payload, "opened");
+ }
+
private void checkMicrowave01Sample() throws Exception {
Set<TransitionTarget> currentStates = SCXMLTestHelper.fireEvent(exec, "turn_on");
Assert.assertEquals(1, currentStates.size());
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/transitions-event-variable.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/transitions-event-variable.xml?rev=1548010&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/transitions-event-variable.xml (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/transitions-event-variable.xml Thu Dec 5 04:25:55 2013
@@ -0,0 +1,34 @@
+<?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.
+-->
+<!--
+ Uses SCXMLReader
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ initial="closed">
+
+ <state id="closed">
+ <transition event="open" cond="_event.name == 'open' and _event.type == 'internal' and _event.data['keyed']" target="opened" />
+ </state>
+
+ <state id="opened">
+ <transition event="close" target="closed" />
+ </state>
+
+</scxml>
+