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 2015/04/09 05:43:20 UTC
svn commit: r1672236 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml2/io/
main/java/org/apache/commons/scxml2/model/
test/java/org/apache/commons/scxml2/model/
Author: woonsan
Date: Thu Apr 9 03:43:19 2015
New Revision: 1672236
URL: http://svn.apache.org/r1672236
Log:
SCXML-227: Applying Michael Goerlich's patch with validating unit tests
Added:
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java?rev=1672236&r1=1672235&r2=1672236&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java Thu Apr 9 03:43:19 2015
@@ -63,9 +63,6 @@ import org.apache.commons.scxml2.model.D
import org.apache.commons.scxml2.model.Else;
import org.apache.commons.scxml2.model.ElseIf;
import org.apache.commons.scxml2.model.EnterableState;
-import org.apache.commons.scxml2.model.ParamsContainer;
-import org.apache.commons.scxml2.model.TransitionalState;
-import org.apache.commons.scxml2.model.Raise;
import org.apache.commons.scxml2.model.Executable;
import org.apache.commons.scxml2.model.ExternalContent;
import org.apache.commons.scxml2.model.Final;
@@ -82,6 +79,8 @@ import org.apache.commons.scxml2.model.O
import org.apache.commons.scxml2.model.OnExit;
import org.apache.commons.scxml2.model.Parallel;
import org.apache.commons.scxml2.model.Param;
+import org.apache.commons.scxml2.model.ParamsContainer;
+import org.apache.commons.scxml2.model.Raise;
import org.apache.commons.scxml2.model.SCXML;
import org.apache.commons.scxml2.model.Script;
import org.apache.commons.scxml2.model.Send;
@@ -89,6 +88,7 @@ import org.apache.commons.scxml2.model.S
import org.apache.commons.scxml2.model.State;
import org.apache.commons.scxml2.model.Transition;
import org.apache.commons.scxml2.model.TransitionType;
+import org.apache.commons.scxml2.model.TransitionalState;
import org.apache.commons.scxml2.model.Var;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -294,6 +294,7 @@ public final class SCXMLReader {
private static final String ATTR_NAMELIST = "namelist";
private static final String ATTR_PROFILE = "profile";
private static final String ATTR_SENDID = "sendid";
+ private static final String ATTR_SENDIDEXPR = "sendidexpr";
private static final String ATTR_SRC = "src";
private static final String ATTR_SRCEXPR = "srcexpr";
private static final String ATTR_TARGET = "target";
@@ -1882,9 +1883,19 @@ public final class SCXMLReader {
*/
private static void readCancel(final XMLStreamReader reader, final Configuration configuration,
final Executable executable, final ActionsContainer parent)
- throws XMLStreamException {
+ throws XMLStreamException, ModelException {
Cancel cancel = new Cancel();
+ cancel.setSendid(readAV(reader, ATTR_SENDID));
+ String attrValue = readAV(reader, ATTR_SENDIDEXPR);
+ if (attrValue != null) {
+ if (cancel.getSendid() != null) {
+ reportConflictingAttribute(reader, configuration, ELEM_CANCEL, ATTR_SENDID, ATTR_SENDIDEXPR);
+ }
+ else {
+ cancel.setSendidexpr(attrValue);
+ }
+ }
readNamespaces(configuration, cancel);
cancel.setParent(executable);
if (parent != null) {
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java?rev=1672236&r1=1672235&r2=1672236&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java Thu Apr 9 03:43:19 2015
@@ -17,6 +17,8 @@
package org.apache.commons.scxml2.model;
import org.apache.commons.scxml2.ActionExecutionContext;
+import org.apache.commons.scxml2.Context;
+import org.apache.commons.scxml2.Evaluator;
import org.apache.commons.scxml2.SCXMLExpressionException;
/**
@@ -44,6 +46,11 @@ public class Cancel extends Action {
private String sendid;
/**
+ * The expression that evaluates to the ID of the send message that should be cancelled.
+ */
+ private String sendidexpr;
+
+ /**
* Get the ID of the send message that should be cancelled.
*
* @return Returns the sendid.
@@ -62,11 +69,44 @@ public class Cancel extends Action {
}
/**
+ * Get the expression that evaluates to the ID of the send message that should be cancelled.
+ *
+ * @return the expression that evaluates to the ID of the send message that should be cancelled.
+ */
+ public String getSendidexpr() {
+ return sendidexpr;
+ }
+
+ /**
+ * Set the expression that evaluates to the ID of the send message that should be cancelled.
+ *
+ * @param sendidexpr the expression that evaluates to the ID of the send message that should be cancelled.
+ */
+ public void setSendidexpr(String sendidexpr) {
+ this.sendidexpr = sendidexpr;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
- exctx.getEventDispatcher().cancel(sendid);
+ EnterableState parentState = getParentEnterableState();
+ Context ctx = exctx.getContext(parentState);
+ ctx.setLocal(getNamespacesKey(), getNamespaces());
+ Evaluator eval = exctx.getEvaluator();
+
+ String sendidValue = sendid;
+ if (sendidValue == null && sendidexpr != null) {
+ sendidValue = (String) getTextContentIfNodeResult(eval.eval(ctx, sendidexpr));
+ if ((sendidValue == null || sendidValue.trim().length() == 0)
+ && exctx.getAppLog().isWarnEnabled()) {
+ exctx.getAppLog().warn("<send>: sendid expression \"" + sendidexpr
+ + "\" evaluated to null or empty String");
+ }
+ }
+
+ exctx.getEventDispatcher().cancel(sendidValue);
}
}
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java?rev=1672236&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java Thu Apr 9 03:43:19 2015
@@ -0,0 +1,50 @@
+/*
+ * 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.model;
+
+import org.apache.commons.scxml2.SCXMLExecutor;
+import org.apache.commons.scxml2.SCXMLTestHelper;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.env.SimpleDispatcher;
+import org.junit.Test;
+
+public class CancelTest {
+
+ @Test
+ public void testCancelBySendId() throws Exception {
+ final SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/model/cancel-test-01.xml");
+ final SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml, null, new SimpleDispatcher());
+ exec.go();
+ TriggerEvent te = new TriggerEvent("event.foo", TriggerEvent.SIGNAL_EVENT);
+ SCXMLTestHelper.fireEvent(exec, te);
+ Thread.sleep(3000);
+ exec.triggerEvents();
+ SCXMLTestHelper.assertState(exec, "twenty");
+ }
+
+ @Test
+ public void testCancelBySendIdExpr() throws Exception {
+ final SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/model/cancel-test-02.xml");
+ final SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml, null, new SimpleDispatcher());
+ exec.go();
+ TriggerEvent te = new TriggerEvent("event.foo", TriggerEvent.SIGNAL_EVENT);
+ SCXMLTestHelper.fireEvent(exec, te);
+ Thread.sleep(3000);
+ exec.triggerEvents();
+ SCXMLTestHelper.assertState(exec, "twenty");
+ }
+}
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml?rev=1672236&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml Thu Apr 9 03:43:19 2015
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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"
+ xmlns:cs="http://commons.apache.org/scxml"
+ version="1.0"
+ datamodel="jexl"
+ initial="ten">
+
+ <datamodel>
+ <data id="rootdata">
+ <root xmlns="">
+ <one>1</one>
+ <two>2</two>
+ </root>
+ </data>
+ </datamodel>
+
+ <state id="ten">
+
+ <transition event="event.foo" target="twenty" />
+
+ <onexit>
+ <cs:var name="one" expr="Data('number($rootdata/root/one)')" />
+ <cs:var name="two" expr="Data('number($rootdata/root/two)')" />
+ <send id="send123" event="event.bar" namelist="one two" delay="1500" />
+ </onexit>
+
+ </state>
+
+ <state id="twenty">
+ <onentry>
+ <cancel sendid="send123" />
+ </onentry>
+
+ <transition event="event.bar" target="thirty" />
+
+ </state>
+
+ <final id="thirty" />
+
+</scxml>
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml?rev=1672236&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml Thu Apr 9 03:43:19 2015
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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"
+ xmlns:cs="http://commons.apache.org/scxml"
+ version="1.0"
+ datamodel="jexl"
+ initial="ten">
+
+ <datamodel>
+ <data id="rootdata">
+ <root xmlns="">
+ <one>1</one>
+ <two>2</two>
+ </root>
+ </data>
+ </datamodel>
+
+ <state id="ten">
+
+ <transition event="event.foo" target="twenty" />
+
+ <onexit>
+ <cs:var name="one" expr="Data('number($rootdata/root/one)')" />
+ <cs:var name="two" expr="Data('number($rootdata/root/two)')" />
+ <send id="send123" event="event.bar" namelist="one two" delay="1500" />
+ </onexit>
+
+ </state>
+
+ <state id="twenty">
+ <onentry>
+ <cancel sendidexpr="'send123'" />
+ </onentry>
+
+ <transition event="event.bar" target="thirty" />
+
+ </state>
+
+ <final id="thirty" />
+
+</scxml>
Re: svn commit: r1672236 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml2/io/ main/java/org/apache/commons/scxml2/model/
test/java/org/apache/commons/scxml2/model/
Posted by Benedikt Ritter <br...@apache.org>.
2015-04-09 16:43 GMT+02:00 Woonsan Ko <wo...@yahoo.com.invalid>:
> I've just updated the file (including mine and others based on JIRA
> tickets).
> I like it. We can give credits to the contributors in a way. Thanks for
> reminder!
>
Yes, it makes life easier for RMs. We generate the release notes based on
the file with:
mvn changes:announcement-generate -Prelease-notes
Benedikt
>
>
> Cheers,
>
> Woonsan
>
> --------------------------------------------
> On Thu, 4/9/15, Benedikt Ritter <br...@apache.org> wrote:
>
> Subject: Re: svn commit: r1672236 - in /commons/proper/scxml/trunk/src:
> main/java/org/apache/commons/scxml2/io/
> main/java/org/apache/commons/scxml2/model/
> test/java/org/apache/commons/scxml2/model/
> To: "Commons Developers List" <de...@commons.apache.org>
> Date: Thursday, April 9, 2015, 6:00 AM
>
> Hi Woosan,
>
> 2015-04-09 5:43 GMT+02:00
> <wo...@apache.org>:
>
> > Author: woonsan
> > Date: Thu Apr 9 03:43:19 2015
> > New Revision: 1672236
> >
> > URL: http://svn.apache.org/r1672236
> > Log:
> > SCXML-227:
> Applying Michael Goerlich's patch with validating unit
> tests
> >
> > Added:
> >
> >
>
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
> >
> >
>
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
> >
> >
>
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
> > Modified:
> >
> >
>
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
> >
> >
>
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
> >
>
> Don't
> forget to add fixed issues to changes.xml. :-)
>
> Benedikt
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter
Re: svn commit: r1672236 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml2/io/ main/java/org/apache/commons/scxml2/model/ test/java/org/apache/commons/scxml2/model/
Posted by Woonsan Ko <wo...@yahoo.com.INVALID>.
I've just updated the file (including mine and others based on JIRA tickets).
I like it. We can give credits to the contributors in a way. Thanks for reminder!
Cheers,
Woonsan
--------------------------------------------
On Thu, 4/9/15, Benedikt Ritter <br...@apache.org> wrote:
Subject: Re: svn commit: r1672236 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml2/io/ main/java/org/apache/commons/scxml2/model/ test/java/org/apache/commons/scxml2/model/
To: "Commons Developers List" <de...@commons.apache.org>
Date: Thursday, April 9, 2015, 6:00 AM
Hi Woosan,
2015-04-09 5:43 GMT+02:00
<wo...@apache.org>:
> Author: woonsan
> Date: Thu AprĀ 9 03:43:19 2015
> New Revision: 1672236
>
> URL: http://svn.apache.org/r1672236
> Log:
> SCXML-227:
Applying Michael Goerlich's patch with validating unit
tests
>
> Added:
>
>
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
>
>
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
>
>
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
> Modified:
>
>
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
>
>
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
>
Don't
forget to add fixed issues to changes.xml. :-)
Benedikt
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1672236 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml2/io/ main/java/org/apache/commons/scxml2/model/
test/java/org/apache/commons/scxml2/model/
Posted by Benedikt Ritter <br...@apache.org>.
Hi Woosan,
2015-04-09 5:43 GMT+02:00 <wo...@apache.org>:
> Author: woonsan
> Date: Thu Apr 9 03:43:19 2015
> New Revision: 1672236
>
> URL: http://svn.apache.org/r1672236
> Log:
> SCXML-227: Applying Michael Goerlich's patch with validating unit tests
>
> Added:
>
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
>
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
>
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
> Modified:
>
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
>
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
>
Don't forget to add fixed issues to changes.xml. :-)
Benedikt
>
> Modified:
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java?rev=1672236&r1=1672235&r2=1672236&view=diff
>
> ==============================================================================
> ---
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
> (original)
> +++
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
> Thu Apr 9 03:43:19 2015
> @@ -63,9 +63,6 @@ import org.apache.commons.scxml2.model.D
> import org.apache.commons.scxml2.model.Else;
> import org.apache.commons.scxml2.model.ElseIf;
> import org.apache.commons.scxml2.model.EnterableState;
> -import org.apache.commons.scxml2.model.ParamsContainer;
> -import org.apache.commons.scxml2.model.TransitionalState;
> -import org.apache.commons.scxml2.model.Raise;
> import org.apache.commons.scxml2.model.Executable;
> import org.apache.commons.scxml2.model.ExternalContent;
> import org.apache.commons.scxml2.model.Final;
> @@ -82,6 +79,8 @@ import org.apache.commons.scxml2.model.O
> import org.apache.commons.scxml2.model.OnExit;
> import org.apache.commons.scxml2.model.Parallel;
> import org.apache.commons.scxml2.model.Param;
> +import org.apache.commons.scxml2.model.ParamsContainer;
> +import org.apache.commons.scxml2.model.Raise;
> import org.apache.commons.scxml2.model.SCXML;
> import org.apache.commons.scxml2.model.Script;
> import org.apache.commons.scxml2.model.Send;
> @@ -89,6 +88,7 @@ import org.apache.commons.scxml2.model.S
> import org.apache.commons.scxml2.model.State;
> import org.apache.commons.scxml2.model.Transition;
> import org.apache.commons.scxml2.model.TransitionType;
> +import org.apache.commons.scxml2.model.TransitionalState;
> import org.apache.commons.scxml2.model.Var;
> import org.w3c.dom.Attr;
> import org.w3c.dom.Document;
> @@ -294,6 +294,7 @@ public final class SCXMLReader {
> private static final String ATTR_NAMELIST = "namelist";
> private static final String ATTR_PROFILE = "profile";
> private static final String ATTR_SENDID = "sendid";
> + private static final String ATTR_SENDIDEXPR = "sendidexpr";
> private static final String ATTR_SRC = "src";
> private static final String ATTR_SRCEXPR = "srcexpr";
> private static final String ATTR_TARGET = "target";
> @@ -1882,9 +1883,19 @@ public final class SCXMLReader {
> */
> private static void readCancel(final XMLStreamReader reader, final
> Configuration configuration,
> final Executable executable, final
> ActionsContainer parent)
> - throws XMLStreamException {
> + throws XMLStreamException, ModelException {
>
> Cancel cancel = new Cancel();
> + cancel.setSendid(readAV(reader, ATTR_SENDID));
> + String attrValue = readAV(reader, ATTR_SENDIDEXPR);
> + if (attrValue != null) {
> + if (cancel.getSendid() != null) {
> + reportConflictingAttribute(reader, configuration,
> ELEM_CANCEL, ATTR_SENDID, ATTR_SENDIDEXPR);
> + }
> + else {
> + cancel.setSendidexpr(attrValue);
> + }
> + }
> readNamespaces(configuration, cancel);
> cancel.setParent(executable);
> if (parent != null) {
>
> Modified:
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java?rev=1672236&r1=1672235&r2=1672236&view=diff
>
> ==============================================================================
> ---
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
> (original)
> +++
> commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Cancel.java
> Thu Apr 9 03:43:19 2015
> @@ -17,6 +17,8 @@
> package org.apache.commons.scxml2.model;
>
> import org.apache.commons.scxml2.ActionExecutionContext;
> +import org.apache.commons.scxml2.Context;
> +import org.apache.commons.scxml2.Evaluator;
> import org.apache.commons.scxml2.SCXMLExpressionException;
>
> /**
> @@ -44,6 +46,11 @@ public class Cancel extends Action {
> private String sendid;
>
> /**
> + * The expression that evaluates to the ID of the send message that
> should be cancelled.
> + */
> + private String sendidexpr;
> +
> + /**
> * Get the ID of the send message that should be cancelled.
> *
> * @return Returns the sendid.
> @@ -62,11 +69,44 @@ public class Cancel extends Action {
> }
>
> /**
> + * Get the expression that evaluates to the ID of the send message
> that should be cancelled.
> + *
> + * @return the expression that evaluates to the ID of the send
> message that should be cancelled.
> + */
> + public String getSendidexpr() {
> + return sendidexpr;
> + }
> +
> + /**
> + * Set the expression that evaluates to the ID of the send message
> that should be cancelled.
> + *
> + * @param sendidexpr the expression that evaluates to the ID of the
> send message that should be cancelled.
> + */
> + public void setSendidexpr(String sendidexpr) {
> + this.sendidexpr = sendidexpr;
> + }
> +
> + /**
> * {@inheritDoc}
> */
> @Override
> public void execute(ActionExecutionContext exctx) throws
> ModelException, SCXMLExpressionException {
> - exctx.getEventDispatcher().cancel(sendid);
> + EnterableState parentState = getParentEnterableState();
> + Context ctx = exctx.getContext(parentState);
> + ctx.setLocal(getNamespacesKey(), getNamespaces());
> + Evaluator eval = exctx.getEvaluator();
> +
> + String sendidValue = sendid;
> + if (sendidValue == null && sendidexpr != null) {
> + sendidValue = (String)
> getTextContentIfNodeResult(eval.eval(ctx, sendidexpr));
> + if ((sendidValue == null || sendidValue.trim().length() == 0)
> + && exctx.getAppLog().isWarnEnabled()) {
> + exctx.getAppLog().warn("<send>: sendid expression \"" +
> sendidexpr
> + + "\" evaluated to null or empty String");
> + }
> + }
> +
> + exctx.getEventDispatcher().cancel(sendidValue);
> }
> }
>
>
> Added:
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java?rev=1672236&view=auto
>
> ==============================================================================
> ---
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
> (added)
> +++
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/CancelTest.java
> Thu Apr 9 03:43:19 2015
> @@ -0,0 +1,50 @@
> +/*
> + * 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.model;
> +
> +import org.apache.commons.scxml2.SCXMLExecutor;
> +import org.apache.commons.scxml2.SCXMLTestHelper;
> +import org.apache.commons.scxml2.TriggerEvent;
> +import org.apache.commons.scxml2.env.SimpleDispatcher;
> +import org.junit.Test;
> +
> +public class CancelTest {
> +
> + @Test
> + public void testCancelBySendId() throws Exception {
> + final SCXML scxml =
> SCXMLTestHelper.parse("org/apache/commons/scxml2/model/cancel-test-01.xml");
> + final SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml,
> null, new SimpleDispatcher());
> + exec.go();
> + TriggerEvent te = new TriggerEvent("event.foo",
> TriggerEvent.SIGNAL_EVENT);
> + SCXMLTestHelper.fireEvent(exec, te);
> + Thread.sleep(3000);
> + exec.triggerEvents();
> + SCXMLTestHelper.assertState(exec, "twenty");
> + }
> +
> + @Test
> + public void testCancelBySendIdExpr() throws Exception {
> + final SCXML scxml =
> SCXMLTestHelper.parse("org/apache/commons/scxml2/model/cancel-test-02.xml");
> + final SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml,
> null, new SimpleDispatcher());
> + exec.go();
> + TriggerEvent te = new TriggerEvent("event.foo",
> TriggerEvent.SIGNAL_EVENT);
> + SCXMLTestHelper.fireEvent(exec, te);
> + Thread.sleep(3000);
> + exec.triggerEvents();
> + SCXMLTestHelper.assertState(exec, "twenty");
> + }
> +}
>
> Added:
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml?rev=1672236&view=auto
>
> ==============================================================================
> ---
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
> (added)
> +++
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-01.xml
> Thu Apr 9 03:43:19 2015
> @@ -0,0 +1,56 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<!--
> + * 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"
> + xmlns:cs="http://commons.apache.org/scxml"
> + version="1.0"
> + datamodel="jexl"
> + initial="ten">
> +
> + <datamodel>
> + <data id="rootdata">
> + <root xmlns="">
> + <one>1</one>
> + <two>2</two>
> + </root>
> + </data>
> + </datamodel>
> +
> + <state id="ten">
> +
> + <transition event="event.foo" target="twenty" />
> +
> + <onexit>
> + <cs:var name="one" expr="Data('number($rootdata/root/one)')"
> />
> + <cs:var name="two" expr="Data('number($rootdata/root/two)')"
> />
> + <send id="send123" event="event.bar" namelist="one two"
> delay="1500" />
> + </onexit>
> +
> + </state>
> +
> + <state id="twenty">
> + <onentry>
> + <cancel sendid="send123" />
> + </onentry>
> +
> + <transition event="event.bar" target="thirty" />
> +
> + </state>
> +
> + <final id="thirty" />
> +
> +</scxml>
>
> Added:
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml?rev=1672236&view=auto
>
> ==============================================================================
> ---
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
> (added)
> +++
> commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/cancel-test-02.xml
> Thu Apr 9 03:43:19 2015
> @@ -0,0 +1,56 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<!--
> + * 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"
> + xmlns:cs="http://commons.apache.org/scxml"
> + version="1.0"
> + datamodel="jexl"
> + initial="ten">
> +
> + <datamodel>
> + <data id="rootdata">
> + <root xmlns="">
> + <one>1</one>
> + <two>2</two>
> + </root>
> + </data>
> + </datamodel>
> +
> + <state id="ten">
> +
> + <transition event="event.foo" target="twenty" />
> +
> + <onexit>
> + <cs:var name="one" expr="Data('number($rootdata/root/one)')"
> />
> + <cs:var name="two" expr="Data('number($rootdata/root/two)')"
> />
> + <send id="send123" event="event.bar" namelist="one two"
> delay="1500" />
> + </onexit>
> +
> + </state>
> +
> + <state id="twenty">
> + <onentry>
> + <cancel sendidexpr="'send123'" />
> + </onentry>
> +
> + <transition event="event.bar" target="thirty" />
> +
> + </state>
> +
> + <final id="thirty" />
> +
> +</scxml>
>
>
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter