commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r601639 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java test/java/org/apache/commons/scxml/WildcardTest.java test/java/org/apache/commons/scxml/env/jexl/wildcard-01.xml
Date Thu, 06 Dec 2007 07:30:34 GMT
Author: rahul
Date: Wed Dec  5 23:30:32 2007
New Revision: 601639

URL: http://svn.apache.org/viewvc?rev=601639&view=rev
Log:
SCXML-53 Wild card event name handling on transitions is not in line with WD

Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/WildcardTest.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wildcard-01.xml

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=601639&r1=601638&r2=601639&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
Wed Dec  5 23:30:32 2007
@@ -348,17 +348,8 @@
          */
         Set allEvents = new HashSet(step.getBeforeStatus().getEvents().size()
             + step.getExternalEvents().size());
-        //for now, we only match against event names
-        for (Iterator ei = step.getBeforeStatus().getEvents().iterator();
-                ei.hasNext();) {
-            TriggerEvent te = (TriggerEvent) ei.next();
-            allEvents.add(te.getName());
-        }
-        for (Iterator ei = step.getExternalEvents().iterator();
-                ei.hasNext();) {
-            TriggerEvent te = (TriggerEvent) ei.next();
-            allEvents.add(te.getName());
-        }
+        allEvents.addAll(step.getBeforeStatus().getEvents());
+        allEvents.addAll(step.getExternalEvents());
         // Finalize invokes, if applicable
         for (Iterator iter = scInstance.getInvokers().keySet().iterator();
                 iter.hasNext();) {
@@ -724,16 +715,13 @@
     public void processInvokes(final TriggerEvent[] events,
             final ErrorReporter errRep, final SCInstance scInstance)
     throws ModelException {
-        Set eventNames = new HashSet();
-        //for now, we only match against event names
-        for (int i = 0; i < events.length; i++) {
-            eventNames.add(events[i].getName());
-        }
+        Set allEvents = new HashSet();
+        allEvents.addAll(Arrays.asList(events));
         for (Iterator invokeIter = scInstance.getInvokers().entrySet().
                 iterator(); invokeIter.hasNext();) {
             Map.Entry iEntry = (Map.Entry) invokeIter.next();
             String parentId = ((TransitionTarget) iEntry.getKey()).getId();
-            if (!finalizeMatch(parentId, eventNames)) { // prevent cycles
+            if (!finalizeMatch(parentId, allEvents)) { // prevent cycles
                 Invoker inv = (Invoker) iEntry.getValue();
                 try {
                     inv.parentEvents(events);
@@ -840,20 +828,27 @@
      */
     protected boolean eventMatch(final String transEvent,
             final Set eventOccurrences) {
-        if (SCXMLHelper.isStringEmpty(transEvent)) {
+        if (SCXMLHelper.isStringEmpty(transEvent)) { // Eventless transition
             return true;
         } else {
-            String transEventDot = transEvent + "."; // prefix event support
+            String trimTransEvent = transEvent.trim();
             Iterator i = eventOccurrences.iterator();
             while (i.hasNext()) {
-                String evt = (String) i.next();
-                if (evt == null) {
+                TriggerEvent te = (TriggerEvent) i.next();
+                String event = te.getName();
+                if (event == null) {
                     continue; // Unnamed events
-                } else if (evt.equals("*")) {
-                    return true; // Wildcard
-                } else if (evt.equals(transEvent)
-                            || evt.startsWith(transEventDot)) {
-                    return true;
+                }
+                String trimEvent = event.trim();
+                if (trimEvent.equals(trimTransEvent)) {
+                    return true; // Match
+                } else if (te.getType() != TriggerEvent.CHANGE_EVENT
+                        && trimTransEvent.equals("*")) {
+                    return true; // Wildcard, skip gen'ed ones like .done etc.
+                } else if (trimTransEvent.endsWith(".*")
+                        && trimEvent.startsWith(trimTransEvent.substring(0,
+                                trimTransEvent.length()-1))) {
+                    return true; // Prefixed wildcard
                 }
             }
             return false;
@@ -875,10 +870,10 @@
         String prefix = parentStateId + ".invoke."; // invoke prefix
         Iterator i = eventOccurrences.iterator();
         while (i.hasNext()) {
-            String evt = (String) i.next();
+            String evt = ((TriggerEvent) i.next()).getName();
             if (evt == null) {
                 continue; // Unnamed events
-            } else if (evt.startsWith(prefix)) {
+            } else if (evt.trim().startsWith(prefix)) {
                 return true;
             }
         }

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/WildcardTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/WildcardTest.java?rev=601639&r1=601638&r2=601639&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/WildcardTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/WildcardTest.java Wed
Dec  5 23:30:32 2007
@@ -75,7 +75,7 @@
             assertEquals("state1", ((State)currentStates.iterator().
                 next()).getId());
             exec = SCXMLTestHelper.testExecutorSerializability(exec);
-            currentStates = SCXMLTestHelper.fireEvent(exec, "*");
+            currentStates = SCXMLTestHelper.fireEvent(exec, "foo.bar.baz");
             assertEquals(1, currentStates.size());
             assertEquals("state4", ((State)currentStates.iterator().
                 next()).getId());

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wildcard-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wildcard-01.xml?rev=601639&r1=601638&r2=601639&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wildcard-01.xml
(original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wildcard-01.xml
Wed Dec  5 23:30:32 2007
@@ -22,11 +22,11 @@
            <onentry>
                <var name="switch" expr="4" />
            </onentry>
-           <!-- We'll match all the events using a wildcard (*),
+           <!-- We'll trigger 'foo.bar.baz' event,
                 and therefore, must end up in state4 -->
-           <transition event="foo.bar" cond="switch eq 2" target="state2"/>
-           <transition event="err.foo" cond="switch eq 3" target="state3"/>
-           <transition event="done.it" cond="switch eq 4" target="state4"/>
+           <transition event="*" cond="switch eq 2" target="state2"/>
+           <transition event="foo.*" cond="switch eq 3" target="state3"/>
+           <transition event="foo.bar.*" cond="switch eq 4" target="state4"/>
      </state>
      <state id="state2" final="true"/>
      <state id="state3" final="true"/>



Mime
View raw message