Author: rahul
Date: Wed Dec 13 13:49:37 2006
New Revision: 486849

URL: http://svn.apache.org/viewvc?view=rev&rev=486849
Log:
Evaluate target and targettype attributes of <send> as expressions. Thanks to 
Sitthichai Rernglertpricha.
SCXML-16

Modified:
    
jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
    
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
    
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-01.xml
    
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml

Modified: 
jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java?view=diff&rev=486849&r1=486848&r2=486849
==============================================================================
--- 
jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
 (original)
+++ 
jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Send.java
 Wed Dec 13 13:49:37 2006
@@ -116,7 +116,6 @@
     public Send() {
         super();
         this.externalNodes = new ArrayList();
-        this.targettype = TARGETTYPE_SCXML;
     }
 
     /**
@@ -275,10 +274,33 @@
         Context ctx = scInstance.getContext(parentState);
         ctx.setLocal(getNamespacesKey(), getNamespaces());
         Evaluator eval = scInstance.getEvaluator();
+        // Most attributes of <send> are expressions so need to be
+        // evaluated before the EventDispatcher callback
         Object hintsValue = null;
         if (!SCXMLHelper.isStringEmpty(hints)) {
             hintsValue = eval.eval(ctx, hints);
         }
+        String targetValue = target;
+        if (!SCXMLHelper.isStringEmpty(target)) {
+            targetValue = (String) eval.eval(ctx, target);
+            if (SCXMLHelper.isStringEmpty(targetValue)
+                    && appLog.isWarnEnabled()) {
+                appLog.warn("<send>: target expression \"" + target
+                    + "\" evaluated to null or empty String");
+            }
+        }
+        String targettypeValue = targettype;
+        if (!SCXMLHelper.isStringEmpty(targettype)) {
+            targettypeValue = (String) eval.eval(ctx, targettype);
+            if (SCXMLHelper.isStringEmpty(targettypeValue)
+                    && appLog.isWarnEnabled()) {
+                appLog.warn("<send>: targettype expression \"" + targettype
+                    + "\" evaluated to null or empty String");
+            }
+        } else {
+            // must default to 'scxml' when unspecified
+            targettypeValue = TARGETTYPE_SCXML;
+        }
         Map params = null;
         if (!SCXMLHelper.isStringEmpty(namelist)) {
             StringTokenizer tkn = new StringTokenizer(namelist);
@@ -296,9 +318,9 @@
         }
         long wait = parseDelay(appLog);
         // Lets see if we should handle it ourselves
-        if (SCXMLHelper.isStringEmpty(targettype)
-                || targettype.trim().equalsIgnoreCase(TARGETTYPE_SCXML)) {
-            if (SCXMLHelper.isStringEmpty(target)) {
+        if (targettypeValue != null
+              && targettypeValue.trim().equalsIgnoreCase(TARGETTYPE_SCXML)) {
+            if (SCXMLHelper.isStringEmpty(targetValue)) {
                 // TODO: Remove both short-circuit passes in v1.0
                 if (wait == 0L) {
                     derivedEvents.add(new TriggerEvent(event,
@@ -317,8 +339,8 @@
         }
         ctx.setLocal(getNamespacesKey(), null);
         // Else, let the EventDispatcher take care of it
-        evtDispatcher.send(sendid, target, targettype, event, params,
-            hintsValue, wait, externalNodes);
+        evtDispatcher.send(sendid, targetValue, targettypeValue, event,
+            params, hintsValue, wait, externalNodes);
     }
 
     /**

Modified: 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml?view=diff&rev=486849&r1=486848&r2=486849
==============================================================================
--- 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
 (original)
+++ 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
 Wed Dec 13 13:49:37 2006
@@ -38,7 +38,7 @@
                       EventDispatcher implementation. See
                       testWizard02Sample() in WizardsTest
                       (org.apache.commons.scxml test package) -->
-                 <send namelist="aValue" targettype="foo" />
+                 <send namelist="aValue" targettype="'foo'" />
            </onentry>
            <transition event="event1" target="state1"/>
            <transition event="event3" target="state3"/>
@@ -47,7 +47,7 @@
      <state id="state3">
            <onentry>
                  <var name="aValue" expr="3"/>
-                 <send namelist="aValue" targettype="foo" />
+                 <send namelist="aValue" targettype="'foo'" />
            </onentry>
            <transition event="event1" target="state1"/>
            <transition event="event2" target="state2"/>
@@ -56,7 +56,7 @@
      <state id="state4">
            <onentry>
                  <var name="aValue" expr="4"/>
-                 <send namelist="aValue" targettype="foo" />
+                 <send namelist="aValue" targettype="'foo'" />
            </onentry>
            <transition event="event1" target="state1"/>
            <transition event="event2" target="state2"/>

Modified: 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-01.xml
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-01.xml?view=diff&rev=486849&r1=486848&r2=486849
==============================================================================
--- 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-01.xml
 (original)
+++ 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-01.xml
 Wed Dec 13 13:49:37 2006
@@ -22,7 +22,7 @@
     <state id="ten">
         <transition event="ten.done" target="twenty">
             <send sendid="send1" delay="0"
-             target="http://localhost:8080/VXMLInterpreter"; targettype="v3"
+             target="'http://localhost:8080/VXMLInterpreter'" targettype="'v3'"
              xmlns:v3="http://foo.bar.com/vxml3";
              xmlns:test="http://my.test.namespace";>
                 <v3:form id="Confirm">

Modified: 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml?view=diff&rev=486849&r1=486848&r2=486849
==============================================================================
--- 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml
 (original)
+++ 
jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/send-02.xml
 Wed Dec 13 13:49:37 2006
@@ -32,42 +32,42 @@
 
     <state id="twenty">
         <onentry>
-            <send event="twenty.done" targettype="scxml" />
+            <send event="twenty.done" targettype="'scxml'" />
         </onentry>
         <transition event="twenty.done" target="thirty" />
     </state>
 
     <state id="thirty">
         <onentry>
-            <send event="thirty.done" targettype=" sCxML  " />
+            <send event="thirty.done" targettype="' sCxML  '" />
         </onentry>
         <transition event="thirty.done" target="forty" />
     </state>
 
     <state id="forty">
         <onentry>
-            <send event="forty.done" target="" />
+            <send event="forty.done" targettype=" " target=" " />
         </onentry>
         <transition event="forty.done" target="fifty" />
     </state>
 
     <state id="fifty">
         <onentry>
-            <send event="fifty.done" target="   " />
+            <send event="fifty.done" target="'  '" />
         </onentry>
         <transition event="fifty.done" target="sixty" />
     </state>
 
     <state id="sixty">
         <onentry>
-            <send event="sixty.done" targettype="scxml" target=" " />
+            <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" />
+            <send event="seventy.done" targettype="'scxml'" target="'foo'" />
         </onentry>
 
         <!-- This transition should not be followed since



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to