You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2014/03/29 20:45:54 UTC

svn commit: r1583056 - /commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java

Author: ate
Date: Sat Mar 29 19:45:54 2014
New Revision: 1583056

URL: http://svn.apache.org/r1583056
Log:
SCXML-200: adding support for multiple event names specified for a transition

Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java?rev=1583056&r1=1583055&r2=1583056&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java Sat Mar 29 19:45:54 2014
@@ -16,6 +16,13 @@
  */
 package org.apache.commons.scxml2.model;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.commons.scxml2.SCXMLHelper;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * <transition> SCXML element. Transition rules are triggered
@@ -31,11 +38,26 @@ public class Transition extends SimpleTr
     private int order;
 
     /**
-     * Property that specifies the trigger for this transition.
+     * Property that specifies the trigger(s) for this transition.
      */
     private String event;
 
     /**
+     * This transition event descriptors
+     */
+    private List<String> events = Collections.emptyList();
+
+    /**
+     * Indicator for a event-less transition
+     */
+    private boolean noEvents;
+
+    /**
+     * Indicator for a transition matching all events (*)
+     */
+    private boolean allEvents;
+
+    /**
      * Optional guard condition.
      */
     private String cond;
@@ -81,7 +103,7 @@ public class Transition extends SimpleTr
      * @param cond The cond to set.
      */
     public void setCond(final String cond) {
-        this.cond = cond;
+        this.cond = SCXMLHelper.isStringEmpty(cond) ? null : cond;
     }
 
     /**
@@ -101,7 +123,56 @@ public class Transition extends SimpleTr
      * @param event The event to set.
      */
     public void setEvent(final String event) {
-        this.event = event;
+        this.event = SCXMLHelper.isStringEmpty(event) ? null : event.trim();
+        if (this.event != null) {
+            // 'event' is a space separated list of event descriptors
+            events = new ArrayList<String>();
+            StringTokenizer st = new StringTokenizer(this.event);
+            while (st.hasMoreTokens()) {
+                String token = st.nextToken();
+                if (token.equals("*")) {
+                    events.clear();
+                    events.add(token);
+                    break;
+                }
+                else {
+                    if (token.endsWith("*")) {
+                        token = token.substring(0, token.length()-1);
+                    }
+                    if (token.endsWith(".")) {
+                        token = token.substring(0, token.length()-1);
+                    }
+                    if (token.length() > 0) {
+                        events.add(token);
+                    }
+                }
+            }
+        }
+        else {
+            events = Collections.emptyList();
+        }
+        noEvents = events.isEmpty();
+        allEvents = !noEvents && events.get(0).equals("*");
+    }
+
+    /**
+     * @return The list of this transition event descriptors
+     */
+    public final List<String> getEvents() {
+        return events;
     }
-}
 
+    /**
+     * @return True if this transition is event-less
+     */
+    public final boolean isNoEventsTransition() {
+        return noEvents;
+    }
+
+    /**
+     * @return True if this transition matches any events (*)
+     */
+    public final boolean isAllEventsTransition() {
+        return allEvents;
+    }
+}