Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremie.tatibouet2016-01-20 16:27:17 +0000
committerjeremie.tatibouet2016-01-20 16:27:17 +0000
commitf165b7219ec568da522dfe15cfb484c0a90dff3f (patch)
tree43d427d1f2805e46703f6e457ba4983678663a3e
parent65b9415c69f0c337356a16954008c0519fbaa4e2 (diff)
downloadorg.eclipse.papyrus-f165b7219ec568da522dfe15cfb484c0a90dff3f.tar.gz
org.eclipse.papyrus-f165b7219ec568da522dfe15cfb484c0a90dff3f.tar.xz
org.eclipse.papyrus-f165b7219ec568da522dfe15cfb484c0a90dff3f.zip
Refactoring and improvements of semantics of transitions.
The semantics of each kind of transition is captured in a separate semantics visitor. Preconditions to enter a target or exit a source were added. Change-Id: I54be79390541082eb6684de354bfe9e78ff6789a Signed-off-by: jeremie.tatibouet <jeremie.tatibouet@cea.fr>
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/Loci/LociL3/StateMachineExecutionFactory.java11
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateConfiguration.java4
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateMachineConfiguration.java13
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/ExternalTransitionActivation.java67
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/InternalTransitionActivation.java29
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/LocalTransitionActivation.java97
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/EntryPointActivation.java15
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ExitPointActivation.java4
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ForkPseudostateActivation.java40
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/JoinPseudostateActivation.java28
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/TerminatePseudostateActivation.java2
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateActivation.java12
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java10
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java136
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java11
15 files changed, 333 insertions, 146 deletions
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/Loci/LociL3/StateMachineExecutionFactory.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/Loci/LociL3/StateMachineExecutionFactory.java
index 01a9e60dbd6..d638e7e033e 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/Loci/LociL3/StateMachineExecutionFactory.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/Loci/LociL3/StateMachineExecutionFactory.java
@@ -16,11 +16,13 @@ package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.Loci.LociL3;
import org.eclipse.papyrus.moka.composites.Semantics.Loci.LociL3.CS_ExecutionFactory;
import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.SemanticVisitor;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.Classes.Kernel.StateMachineOpaqueExpressionEvaluation;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.ExternalTransitionActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.FinalStateActivation;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.InternalTransitionActivation;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.LocalTransitionActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.RegionActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.StateActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.StateMachineExecution;
-import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.TransitionActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Pseudostate.ChoicePseudostateActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Pseudostate.EntryPointActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Pseudostate.ExitPointActivation;
@@ -64,7 +66,12 @@ public class StateMachineExecutionFactory extends CS_ExecutionFactory {
visitor = new StateActivation() ;
}
}else if (element instanceof Transition) {
- visitor = new TransitionActivation() ;
+ Transition transition = (Transition) element;
+ switch(transition.getKind()){
+ case EXTERNAL_LITERAL: visitor = new ExternalTransitionActivation(); break;
+ case INTERNAL_LITERAL: visitor = new InternalTransitionActivation(); break;
+ case LOCAL_LITERAL: visitor = new LocalTransitionActivation(); break;
+ }
}else if (element instanceof Region) {
visitor = new RegionActivation();
}else if(element instanceof OpaqueExpression) {
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateConfiguration.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateConfiguration.java
index a3a0c2ae8d1..d135146358f 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateConfiguration.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateConfiguration.java
@@ -182,10 +182,6 @@ public class StateConfiguration {
return added;
}
- public boolean isActive(VertexActivation activation){
- return false; //TODO
- }
-
public String toString(){
String result = "";
int i = 0;
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateMachineConfiguration.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateMachineConfiguration.java
index 38c28a0bbfe..b258b8ef164 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateMachineConfiguration.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Configuration/StateMachineConfiguration.java
@@ -17,6 +17,7 @@ import static org.eclipse.papyrus.moka.fuml.statemachines.Activator.logger;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -83,12 +84,14 @@ public class StateMachineConfiguration {
return this.remove(stateActivation);
}
- public boolean isStable(){
- return true; //TODO
- }
-
public boolean isActive(VertexActivation activation){
- return this.rootConfiguration.isActive(activation);
+ // A vertex that is currently active is part of the state-machine configuration
+ boolean found = false;
+ Iterator<Integer> levelsIterator = this.cartorgraphy.keySet().iterator();
+ while(!found && levelsIterator.hasNext()){
+ found = this.cartorgraphy.get(levelsIterator.next()).contains(activation);
+ }
+ return found;
}
protected boolean remove(VertexActivation activation){
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/ExternalTransitionActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/ExternalTransitionActivation.java
new file mode 100644
index 00000000000..f5b7f026d4d
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/ExternalTransitionActivation.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines;
+
+import org.eclipse.uml2.uml.Vertex;
+
+public class ExternalTransitionActivation extends TransitionActivation {
+
+ protected void exitSource(){
+ // The exiting phase of the source vertex activation is conditioned both by
+ // the prerequisites that apply to leave the source and the prerequisites that
+ // apply to enter the target.
+ // 1 - The source can be exited and its target can be entered
+ // -> The source is exited using the common ancestor
+ // 2 - The source can be exited but is target is not ready to be entered
+ // -> The source is exited but the common ancestor is used. This implies
+ // the exiting phase is not propagated to parent state (if required)
+ if(this.vertexSourceActivation.isExitable(this)){
+ if(this.vertexTargetActivation.isEnterable(this)){
+ this.vertexSourceActivation.exit(this, this.getLeastCommonAncestor());
+ }else{
+ this.vertexSourceActivation.exit(this, null);
+ }
+ }
+ }
+
+ protected void enterTarget() {
+ // If the target vertex activation can be entered (i.e., its possible prerequisites
+ // are satisfied) then the entering process begins. Note that this process may lead
+ // to enter other states based on what is the common ancestor exiting between the
+ // the source and the target. Besides the prerequisites imposed by the target vertex
+ // activation there are no other constraints to enter the target state
+ if(this.vertexTargetActivation.isEnterable(this)){
+ this.vertexTargetActivation.enter(this, this.getLeastCommonAncestor());
+ }else{
+ if(this.vertexTargetActivation instanceof StateActivation){
+ StateActivation targetStateActivation = (StateActivation) this.vertexTargetActivation;
+ int i = 0;
+ RegionActivation containingRegionActivation = null;
+ while(containingRegionActivation == null && i < targetStateActivation.regionActivation.size()){
+ RegionActivation currentActivation = targetStateActivation.regionActivation.get(i);
+ if(currentActivation.getVertexActivation((Vertex)this.vertexSourceActivation.getNode())!=null){
+ containingRegionActivation = currentActivation;
+ }
+ i++;
+ }
+ if(containingRegionActivation!=null){
+ containingRegionActivation.isCompleted = true;
+ if(targetStateActivation.hasCompleted()){
+ targetStateActivation.notifyCompletion();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/InternalTransitionActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/InternalTransitionActivation.java
new file mode 100644
index 00000000000..cb27258ba5d
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/InternalTransitionActivation.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines;
+
+public class InternalTransitionActivation extends TransitionActivation{
+
+ @Override
+ protected void exitSource() {
+ // An internal transition does not cause exit of the source state
+ return;
+ }
+
+ protected void enterTarget() {
+ // An internal transition does not cause entry of the target state
+ return;
+ }
+
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/LocalTransitionActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/LocalTransitionActivation.java
new file mode 100644
index 00000000000..98a29d6f1bc
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/LocalTransitionActivation.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines;
+
+import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.Execution;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Pseudostate.EntryPointActivation;
+import org.eclipse.uml2.uml.Vertex;
+
+public class LocalTransitionActivation extends TransitionActivation {
+
+ protected StateActivation getContainingState(){
+ // The container of a local transition is determined in the following manner:
+ // 1 - If the source vertex is an entry point then the containing state is the
+ // the state that has this entry point on its edge
+ // 2 - Else in the case where the source contains the target then the containing
+ // state is the source itself. Otherwise the source is the target
+ StateActivation containingState = null;
+ if(this.vertexSourceActivation instanceof EntryPointActivation){
+ containingState = (StateActivation) this.vertexSourceActivation.getParentState();
+ }else{
+ if(this.vertexSourceActivation.getVertexActivation((Vertex)this.vertexTargetActivation.getNode())!=null){
+ containingState = (StateActivation) this.vertexSourceActivation;
+ }else{
+ containingState = (StateActivation) this.vertexTargetActivation;
+ }
+ }
+ return containingState;
+ }
+
+ @Override
+ protected void exitSource() {
+ // Exiting the source state of a local transition consists in the following set of actions:
+ // 1 - Check if the source state can be exited (if it cannot then do nothing)
+ // 2 - If the source can be exited and this latter is an entry point then the exit
+ // of the source is trivial (i.e., it only consists in exiting the entry point)
+ // - If the source can be exited and this latter is a composite state then the top
+ // vertex that is located in the top region which contains (maybe in deep nesting)
+ // the tar get is exited. At this point, if the source is not the containing state
+ // then it is also exited
+ StateActivation containingState = this.getContainingState();
+ if(this.vertexSourceActivation.isExitable(this)){
+ if(this.vertexSourceActivation instanceof EntryPointActivation){
+ this.vertexSourceActivation.exit(this, null);
+ }else{
+ int i=0;
+ RegionActivation containingRegion = null;
+ while(containingRegion==null && i < containingState.regionActivation.size()){
+ RegionActivation regionActivation = containingState.regionActivation.get(i);
+ if(regionActivation.getVertexActivation((Vertex)this.vertexTargetActivation.getNode())!=null){
+ containingRegion = regionActivation;
+ }
+ i++;
+ }
+ if(containingRegion!=null){
+ i = 0;
+ VertexActivation vertexActivationToBeExited = null;
+ Execution stateMachineExecution = this.getStateMachineExecution();
+ while(vertexActivationToBeExited == null && i < containingRegion.vertexActivations.size()){
+ VertexActivation currentActivation = containingRegion.vertexActivations.get(i);
+ if(((StateMachineExecution)stateMachineExecution).getConfiguration().isActive(currentActivation)){
+ vertexActivationToBeExited = currentActivation;
+ }
+ i++;
+ }
+ if(vertexActivationToBeExited != null){
+ vertexActivationToBeExited.exit(this, null);
+ }
+ }
+ if(this.vertexSourceActivation != containingState){
+ this.vertexSourceActivation.exit(this, this.getLeastCommonAncestor());
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void enterTarget() {
+ // Entering the target of local transition consists in checking if the target can be entered. If
+ // this is the case then only when the target is not also the containing state it is entered
+ if(this.vertexTargetActivation.isEnterable(this)){
+ if(this.vertexTargetActivation != this.getContainingState()){
+ this.vertexTargetActivation.enter(this, this.getLeastCommonAncestor());
+ }
+ }
+ }
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/EntryPointActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/EntryPointActivation.java
index 90e2b0609b8..3465b190f5d 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/EntryPointActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/EntryPointActivation.java
@@ -19,6 +19,21 @@ import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.Behav
public class EntryPointActivation extends ConnectionPointActivation {
+ public boolean isExitable(TransitionActivation exitingTransition) {
+ // An entry point can be exited as soon as every outgoing transition expect
+ // the current "exitingTransition" have been traversed.
+ int i = 0;
+ boolean isExitable = true;
+ while(isExitable && i < this.outgoingTransitionActivations.size()){
+ TransitionActivation transitionActivation = this.outgoingTransitionActivations.get(i);
+ if(transitionActivation != exitingTransition){
+ isExitable = transitionActivation.isTraversed();
+ }
+ i++;
+ }
+ return isExitable;
+ }
+
public void enter(TransitionActivation enteringTransition, RegionActivation leastCommonAncestor) {
// Enter a state through an entry point. The state on which the entry point is
// placed can be a deeply nested state. Therefore parent state of that state must
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ExitPointActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ExitPointActivation.java
index a2bf667633f..493f0333130 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ExitPointActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ExitPointActivation.java
@@ -24,7 +24,7 @@ import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.Behav
public class ExitPointActivation extends ConnectionPointActivation {
- public boolean isReady(TransitionActivation enteringTransition) {
+ public boolean isEnterable(TransitionActivation enteringTransition) {
// Determine if this exit point satisfied its requirement to be exited.
// The requirement is: all incoming transitions must have been fired once
// if they originate from sub-states located in orthogonal regions
@@ -59,7 +59,7 @@ public class ExitPointActivation extends ConnectionPointActivation {
// that can be used to leave the ExitPoint. This transition is fired. This lead
// to exit and parent states in cascade if required.
List<TransitionActivation> fireableTransitions = this.getFireableTransitions();
- if (this.isReady(enteringTransition) && !fireableTransitions.isEmpty()) {
+ if (!fireableTransitions.isEmpty()) {
ChoiceStrategy choiceStrategy = (ChoiceStrategy) this.getExecutionLocus().factory.getStrategy("choice");
int chosenIndex = choiceStrategy.choose(fireableTransitions.size());
TransitionActivation selectedTransition = fireableTransitions.get(chosenIndex - 1);
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ForkPseudostateActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ForkPseudostateActivation.java
index 34c47d2bbf5..ba04c19f417 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ForkPseudostateActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/ForkPseudostateActivation.java
@@ -19,6 +19,23 @@ import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.Behav
public class ForkPseudostateActivation extends PseudostateActivation {
+
+ @Override
+ public boolean isExitable(TransitionActivation exitingTransition) {
+ // The Fork node activation can only be exited when all of its outgoing transitions
+ // (expect the current "exitingTransition")previously fired.
+ int i = 0;
+ boolean isExitable = true;
+ while(isExitable && i < this.outgoingTransitionActivations.size()){
+ TransitionActivation transitionActivation = this.outgoingTransitionActivations.get(i);
+ if(transitionActivation != exitingTransition){
+ isExitable = transitionActivation.isTraversed();
+ }
+ i++;
+ }
+ return isExitable;
+ }
+
@Override
public void enter(TransitionActivation enteringTransition, RegionActivation leastCommonAncestor) {
// Fires all outgoing transitions of the for **concurrently**
@@ -40,23 +57,12 @@ public class ForkPseudostateActivation extends PseudostateActivation {
public void exit(TransitionActivation exitingTransition, RegionActivation leastCommonAncestor) {
// A fork will only be allowed to exit when all other transitions outgoing
//this pseudo state have already been traversed
- boolean isExitable = true;
- int i = 0;
- while(isExitable && i < this.outgoingTransitionActivations.size()){
- TransitionActivation transitionActivation = this.outgoingTransitionActivations.get(i);
- if(exitingTransition!=transitionActivation){
- isExitable = transitionActivation.isTraversed();
- }
- i++;
- }
- if(isExitable){
- super.exit(exitingTransition, leastCommonAncestor);
- // If required parent state is exited (the rule applies recursively)
- if (leastCommonAncestor != null && this.getParent() != leastCommonAncestor) {
- VertexActivation parentVertexActivation = this.getParentState();
- if (parentVertexActivation != null) {
- parentVertexActivation.enter(exitingTransition, leastCommonAncestor);
- }
+ super.exit(exitingTransition, leastCommonAncestor);
+ // If required parent state is exited (the rule applies recursively)
+ if (leastCommonAncestor != null && this.getParent() != leastCommonAncestor) {
+ VertexActivation parentVertexActivation = this.getParentState();
+ if (parentVertexActivation != null) {
+ parentVertexActivation.enter(exitingTransition, leastCommonAncestor);
}
}
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/JoinPseudostateActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/JoinPseudostateActivation.java
index 416cfa73ba4..9cead7fade0 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/JoinPseudostateActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/JoinPseudostateActivation.java
@@ -19,7 +19,7 @@ import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.Behav
public class JoinPseudostateActivation extends PseudostateActivation {
- public boolean isReady(TransitionActivation enteringTransition) {
+ public boolean isEnterable(TransitionActivation enteringTransition) {
// Determine if all incoming transitions except this one already have been traversed
// If this is the case then this node is ready to be entered
boolean isReady = true;
@@ -41,21 +41,19 @@ public class JoinPseudostateActivation extends PseudostateActivation {
// outgoing transition of the Join. Note that a Fork cannot have more than an outgoing transition
// (if this is the case then the model is ill-formed).
// The guard of the outgoing transition is evaluated to verify that the transition can be fired
- if (this.isReady(enteringTransition)) {
- // If required parent state is entered first (the rule applies recursively)
- if (leastCommonAncestor != null && this.getParent() != leastCommonAncestor) {
- VertexActivation parentVertexActivation = this.getParentState();
- if (parentVertexActivation != null) {
- parentVertexActivation.enter(enteringTransition, leastCommonAncestor);
- }
+ // If required parent state is entered first (the rule applies recursively)
+ if (leastCommonAncestor != null && this.getParent() != leastCommonAncestor) {
+ VertexActivation parentVertexActivation = this.getParentState();
+ if (parentVertexActivation != null) {
+ parentVertexActivation.enter(enteringTransition, leastCommonAncestor);
}
- // The Join pseudo state is entered and its outgoing transition is fired (if possible)
- super.enter(enteringTransition, leastCommonAncestor);
- if (!this.outgoingTransitionActivations.isEmpty()) {
- TransitionActivation transitionActivation = this.outgoingTransitionActivations.get(0);
- if (transitionActivation.evaluateGuard()) {
- transitionActivation.fire();
- }
+ }
+ // The Join pseudo state is entered and its outgoing transition is fired (if possible)
+ super.enter(enteringTransition, leastCommonAncestor);
+ if (!this.outgoingTransitionActivations.isEmpty()) {
+ TransitionActivation transitionActivation = this.outgoingTransitionActivations.get(0);
+ if (transitionActivation.evaluateGuard()) {
+ transitionActivation.fire();
}
}
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/TerminatePseudostateActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/TerminatePseudostateActivation.java
index 3dfdccd5cb2..d893846d4b3 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/TerminatePseudostateActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Pseudostate/TerminatePseudostateActivation.java
@@ -20,7 +20,7 @@ public class TerminatePseudostateActivation extends PseudostateActivation {
super.enter(enteringTransition, leastCommonAncestor);
Execution stateMachineExecution = this.getStateMachineExecution();
stateMachineExecution.terminate();
- stateMachineExecution.destroy();
+ stateMachineExecution.destroy(); //FIXME: issue here
super.exit(enteringTransition, leastCommonAncestor);
}
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateActivation.java
index 569c4f1b7a8..31ff6f07e75 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateActivation.java
@@ -248,6 +248,12 @@ public class StateActivation extends VertexActivation {
}
}
+ public boolean isEnterable(TransitionActivation enteringTransition) {
+ // A state can only be entered if it is not part of the state-machine configuration
+ // (i.e., the state is not currently active)
+ return !((StateMachineExecution)this.getStateMachineExecution()).getConfiguration().isActive(this);
+ }
+
public void enter(TransitionActivation enteringTransition, RegionActivation leastCommonAncestor) {
if(this.status.equals(StateMetadata.IDLE)){
// The state is entered via an explicit transition
@@ -288,6 +294,12 @@ public class StateActivation extends VertexActivation {
}
}
+ public boolean isExitable(TransitionActivation exitingTransition) {
+ // A state can only be be exited if it is part of the state-machine configuration
+ // (i.e., the state is currently active)
+ return !this.isEnterable(exitingTransition);
+ }
+
public void exit(TransitionActivation exitingTransition, RegionActivation leastCommonAncestor){
// If we exit a composite state, this provokes the termination of all of its regions
if(!this.regionActivation.isEmpty()){
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java
index 5d308604326..0e7a59e2af8 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java
@@ -92,20 +92,22 @@ public class StateMachineExecution extends Execution {
}
public void execute() {
- /*0. Initialization*/
+ // The execution of state-machine is realized as described below
+ // 1 - An event accepter is placed in the list of waiting event accepters for this state-machine
+ // 2 - All visitors required to interpret the state-machine are instantiated and link together
+ // 3 - All top level regions (i.e. those directly owned by the executed state-machine) are entered
+ // concurrently.
+ // Note: a state-machine always has at runtime a single event accepter
if(this.context!=null && this.context.objectActivation!=null){
this.context.register(new StateMachineEventAccepter(this));
}
this.initRegions();
- /*1. Create visitors for all vertices*/
for(RegionActivation activation: this.regionActivation){
activation.activate();
}
- /*2. Create visitors for all transitions*/
for(RegionActivation activation: this.regionActivation){
activation.activateTransitions();
}
- /*3. Fire "concurrently" all initial transition in the different regions*/
for(RegionActivation regionActivation: this.regionActivation){
regionActivation.enter(null);
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java
index 3288627b032..3e37f0024ff 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java
@@ -32,28 +32,30 @@ import org.eclipse.uml2.uml.OpaqueExpression;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.SignalEvent;
import org.eclipse.uml2.uml.Transition;
-import org.eclipse.uml2.uml.TransitionKind;
import org.eclipse.uml2.uml.Trigger;
import org.eclipse.uml2.uml.ValueSpecification;
-public class TransitionActivation extends StateMachineSemanticVisitor {
+public abstract class TransitionActivation extends StateMachineSemanticVisitor {
- /**
- * Provide the status of a specific transition
- *
- * NONE: The transition exists, however its source state was is not yet reached
- * REACHED: The source vertex of the transition is reached
- * TRAVERSED: The transition is being executed
- * COMPLETED: The source transition was executed and its target state is reached
- */
- public enum TransitionMetadata{NONE, REACHED, TRAVERSED, COMPLETED}
+ // Provide the status of a specific transition
+ // NONE: The transition exists, however its source state was is not yet reached
+ // REACHED: The source vertex of the transition is reached
+ // TRAVERSED: The transition was executed
+ public enum TransitionMetadata{NONE, REACHED, TRAVERSED}
+ // The source activation of this transition activation
protected VertexActivation vertexSourceActivation;
+ // The target activation of this transition activation
protected VertexActivation vertexTargetActivation;
+ // The status (NONE, REACHED, TRAVERSED or COMPLETED) of the transition
protected TransitionMetadata status;
+ // Least common ancestor of the source and the target. This is materialized
+ // by the region activation that is the common ancestor of the source and the target.
+ private RegionActivation leastCommonAncestor;
+
public TransitionMetadata getState() {
return status;
}
@@ -68,30 +70,26 @@ public class TransitionActivation extends StateMachineSemanticVisitor {
}
public boolean isReached(){
+ /// Convenience operation which returns true if the status of this transition
+ // is REACHED; false otherwise.
return this.status.equals(TransitionMetadata.REACHED);
}
public boolean isTraversed(){
+ // Convenience operation which returns true if the status of this transition
+ // is TRAVERSED; false otherwise.
return this.status.equals(TransitionMetadata.TRAVERSED);
}
- public boolean isCompleted(){
- return this.status.equals(TransitionMetadata.COMPLETED);
- }
-
- /**
- * A transition that is automatic has no triggers and no guard.
- * @return boolean
- */
- public boolean isAutomatic(){
+ public boolean isCompletion(){
+ // Convenience operation to which returns true if the transition is a completion
+ // transition. FIXME: to be verified
Transition transition = (Transition)this.node;
return transition.getTriggers().isEmpty() && transition.getGuard() == null;
}
- /**
- * @return true if the guard evaluates to true false in the other case
- */
public boolean evaluateGuard(){
+ // TODO
boolean result = true;
Transition transition = (Transition) this.node;
if (transition.getGuard() != null) {
@@ -114,21 +112,16 @@ public class TransitionActivation extends StateMachineSemanticVisitor {
return result;
}
- /**
- * True if the transition has a trigger which matches the given signal type
- */
public boolean hasTrigger(final SignalInstance signal){
+ // TODO
int i = 0;
Transition transition = (Transition)this.node;
Trigger trigger = null;
while(i < transition.getTriggers().size() && trigger==null){
Trigger currentTrigger = transition.getTriggers().get(i);
- /*1. Check that expected signal type and conforms to signal instance type*/
if(currentTrigger.getEvent()!=null &&
currentTrigger.getEvent() instanceof SignalEvent
&& ((SignalEvent)currentTrigger.getEvent()).getSignal()==signal.type){
- /*1.1. The port from which the signal was emitted must be one which is referenced
- * in the trigger*/
if(currentTrigger.getPorts().size() > 0) {
List<Port> portsOfTrigger = currentTrigger.getPorts();
Port onPort = ((CS_SignalInstance)signal).interactionPoint.definingPort;
@@ -150,11 +143,6 @@ public class TransitionActivation extends StateMachineSemanticVisitor {
return trigger != null;
}
- /**
- * A triggered transition means implies event accepters are registered. If one them match
- * an available signal the transition can be elected to fire
- * @return boolean
- */
public boolean isTriggered(){
return !((Transition)this.node).getTriggers().isEmpty();
}
@@ -188,76 +176,36 @@ public class TransitionActivation extends StateMachineSemanticVisitor {
}
}
- public StateActivation getContainingState(){
- // Get the state containing the region which contains the transition
- RegionActivation regionActivation = (RegionActivation) this.getParent();
- if(regionActivation!=null){
- if(regionActivation.getParent() instanceof StateActivation){
- return (StateActivation) regionActivation.getParent();
- }
- }
- return null;
- }
-
- protected void exitSource(){
- // A source state is exited when the transition fires under the following conditions:
- // 1 - The transition leaving the source vertex is external
- // 2 - The transition leaving the source vertex is local but the source state is not the
- // state which contains the transition
- Transition node = (Transition) this.getNode();
- boolean exitSourceState = false;
- // Determine if the transition will lead to exit the source state
- if(node.getKind()==TransitionKind.EXTERNAL_LITERAL){
- exitSourceState = true;
- }else if(node.getKind()==TransitionKind.LOCAL_LITERAL){
- StateActivation stateActivation = this.getContainingState();
- exitSourceState = stateActivation!=null && node.getSource()!=stateActivation.getNode();
- }
- // Proceed to the exiting of the source vertex. Note that if required the containing
- // state will also be exited (this rule applies recursively). The exiting phase is not
- // realized in cascade when the target is not ready to be entered (e.g., in the case of
- // a join or in the case of an exit point playing the role of a join).
- RegionActivation leastCommonAncestor = null;
- if(exitSourceState){
- if(this.vertexTargetActivation.isReady(this)){
- if(this.vertexSourceActivation.getParentState()!=
- this.vertexTargetActivation.getParentState()){
- leastCommonAncestor = this.vertexSourceActivation.
- getLeastCommonAncestor(this.vertexTargetActivation);
- }
- this.vertexSourceActivation.exit(this, leastCommonAncestor);
- }else{
- this.vertexSourceActivation.exit(this, null);
- }
- }
- }
-
- protected void enterTarget(){
- Transition node = (Transition) this.getNode();
- RegionActivation leastCommonAncestor = null;
- // A target state is always entered except when the transition reaching this latter
- // has the internal kind
- if(node.getKind()!=TransitionKind.INTERNAL_LITERAL){
- if(this.vertexSourceActivation.getParentState()!=this.vertexTargetActivation.getParentState()){
- leastCommonAncestor = this.vertexSourceActivation.getLeastCommonAncestor(this.vertexTargetActivation);
- }
- this.vertexTargetActivation.enter(this, leastCommonAncestor);
- }
- }
-
public void fire(){
+ // The fire sequence is broken into the following set of actions
+ // 1 - Exit the source (depends on the kind of transition that is currently used)
+ // 2 - Execute the effect (if one exists for that transition)
+ // 3 - Enter the target (depends on the kind of transition that is currently used)
this.exitSource();
- // FIXME: specific to the Moka implementation
FUMLExecutionEngine.eInstance.getControlDelegate().control(this);
this.executeEffect();
- // FIXME: specific to the Moka implementation
((SM_ControlDelegate)FUMLExecutionEngine.eInstance.getControlDelegate()).inactive(this.getNode());
this.setState(TransitionMetadata.TRAVERSED);
- // FIXME: specific to the Moka implementation
logger.info(this.getNode().getName()+" => TRAVERSED");
this.enterTarget();
}
+
+ protected RegionActivation getLeastCommonAncestor(){
+ // Return the common ancestor of the source and the target. This common ancestor is
+ // a region activation
+ if(this.vertexSourceActivation.getParentState()!=this.vertexTargetActivation.getParentState()){
+ if(this.leastCommonAncestor==null){
+ this.leastCommonAncestor = this.vertexSourceActivation.getLeastCommonAncestor(this.vertexTargetActivation);
+ }
+ }
+ return this.leastCommonAncestor;
+ }
+
+ protected abstract void exitSource();
+
+ protected abstract void enterTarget();
+
public String toString(){
return "["+this.getSourceActivation()+"] -> ["+this.getTargetActivation()+"]";
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java
index 21a54987ea0..bf62314fa93 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java
@@ -173,14 +173,21 @@ public abstract class VertexActivation extends StateMachineSemanticVisitor {
return leastCommonAncestor;
}
- public boolean isReady(TransitionActivation enteringTransition){
- // By default a vertex as no prerequisite that need to be full-filled
+ public boolean isEnterable(TransitionActivation enteringTransition){
+ // By default a vertex has no prerequisites that need to be full-filled
// to be entered. Nevertheless some vertex (e.g., join or exit) have such
// prerequisites. Therefore this method is intended to be overridden in vertex
// activation sub-classes.
return true;
}
+ public boolean isExitable(TransitionActivation exitingTransition){
+ // By default a vertex has no prerequisites that need to be full-filled to be entered
+ // Nevertheless some vertex (e.g., Fork) have such prerequisite. Therefore this method
+ // is intended to be overridden in vertex activation sub-classes.
+ return true;
+ }
+
public void terminate(){
// Terminate applied by a vertex activation does nothing by default. However it is intended
// to be overridden by sub-classe(s)

Back to the top