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/18 02:54:02 UTC
svn commit: r1578711 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml2/io/
main/java/org/apache/commons/scxml2/model/
main/java/org/apache/commons/scxml2/semantics/
test/java/org/apache/commons/scxml2/io/ test/java/org/apache/co...
Author: ate
Date: Tue Mar 18 01:54:02 2014
New Revision: 1578711
URL: http://svn.apache.org/r1578711
Log:
SCXML-199: map the <scxml> initial attribute to an initial Transition to support multiple target states, conforming to the SCXML specification
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Path.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/SCXML.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/ErrorConstants.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/SCXMLSemanticsImpl.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ScxmlInitialAttributeTest.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java Tue Mar 18 01:54:02 2014
@@ -159,25 +159,25 @@ final class ModelUpdater {
*/
static void updateSCXML(final SCXML scxml) throws ModelException {
String initial = scxml.getInitial();
- TransitionTarget initialTarget = null;
+ Transition initialTransition = new Transition();
if (initial != null) {
- //we have to use getTargets() here since the initialTarget can be
- //an indirect descendant
- // TODO: initial may specify multiple targets (like it may for any state, see also State#first)
- initialTarget = scxml.getTargets().get(initial);
- if (initialTarget == null) {
- // Where do we, where do we go?
+
+ initialTransition.setNext(scxml.getInitial());
+ updateTransition(initialTransition, scxml.getTargets());
+
+ if (initialTransition.getTargets().size() == 0) {
logAndThrowModelError(ERR_SCXML_NO_INIT, new Object[] {
initial });
}
} else {
// If 'initial' is not specified, the default initial state is
// the first child state in document order.
- initialTarget = scxml.getFirstChild();
+ initialTransition.getTargets().add(scxml.getFirstChild());
+ initialTransition.getPaths(); // init paths
}
- scxml.setInitialTarget(initialTarget);
+ scxml.setInitialTransition(initialTransition);
Map<String, TransitionTarget> targets = scxml.getTargets();
Map<String, TransitionTarget> children = scxml.getChildren();
for (TransitionTarget tt : children.values()) {
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Path.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Path.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Path.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Path.java Tue Mar 18 01:54:02 2014
@@ -32,6 +32,8 @@ import org.apache.commons.scxml2.SCXMLHe
* the least common ancestor and a "down segment" that traces
* down to the target of the Transition.
*
+ * For an initial transition, the TransitionTarget source is null and
+ * the "up segment" will be empty and the scope null.
*/
public class Path implements Serializable {
@@ -73,7 +75,7 @@ public class Path implements Serializabl
scope = source;
//all segments remain empty
} else {
- TransitionTarget tt = SCXMLHelper.getLCA(source, target);
+ TransitionTarget tt = source != null ? SCXMLHelper.getLCA(source, target) : null;
if (tt != null) {
scope = tt;
if (scope == source || scope == target) {
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/SCXML.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/SCXML.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/SCXML.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/SCXML.java Tue Mar 18 01:54:02 2014
@@ -54,9 +54,9 @@ public class SCXML implements Serializab
private String version;
/**
- * The initial TransitionTarget for the SCXML executor.
+ * The initial Transition for the SCXML executor.
*/
- private TransitionTarget initialTarget;
+ private Transition initialTransition;
/**
* The initial transition target ID (used by XML Digester only).
@@ -124,25 +124,26 @@ public class SCXML implements Serializab
}
/**
- * Get the initial TransitionTarget.
+ * Get the initial Transition.
*
- * @return Returns the initial target for this state machine.
+ * @return Returns the initial transition for this state machine.
*
- * @since 0.7
+ * @since 2.0
*/
- public final TransitionTarget getInitialTarget() {
- return initialTarget;
+ public final Transition getInitialTransition() {
+ return initialTransition;
}
/**
- * Set the initial TransitionTarget.
+ * Set the initial Transition.
+ * <p>Note: the initial transition can/may not have executable content!</p>
*
- * @param initialTarget The initial target to set.
+ * @param initialTransition The initial transition to set.
*
- * @since 0.7
+ * @since 2.0
*/
- public final void setInitialTarget(final TransitionTarget initialTarget) {
- this.initialTarget = initialTarget;
+ public final void setInitialTransition(final Transition initialTransition) {
+ this.initialTransition = initialTransition;
}
/**
@@ -280,22 +281,20 @@ public class SCXML implements Serializab
}
/**
- * Get the ID of the initial transition target.
+ * Get the the initial transition target.
*
* @return String Returns the initial transition target ID
- * (used by XML Digester only).
- * @see #getInitialTarget()
+ * @see #getInitialTransition()
*/
public final String getInitial() {
return initial;
}
/**
- * Set the ID of the initial transition target.
+ * Set the initial transition target.
*
- * @param initial The initial transition target ID
- * (used by XML Digester only).
- * @see #setInitialTarget(TransitionTarget)
+ * @param initial The initial transition target
+ * @see #setInitialTransition(Transition)
*/
public final void setInitial(final String initial) {
this.initial = initial;
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/ErrorConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/ErrorConstants.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/ErrorConstants.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/ErrorConstants.java Tue Mar 18 01:54:02 2014
@@ -25,7 +25,7 @@ public class ErrorConstants {
/**
* Missing initial state for a composite state or for the scxml root.
*
- * @see org.apache.commons.scxml2.model.SCXML#getInitialTarget()
+ * @see org.apache.commons.scxml2.model.SCXML#getInitialTransition()
* @see org.apache.commons.scxml2.model.State#getInitial()
*/
public static final String NO_INITIAL = "NO_INITIAL";
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/SCXMLSemanticsImpl.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/SCXMLSemanticsImpl.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/semantics/SCXMLSemanticsImpl.java Tue Mar 18 01:54:02 2014
@@ -338,13 +338,13 @@ public class SCXMLSemanticsImpl implemen
public void determineInitialStates(final Step step, final SCXML stateMachine, final ErrorReporter errRep,
final SCInstance scInstance)
throws ModelException {
- TransitionTarget tmp = stateMachine.getInitialTarget();
- if (tmp == null) {
+ Transition t = stateMachine.getInitialTransition();
+ if (t == null) {
errRep.onError(ErrorConstants.NO_INITIAL,
"SCXML initialstate is missing!", stateMachine);
} else {
Set<TransitionTarget> targets = step.getAfterStatus().getStates();
- targets.add(tmp);
+ targets.addAll(t.getTargets());
determineTargetStates(targets, errRep, scInstance);
//set of ALL entered states (even if initialState is a jump-over)
Set<TransitionTarget> onEntry = SCXMLHelper.getAncestorClosure(targets, null);
@@ -356,7 +356,6 @@ public class SCXMLSemanticsImpl implemen
List<TransitionTarget> entering = Arrays.asList(oen);
Collections.reverse(entering);
step.getEntryList().addAll(entering);
-
}
}
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java Tue Mar 18 01:54:02 2014
@@ -166,7 +166,7 @@ public class SCXMLReaderTest {
public void testSCXMLReaderSend01Sample() throws Exception {
// Digest
scxml = SCXMLTestHelper.parse(send01);
- State ten = (State) scxml.getInitialTarget();
+ State ten = (State) scxml.getInitialTransition().getTargets().get(0);
Assert.assertEquals("ten", ten.getId());
List<Transition> ten_done = ten.getTransitionsList("ten.done");
Assert.assertEquals(1, ten_done.size());
@@ -192,7 +192,7 @@ public class SCXMLReaderTest {
Assert.assertNotNull(scxml);
scxmlAsString = serialize(scxml);
Assert.assertNotNull(scxmlAsString);
- Final foo = (Final) scxml.getInitialTarget();
+ Final foo = (Final) scxml.getInitialTransition().getTargets().get(0);
Assert.assertEquals("foo", foo.getId());
}
@@ -203,7 +203,7 @@ public class SCXMLReaderTest {
"action", MyAction.class);
cas.add(ca);
scxml = SCXMLTestHelper.parse(action01, cas);
- State state = (State) scxml.getInitialTarget();
+ State state = (State) scxml.getInitialTransition().getTargets().get(0);
Assert.assertEquals("actions", state.getId());
List<Action> actions = state.getOnEntry().getActions();
Assert.assertEquals(1, actions.size());
@@ -221,7 +221,7 @@ public class SCXMLReaderTest {
Assert.assertNotNull(scxml);
scxmlAsString = serialize(scxml);
Assert.assertNotNull(scxmlAsString);
- Final foo = (Final) scxml.getInitialTarget();
+ Final foo = (Final) scxml.getInitialTransition().getTargets().get(0);
Assert.assertEquals("foo", foo.getId());
Datamodel dataModel = scxml.getDatamodel();
Assert.assertNotNull(dataModel);
@@ -244,7 +244,7 @@ public class SCXMLReaderTest {
Assert.assertNotNull(scxml);
scxmlAsString = serialize(scxml);
Assert.assertNotNull(scxmlAsString);
- foo = (Final) scxml.getInitialTarget();
+ foo = (Final) scxml.getInitialTransition().getTargets().get(0);
Assert.assertEquals("foo", foo.getId());
dataModel = scxml.getDatamodel();
Assert.assertNotNull(dataModel);
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ScxmlInitialAttributeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ScxmlInitialAttributeTest.java?rev=1578711&r1=1578710&r2=1578711&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ScxmlInitialAttributeTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/ScxmlInitialAttributeTest.java Tue Mar 18 01:54:02 2014
@@ -59,8 +59,8 @@ public class ScxmlInitialAttributeTest {
public void testInitial() throws Exception {
SCXML scxml = SCXMLTestHelper.parse(new StringReader(SCXML_WITH_LEGAL_INITIAL), null);
assertEquals("The initial state ID reading was wrong.", "s1", scxml.getInitial());
- assertNotNull(scxml.getInitialTarget());
- assertEquals("The initial state resolution was wrong.", "s1", scxml.getInitialTarget().getId());
+ assertNotNull(scxml.getInitialTransition().getTargets().get(0));
+ assertEquals("The initial state resolution was wrong.", "s1", scxml.getInitialTransition().getTargets().get(0).getId());
SCXMLExecutor exec = executeSCXML(scxml);
assertEquals(scxml.getTargets().get("s1"), exec.getCurrentStatus().getStates().iterator().next());
}
@@ -69,8 +69,8 @@ public class ScxmlInitialAttributeTest {
public void testNoInitial() throws Exception {
SCXML scxml = SCXMLTestHelper.parse(new StringReader(SCXML_WITH_NO_INITIAL), null);
assertNull(scxml.getInitial());
- assertNotNull("The initial state ID reading was wrong.", scxml.getInitialTarget());
- assertEquals("The initial state resolution was wrong.", "s1", scxml.getInitialTarget().getId());
+ assertNotNull("The initial state ID reading was wrong.", scxml.getInitialTransition().getTargets().get(0));
+ assertEquals("The initial state resolution was wrong.", "s1", scxml.getInitialTransition().getTargets().get(0).getId());
SCXMLExecutor exec = executeSCXML(scxml);
assertEquals(scxml.getTargets().get("s1"), exec.getCurrentStatus().getStates().iterator().next());
}