Author: rahul Date: Fri Mar 24 16:01:58 2006 New Revision: 388680 URL: http://svn.apache.org/viewcvs?rev=388680&view=rev Log: * Correct behavior (short-circuit EventDispatcher, raise derived event) for the <send> element for special case when: - targettype is "scxml" - target is empty
* Define a new event type for internally raised error events. State machines can watch for these events and display error recovery behaviors. * Add a test case that demonstrates this <send> usage. The state machine in this test case effectively runs itself (without external events) since all events are internally raised via the <send> usage mentioned above. * Also corrected typos in actions-test.xml Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml (with props) Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLExecutorTest.java jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java?rev=388680&r1=388679&r2=388680&view=diff ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java (original) +++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java Fri Mar 24 16:01:58 2006 @@ -1,6 +1,6 @@ /* * - * Copyright 2005 The Apache Software Foundation. + * Copyright 2005-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +71,12 @@ * */ public static final int TIME_EVENT = 4; + + /** + * <code>ERROR_EVENT</code>. + * + */ + public static final int ERROR_EVENT = 5; /** * The event name. Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java?rev=388680&r1=388679&r2=388680&view=diff ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java (original) +++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java Fri Mar 24 16:01:58 2006 @@ -1,6 +1,6 @@ /* * - * Copyright 2005 The Apache Software Foundation. + * Copyright 2005-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.apache.commons.scxml.SCInstance; import org.apache.commons.scxml.SCXMLExpressionException; import org.apache.commons.scxml.SCXMLHelper; +import org.apache.commons.scxml.TriggerEvent; /** * The class in this SCXML object model that corresponds to the @@ -41,6 +42,18 @@ public class Send extends Action implements ExternalContent { /** + * The default targettype. + */ + private static final String TARGETTYPE_SCXML = "scxml"; + + /** + * The spec mandated derived event when target cannot be reached + * for TARGETTYPE_SCXML. + */ + private static final String EVENT_ERR_SEND_TARGETUNAVAILABLE = + "error.send.targetunavailable"; + + /** * The ID of the send message. */ private String sendid; @@ -98,6 +111,7 @@ public Send() { super(); this.externalNodes = new ArrayList(); + this.targettype = TARGETTYPE_SCXML; } /** @@ -251,6 +265,23 @@ final ErrorReporter errRep, final SCInstance scInstance, final Log appLog, final Collection derivedEvents) throws ModelException, SCXMLExpressionException { + // Lets see if we should handle it ourselves + if (targettype != null && targettype.trim().toLowerCase(). + equals(TARGETTYPE_SCXML)) { + if (SCXMLHelper.isStringEmpty(target)) { + derivedEvents.add(new TriggerEvent(event, + TriggerEvent.SIGNAL_EVENT)); + } else { + // We know of no other + appLog.warn("<send>: Unavailable target - " + target); + derivedEvents.add(new TriggerEvent( + EVENT_ERR_SEND_TARGETUNAVAILABLE, + TriggerEvent.ERROR_EVENT)); + } + // short-circuit the EventDispatcher + return; + } + // Else, let the EventDispatcher take care of it State parentState = getParentState(); Context ctx = scInstance.getContext(parentState); Evaluator eval = scInstance.getEvaluator(); Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLExecutorTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLExecutorTest.java?rev=388680&r1=388679&r2=388680&view=diff ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLExecutorTest.java (original) +++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLExecutorTest.java Fri Mar 24 16:01:58 2006 @@ -46,7 +46,7 @@ // Test data private URL microwave01jsp, microwave02jsp, microwave01jexl, - microwave02jexl, transitions01; + microwave02jexl, transitions01, send02; private SCXMLExecutor exec; /** @@ -63,6 +63,8 @@ getResource("org/apache/commons/scxml/env/jexl/microwave-02.xml"); transitions01 = this.getClass().getClassLoader(). getResource("org/apache/commons/scxml/transitions-01.xml"); + send02 = this.getClass().getClassLoader(). + getResource("org/apache/commons/scxml/send-02.xml"); } /** @@ -70,7 +72,7 @@ */ public void tearDown() { microwave01jsp = microwave02jsp = microwave01jexl = microwave02jexl = - transitions01 = null; + transitions01 = send02 = null; } /** @@ -116,6 +118,19 @@ next()).getId()); currentStates = fireEvent("twenty_two.done"); assertEquals(3, exec.getCurrentStatus().getStates().size()); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + public void testSendTargettypeSCXMLSample() { + exec = SCXMLTestHelper.getExecutor(send02); + assertNotNull(exec); + try { + Set currentStates = exec.getCurrentStatus().getStates(); + assertEquals(1, currentStates.size()); + assertEquals("ninety", ((State)currentStates.iterator(). + next()).getId()); } catch (Exception e) { fail(e.getMessage()); } Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml?rev=388680&r1=388679&r2=388680&view=diff ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml (original) +++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/actions-test.xml Fri Mar 24 16:01:58 2006 @@ -31,7 +31,7 @@ </if> <var name="drink" expr="water" /> <var name="eat" expr="flies" /> - <send sendId="send12345" target="freddy" targetType="frog" + <send sendid="send12345" target="freddy" targettype="frog" event="croak" namelist="drink eat" hints="h2o bzz" delay="1000" /> <cancel sendId="send12345"/> Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml?rev=388680&view=auto ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml (added) +++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml Fri Mar 24 16:01:58 2006 @@ -0,0 +1,89 @@ +<?xml version="1.0"?> +<!-- + Copyright 2006 The Apache Software Foundation + + Licensed 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. +--> +<!-- Various send usages that fire the events on the existing execution + engine. --> +<scxml xmlns="http://www.w3.org/2005/07/SCXML" + version="1.0" + initialstate="ten"> + + <!-- We are expected to just fall all the way through down to + the state "seventy", then hop over and end up in "ninety" --> + <state id="ten"> + <onentry> + <send event="ten.done" /> + </onentry> + <transition event="ten.done" target="twenty" /> + </state> + + <state id="twenty"> + <onentry> + <send event="twenty.done" targettype="scxml" /> + </onentry> + <transition event="twenty.done" target="thirty" /> + </state> + + <state id="thirty"> + <onentry> + <send event="thirty.done" targettype=" sCxML " /> + </onentry> + <transition event="thirty.done" target="forty" /> + </state> + + <state id="forty"> + <onentry> + <send event="forty.done" target="" /> + </onentry> + <transition event="forty.done" target="fifty" /> + </state> + + <state id="fifty"> + <onentry> + <send event="fifty.done" target=" " /> + </onentry> + <transition event="fifty.done" target="sixty" /> + </state> + + <state id="sixty"> + <onentry> + <send event="sixty.done" targettype="scxml" target=" " /> + </onentry> + <transition event="sixty.done" target="seventy" /> + </state> + + <state id="seventy"> + <onentry> + <send event="seventy.done" targettype="scxml" target="foo" /> + </onentry> + + <!-- This transition should not be followed since + target "foo" is unavailable (any target other + than an empty target is unavailable, empty target + is current execution i.e. this state machine) --> + <transition event="seventy.done" target="eighty" /> + + <!-- Since "foo" it not available, the event + "error.send.targetunavailable" should be raised --> + <transition event="error.send.targetunavailable" target="ninety" /> + + </state> + + <state id="eighty" final="true" /> + + <state id="ninety" final="true" /> + +</scxml> + Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]