Author: rahul
Date: Wed May 28 14:00:09 2008
New Revision: 661081
URL: http://svn.apache.org/viewvc?rev=661081&view=rev
Log:
Support for <transition> children for <parallel> states.
* Move transitions bookkeeping from State to TransitionTarget.
* Remove deprecated State#getTransitions()
* Remove (recently deprecated in 0.x branch aka trunk) Path#getScope() in
favor of Path#getPathScope()
* Adjust io and semantics packages accordingly.
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Path.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/State.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java?rev=661081&r1=661080&r2=661081&view=diff
==============================================================================
---
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
(original)
+++
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
Wed May 28 14:00:09 2008
@@ -214,6 +214,9 @@
for (TransitionTarget tt : p.getChildren()) {
updateState((State) tt, targets);
}
+ for (Transition trn : p.getTransitionsList()) {
+ updateTransition(trn, targets);
+ }
}
/**
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=661081&r1=661080&r2=661081&view=diff
==============================================================================
---
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
(original)
+++
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
Wed May 28 14:00:09 2008
@@ -790,6 +790,8 @@
addSimpleRulesTuple(xp, scxmlRules, Parallel.class, null, null,
"addChild");
addDatamodelRules(xp + XPF_DM, scxmlRules, scxml, pr);
+ addTransitionRules(xp + XPF_TR, scxmlRules, "addTransition",
+ pr, customActions);
addHandlerRules(xp, scxmlRules, pr, customActions);
scxmlRules.add(xp, new UpdateModelRule(scxml));
}
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Path.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Path.java?rev=661081&r1=661080&r2=661081&view=diff
==============================================================================
---
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Path.java
(original)
+++
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Path.java
Wed May 28 14:00:09 2008
@@ -51,10 +51,10 @@
private List<TransitionTarget> downSeg = new ArrayList<TransitionTarget>();
/**
- * "Lowest" state which is not being exited nor entered by
- * the transition.
+ * "Lowest" transition target which is not being exited nor
+ * entered by the transition.
*/
- private State scope = null;
+ private TransitionTarget scope = null;
/**
* Whether the path crosses region border(s).
@@ -70,18 +70,14 @@
Path(final TransitionTarget source, final TransitionTarget target) {
if (target == null) {
//a local "stay" transition
- scope = (State) source;
+ scope = source;
//all segments remain empty
} else {
TransitionTarget tt = SCXMLHelper.getLCA(source, target);
if (tt != null) {
- if (tt instanceof State) {
- scope = (State) tt;
- } else {
- scope = tt.getParentState();
- }
+ scope = tt;
if (scope == source || scope == target) {
- scope = scope.getParentState();
+ scope = scope.getParent();
}
}
tt = source;
@@ -160,14 +156,14 @@
}
/**
- * Get the farthest state from root which is not being exited
+ * Get the farthest transition target from root which is not being exited
* nor entered by the transition (null if scope is document root).
*
- * @return State scope of the transition path, null means global transition
- * (SCXML document level) Scope is the least state which is not
- * being exited nor entered by the transition.
+ * @return Scope of the transition path, null means global transition
+ * (SCXML document level). Scope is the least transition target
+ * which is not being exited nor entered by the transition.
*/
- public final State getScope() {
+ public final TransitionTarget getPathScope() {
return scope;
}
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/State.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/State.java?rev=661081&r1=661080&r2=661081&view=diff
==============================================================================
---
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/State.java
(original)
+++
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/State.java
Wed May 28 14:00:09 2008
@@ -16,10 +16,7 @@
*/
package org.apache.commons.scxml.model;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -70,11 +67,6 @@
private Initial initial;
/**
- * A list of outgoing Transitions from this state, by document order.
- */
- private List<Transition> transitions;
-
- /**
* Applies to composite states only. If one of its final children is
* active, its parent is marked done. This property is reset upon
* re-entry.
@@ -88,7 +80,6 @@
*/
public State() {
this.children = new LinkedHashMap<String, TransitionTarget>();
- this.transitions = new ArrayList<Transition>();
}
/**
@@ -200,60 +191,6 @@
}
/**
- * Get the map of all outgoing transitions from this state.
- *
- * @return Map Returns the transitions Map.
- * @deprecated Use [EMAIL PROTECTED] #getTransitionsList()} instead
- */
- public final Map<String, List<Transition>> getTransitions() {
- Map<String, List<Transition>> transitionsMap = new HashMap<String,
List<Transition>>();
- for (Transition transition : transitions) {
- String event = transition.getEvent();
- if (!transitionsMap.containsKey(event)) {
- List<Transition> eventTransitions = new
ArrayList<Transition>();
- eventTransitions.add(transition);
- transitionsMap.put(event, eventTransitions);
- } else {
- transitionsMap.get(event).add(transition);
- }
- }
- return transitionsMap;
- }
-
- /**
- * Get the list of all outgoing transitions from this state, that
- * will be candidates for being fired on the given event.
- *
- * @param event The event
- * @return List Returns the candidate transitions for given event
- */
- public final List<Transition> getTransitionsList(final String event) {
- List<Transition> matchingTransitions = null; // since we returned null
upto v0.6
- for (Transition t : transitions) {
- if ((event == null && t.getEvent() == null)
- || (event != null && event.equals(t.getEvent()))) {
- if (matchingTransitions == null) {
- matchingTransitions = new ArrayList<Transition>();
- }
- matchingTransitions.add(t);
- }
- }
- return matchingTransitions;
- }
-
- /**
- * Add a transition to the map of all outgoing transitions for
- * this state.
- *
- * @param transition
- * The transitions to set.
- */
- public final void addTransition(final Transition transition) {
- transitions.add(transition);
- transition.setParent(this);
- }
-
- /**
* Get the map of child states (may be empty).
*
* @return Map Returns the children.
@@ -289,15 +226,6 @@
}
/**
- * Get the outgoing transitions for this state as a java.util.List.
- *
- * @return List Returns the transitions list.
- */
- public final List<Transition> getTransitionsList() {
- return transitions;
- }
-
- /**
* Check whether this is a simple (leaf) state (UML terminology).
*
* @return true if this is a simple state, otherwise false
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java?rev=661081&r1=661080&r2=661081&view=diff
==============================================================================
---
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
(original)
+++
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
Wed May 28 14:00:09 2008
@@ -51,6 +51,11 @@
private Datamodel datamodel;
/**
+ * A list of outgoing Transitions from this state, by document order.
+ */
+ private List<Transition> transitions;
+
+ /**
* The parent of this transition target (may be null, if the parent
* is the SCXML document root).
*/
@@ -71,6 +76,7 @@
onEntry.setParent(this);
onExit = new OnExit(); //empty defaults
onExit.setParent(this);
+ transitions = new ArrayList<Transition>();
parent = null;
history = new ArrayList<History>();
}
@@ -150,6 +156,48 @@
}
/**
+ * Get the list of all outgoing transitions from this state, that
+ * will be candidates for being fired on the given event.
+ *
+ * @param event The event
+ * @return List Returns the candidate transitions for given event
+ */
+ public final List<Transition> getTransitionsList(final String event) {
+ List<Transition> matchingTransitions = null; // since we returned null
upto v0.6
+ for (Transition t : transitions) {
+ if ((event == null && t.getEvent() == null)
+ || (event != null && event.equals(t.getEvent()))) {
+ if (matchingTransitions == null) {
+ matchingTransitions = new ArrayList<Transition>();
+ }
+ matchingTransitions.add(t);
+ }
+ }
+ return matchingTransitions;
+ }
+
+ /**
+ * Add a transition to the map of all outgoing transitions for
+ * this state.
+ *
+ * @param transition
+ * The transitions to set.
+ */
+ public final void addTransition(final Transition transition) {
+ transitions.add(transition);
+ transition.setParent(this);
+ }
+
+ /**
+ * Get the outgoing transitions for this state as a java.util.List.
+ *
+ * @return List Returns the transitions list.
+ */
+ public final List<Transition> getTransitionsList() {
+ return transitions;
+ }
+
+ /**
* Get the parent TransitionTarget.
*
* @return Returns the parent state
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=661081&r1=661080&r2=661081&view=diff
==============================================================================
---
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
(original)
+++
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
Wed May 28 14:00:09 2008
@@ -274,11 +274,8 @@
te = new TriggerEvent(p.getId() + ".done",
TriggerEvent.CHANGE_EVENT);
internalEvents.add(te);
- te = new TriggerEvent(p.getParent().getId()
- + ".done", TriggerEvent.CHANGE_EVENT);
- internalEvents.add(te);
//this is not in the specs, but is makes sense
- scInstance.setDone(p.getParentState(), true);
+ scInstance.setDone(p, true);
}
}
}
@@ -304,14 +301,14 @@
// breath-first search to-do list
LinkedList<TransitionTarget> todoList = new
LinkedList<TransitionTarget>(stateSet);
while (!todoList.isEmpty()) {
- State st = (State) todoList.removeFirst();
- for (Transition t : st.getTransitionsList()) {
+ TransitionTarget tt = todoList.removeFirst();
+ for (Transition t : tt.getTransitionsList()) {
if (!transSet.contains(t)) {
transSet.add(t);
step.getTransitList().add(t);
}
}
- State parent = st.getParentState();
+ TransitionTarget parent = tt.getParent();
if (parent != null && !stateSet.contains(parent)) {
stateSet.add(parent);
todoList.addLast(parent);