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 2007/12/04 23:28:15 UTC
svn commit: r601119 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml/io/
main/java/org/apache/commons/scxml/model/
test/java/org/apache/commons/scxml/model/
Author: rahul
Date: Tue Dec 4 14:28:14 2007
New Revision: 601119
URL: http://svn.apache.org/viewvc?rev=601119&view=rev
Log:
SCXML-55 Add support for <event> tag
Test by Mike Tillberg <mtillberg at comcast dot net>
Added:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java (with props)
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ActionsTest.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=601119&r1=601118&r2=601119&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java Tue Dec 4 14:28:14 2007
@@ -45,6 +45,7 @@
import org.apache.commons.scxml.model.Datamodel;
import org.apache.commons.scxml.model.Else;
import org.apache.commons.scxml.model.ElseIf;
+import org.apache.commons.scxml.model.Event;
import org.apache.commons.scxml.model.Executable;
import org.apache.commons.scxml.model.Exit;
import org.apache.commons.scxml.model.ExternalContent;
@@ -576,6 +577,9 @@
/** <assign> child element. */
private static final String XPF_ASN = "/assign";
+ /** <event> child element. */
+ private static final String XPF_EVT = "/event";
+
/** <send> child element. */
private static final String XPF_SND = "/send";
@@ -1006,6 +1010,7 @@
// Actions in SCXML namespace
addActionRulesTuple(xp + XPF_ASN, scxmlRules, Assign.class);
scxmlRules.add(xp + XPF_ASN, new SetPathResolverRule(pr));
+ addActionRulesTuple(xp + XPF_EVT, scxmlRules, Event.class);
addSendRulesTuple(xp + XPF_SND, scxmlRules);
addActionRulesTuple(xp + XPF_CAN, scxmlRules, Cancel.class);
addActionRulesTuple(xp + XPF_LOG, scxmlRules, Log.class);
Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java?rev=601119&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java (added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java Tue Dec 4 14:28:14 2007
@@ -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.ErrorReporter;
+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
+ * <event> SCXML element.
+ *
+ */
+public class Event extends Action {
+
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The name of the derived event to be generated.
+ */
+ private String name;
+
+ /**
+ * Constructor.
+ */
+ public Event() {
+ super();
+ }
+
+ /**
+ * Get the event name.
+ *
+ * @return Returns the name.
+ */
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * Set the event name.
+ *
+ * @param name The event name to set.
+ */
+ public final void setName(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute(final EventDispatcher evtDispatcher,
+ final ErrorReporter errRep, final SCInstance scInstance,
+ final Log appLog, final Collection derivedEvents)
+ throws ModelException, SCXMLExpressionException {
+
+ if (appLog.isDebugEnabled()) {
+ appLog.debug("<event>: Adding event named '" + name
+ + "' to list of derived events.");
+ }
+ TriggerEvent ev = new TriggerEvent(name, TriggerEvent.SIGNAL_EVENT);
+ derivedEvents.add(ev);
+
+ }
+
+}
+
Propchange: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Event.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ActionsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ActionsTest.java?rev=601119&r1=601118&r2=601119&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ActionsTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ActionsTest.java Tue Dec 4 14:28:14 2007
@@ -83,10 +83,13 @@
* Test the implementation
*/
public void testModelActions() {
- exec = SCXMLTestHelper.getExecutor(actionsSample, ctx, evaluator);
+ SCXML scxml = SCXMLTestHelper.parse(actionsSample);
+ exec = SCXMLTestHelper.getExecutor(scxml, ctx, evaluator);
ELContext ctx = (ELContext) SCXMLTestHelper.lookupContext(exec,
"actionsTest");
assertEquals((String) ctx.get("foo"), "foobar");
+ assertEquals("Missed event transition",
+ "true", (String) ctx.get("eventsent"));
}
public static void main(String args[]) {
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml?rev=601119&r1=601118&r2=601119&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml Tue Dec 4 14:28:14 2007
@@ -16,13 +16,15 @@
* limitations under the License.
-->
<scxml xmlns="http://www.w3.org/2005/07/scxml"
+ xmlns:cs="http://commons.apache.org/scxml"
version="1.0"
initialstate="actionsTest">
<state id="actionsTest" final="true">
<onentry>
- <var name="foo" expr="" />
- <var name="delta" expr="${1+2+3}" />
+ <cs:var name="foo"/>
+ <cs:var name="delta" expr="${1+2+3}" />
+ <cs:var name="eventsent"/>
<if cond="${delta le 3}">
<assign name="foo" expr="bar" />
<elseif cond="${delta eq 3}"/>
@@ -30,15 +32,21 @@
<else/>
<assign name="foo" expr="foobar" />
</if>
- <var name="drink" expr="water" />
- <var name="eat" expr="flies" />
+ <cs:var name="drink" expr="water" />
+ <cs:var name="eat" expr="flies" />
<send sendid="send12345" target="freddy" targettype="frog"
event="croak" namelist="drink eat" hints="h2o bzz"
delay="1000" />
<cancel sendId="send12345"/>
<log expr="leaving" label="entry001" />
+ <event name="event.test"/>
<exit expr="later" namelist="freddy" />
</onentry>
+
+ <transition event="event.test">
+ <assign name="eventsent" expr="true"/>
+ </transition>
+
</state>
</scxml>