Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremie.tatibouet2016-03-04 15:56:01 +0000
committerjeremie.tatibouet2016-03-04 15:56:01 +0000
commitf87ddf97ad995c801b887a479b346fe925c0827b (patch)
treec618771f7d08ae35211459e0644c400df7d61809
parentc893d63617d44125268f87717a9ca05a689dc1a4 (diff)
downloadorg.eclipse.papyrus-initial-submission-V1.tar.gz
org.eclipse.papyrus-initial-submission-V1.tar.xz
org.eclipse.papyrus-initial-submission-V1.zip
Merge DefaultTransitionSelectionStrategy to StateMachineEventAccepterinitial-submission-V1
Remove DefaultTransitionSelectionStrategy Remove TransitionSelectionStrategy Change-Id: I41712506b654c2984201b15af0b2a870ce83b75e 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/StateMachines/DefaultTransitionSelectionStrategy.java114
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineEventAccepter.java102
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/TransitionSelectionStrategy.java53
3 files changed, 94 insertions, 175 deletions
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/DefaultTransitionSelectionStrategy.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/DefaultTransitionSelectionStrategy.java
deleted file mode 100644
index 6fe9d70cf5e..00000000000
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/DefaultTransitionSelectionStrategy.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventOccurrence;
-import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ChoiceStrategy;
-
-public class DefaultTransitionSelectionStrategy extends TransitionSelectionStrategy {
-
- public DefaultTransitionSelectionStrategy(StateMachineExecution execution) {
- super(execution);
- }
-
- public boolean isDeferred(EventOccurrence eventOccurrence){
- // Determine if the dispatched event occurrence is deferred in the
- // current state machine configuration. An event occurrence can only be deferred
- // if the following conditions are fulfilled:
- // 1 - One active state in the hierarchy declares the event types as being deferred.
- // 2 - No transitions (ready to fire) with a higher priority than the deferring state
- // could be found.
- return this._isDeferred(eventOccurrence, this.execution.getConfiguration().rootConfiguration);
- }
-
- public boolean _isDeferred(EventOccurrence eventOccurrence, StateConfiguration stateConfiguration){
- // Determine if the given state configuration is capable of deferring the given event occurrence.
- int i = 0;
- boolean deferred = false;
- while(!deferred && i < stateConfiguration.children.size()){
- deferred = this._isDeferred(eventOccurrence, stateConfiguration.children.get(i));
- i++;
- }
- if(!deferred &&
- stateConfiguration.vertexActivation != null &&
- this._select(eventOccurrence, stateConfiguration).isEmpty() &&
- ((StateActivation)stateConfiguration.vertexActivation).canDefer(eventOccurrence)){
- deferred = true;
- }
- return deferred;
- }
-
- public void defer(EventOccurrence eventOccurrence){
- // Defers the given event occurrence. A deferred event occurrence is registered in
- // the deferred event pool. This latter refers to the deferred event as well as to the
- // the deferring state.
- this._defer(eventOccurrence, this.execution.getConfiguration().rootConfiguration);
- }
-
- protected boolean _defer(EventOccurrence eventOccurrence, StateConfiguration stateConfiguration){
- // Defers the given event occurrence in the context of the given state configuration.
- int i = 0;
- boolean deferred = false;
- while(!deferred && i < stateConfiguration.children.size()){
- deferred = this._defer(eventOccurrence, stateConfiguration.children.get(i));
- i++;
- }
- if(!deferred &&
- stateConfiguration.vertexActivation != null &&
- ((StateActivation)stateConfiguration.vertexActivation).canDefer(eventOccurrence)){
- ((StateActivation)stateConfiguration.vertexActivation).defer(eventOccurrence);
- deferred = true;
- }
- return deferred;
- }
-
- public boolean isTriggering(EventOccurrence eventOccurrence){
- // Returns true when one or more transition are ready to be fired using this event
- // occurrence; false otherwise.
- return !this.select(eventOccurrence).isEmpty();
- }
-
- public List<TransitionActivation> select(EventOccurrence eventOccurrence) {
- // Find for the given configuration the set of transition that can fire.
- return this._select(eventOccurrence, this.execution.getConfiguration().rootConfiguration);
- }
-
- protected List<TransitionActivation> _select(EventOccurrence eventOccurrence, StateConfiguration stateConfiguration){
- // Find for the given state configuration all transition that can actually fire.
- // The set of transition only contains transitions with the highest priority. In addition
- // no conflicting transitions are added to that set.
- List<TransitionActivation> selectedTransitions = new ArrayList<TransitionActivation>();
- for(int i = 0; i < stateConfiguration.children.size(); i++){
- selectedTransitions.addAll(this._select(eventOccurrence, stateConfiguration.children.get(i)));
- }
- if(selectedTransitions.isEmpty() && stateConfiguration.vertexActivation != null){
- for(int i = 0; i < stateConfiguration.vertexActivation.getOutgoingTransitions().size(); i++){
- TransitionActivation transitionActivation = stateConfiguration.vertexActivation.getOutgoingTransitions().get(i);
- if(transitionActivation.canFireOn(eventOccurrence)){
- selectedTransitions.add(transitionActivation);
- }
- }
- if(selectedTransitions.size() > 1){
- ChoiceStrategy choiceStrategy = (ChoiceStrategy) this.execution.locus.factory.getStrategy("choice");
- TransitionActivation electedTransition = selectedTransitions.get(choiceStrategy.choose(selectedTransitions.size()) - 1);
- selectedTransitions.clear();
- selectedTransitions.add(electedTransition);
- }
- }
- return selectedTransitions;
- }
-}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineEventAccepter.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineEventAccepter.java
index a144fdac87d..443745dd14f 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineEventAccepter.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineEventAccepter.java
@@ -13,11 +13,13 @@
*****************************************************************************/
package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventAccepter;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventOccurrence;
+import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ChoiceStrategy;
public class StateMachineEventAccepter extends EventAccepter{
@@ -27,12 +29,8 @@ public class StateMachineEventAccepter extends EventAccepter{
// accepter.
public StateMachineExecution registrationContext;
- // The strategy on which the transition selection process relies.
- protected TransitionSelectionStrategy selectionStrategy;
-
public StateMachineEventAccepter(StateMachineExecution execution) {
this.registrationContext = execution;
- this.selectionStrategy = new DefaultTransitionSelectionStrategy(execution);
}
@Override
@@ -46,10 +44,10 @@ public class StateMachineEventAccepter extends EventAccepter{
// is registered at the waiting event accepter list handled by the object activation
// Note that there always is a single event accepter for a state-machine (this works differently
// than for activities).
- if(this.selectionStrategy.isDeferred(eventOccurrence)){
- this.selectionStrategy.defer(eventOccurrence);
+ if(this.isDeferred(eventOccurrence)){
+ this.defer(eventOccurrence);
}else{
- List<TransitionActivation> fireableTransition = this.selectionStrategy.select(eventOccurrence);
+ List<TransitionActivation> fireableTransition = this.select(eventOccurrence);
if(!fireableTransition.isEmpty()){
int i = 0;
while(i < fireableTransition.size()){
@@ -69,7 +67,95 @@ public class StateMachineEventAccepter extends EventAccepter{
// There are two cases in which the state machine event accepter can match
// 1 - In the current state machine configuration the event can be deferred
// 2 - In the current state machine configuration the current event can trigger one or more transitions
- return this.selectionStrategy.isDeferred(eventOccurrence) | this.selectionStrategy.isTriggering(eventOccurrence);
+ return this.isDeferred(eventOccurrence) | this.isTriggering(eventOccurrence);
+ }
+
+
+ protected boolean isDeferred(EventOccurrence eventOccurrence){
+ // Determine if the dispatched event occurrence is deferred in the
+ // current state machine configuration. An event occurrence can only be deferred
+ // if the following conditions are fulfilled:
+ // 1 - One active state in the hierarchy declares the event types as being deferred.
+ // 2 - No transitions (ready to fire) with a higher priority than the deferring state
+ // could be found.
+ return this._isDeferred(eventOccurrence, this.registrationContext.getConfiguration().rootConfiguration);
+ }
+
+ protected boolean _isDeferred(EventOccurrence eventOccurrence, StateConfiguration stateConfiguration){
+ // Determine if the given state configuration is capable of deferring the given event occurrence.
+ int i = 0;
+ boolean deferred = false;
+ while(!deferred && i < stateConfiguration.children.size()){
+ deferred = this._isDeferred(eventOccurrence, stateConfiguration.children.get(i));
+ i++;
+ }
+ if(!deferred &&
+ stateConfiguration.vertexActivation != null &&
+ this._select(eventOccurrence, stateConfiguration).isEmpty() &&
+ ((StateActivation)stateConfiguration.vertexActivation).canDefer(eventOccurrence)){
+ deferred = true;
+ }
+ return deferred;
+ }
+
+ protected void defer(EventOccurrence eventOccurrence){
+ // Defers the given event occurrence. A deferred event occurrence is registered in
+ // the deferred event pool. This latter refers to the deferred event as well as to the
+ // the deferring state.
+ this._defer(eventOccurrence, this.registrationContext.getConfiguration().rootConfiguration);
+ }
+
+ protected boolean _defer(EventOccurrence eventOccurrence, StateConfiguration stateConfiguration){
+ // Defers the given event occurrence in the context of the given state configuration.
+ int i = 0;
+ boolean deferred = false;
+ while(!deferred && i < stateConfiguration.children.size()){
+ deferred = this._defer(eventOccurrence, stateConfiguration.children.get(i));
+ i++;
+ }
+ if(!deferred &&
+ stateConfiguration.vertexActivation != null &&
+ ((StateActivation)stateConfiguration.vertexActivation).canDefer(eventOccurrence)){
+ ((StateActivation)stateConfiguration.vertexActivation).defer(eventOccurrence);
+ deferred = true;
+ }
+ return deferred;
+ }
+
+ protected boolean isTriggering(EventOccurrence eventOccurrence){
+ // Returns true when one or more transition are ready to be fired using this event
+ // occurrence; false otherwise.
+ return !this.select(eventOccurrence).isEmpty();
+ }
+
+ protected List<TransitionActivation> select(EventOccurrence eventOccurrence) {
+ // Find for the given configuration the set of transition that can fire.
+ return this._select(eventOccurrence, this.registrationContext.getConfiguration().rootConfiguration);
+ }
+
+ protected List<TransitionActivation> _select(EventOccurrence eventOccurrence, StateConfiguration stateConfiguration){
+ // Find for the given state configuration all transition that can actually fire.
+ // The set of transition only contains transitions with the highest priority. In addition
+ // no conflicting transitions are added to that set.
+ List<TransitionActivation> selectedTransitions = new ArrayList<TransitionActivation>();
+ for(int i = 0; i < stateConfiguration.children.size(); i++){
+ selectedTransitions.addAll(this._select(eventOccurrence, stateConfiguration.children.get(i)));
+ }
+ if(selectedTransitions.isEmpty() && stateConfiguration.vertexActivation != null){
+ for(int i = 0; i < stateConfiguration.vertexActivation.getOutgoingTransitions().size(); i++){
+ TransitionActivation transitionActivation = stateConfiguration.vertexActivation.getOutgoingTransitions().get(i);
+ if(transitionActivation.canFireOn(eventOccurrence)){
+ selectedTransitions.add(transitionActivation);
+ }
+ }
+ if(selectedTransitions.size() > 1){
+ ChoiceStrategy choiceStrategy = (ChoiceStrategy) this.registrationContext.locus.factory.getStrategy("choice");
+ TransitionActivation electedTransition = selectedTransitions.get(choiceStrategy.choose(selectedTransitions.size()) - 1);
+ selectedTransitions.clear();
+ selectedTransitions.add(electedTransition);
+ }
+ }
+ return selectedTransitions;
}
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/TransitionSelectionStrategy.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/TransitionSelectionStrategy.java
deleted file mode 100644
index 86f3d66655a..00000000000
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/TransitionSelectionStrategy.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 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;
-
-import java.util.List;
-
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventOccurrence;
-
-public abstract class TransitionSelectionStrategy{
-
- // The state-machine execution for which the configuration
- // will be used to determine transition which can be fired
- protected StateMachineExecution execution;
-
- public TransitionSelectionStrategy(StateMachineExecution execution){
- this.execution = execution;
- }
-
- /*
- * Returns true if the given event occurrence can be deferred; false otherwise.
- */
- public abstract boolean isDeferred(EventOccurrence eventOccurrence);
-
- /*
- * Defer the given event occurrence
- */
- public abstract void defer(EventOccurrence eventOccurrence);
-
- /*
- * Returns true if at least one outgoing transition of a state which is currently
- * part of the active state configuration.
- */
- public abstract boolean isTriggering(EventOccurrence eventOccurrence);
-
- /*
- * Describe the process of selecting transition that can be fired using the given event
- * occurrence. Note that the selection only assesses outgoing transition that are in the
- * state-machine configuration. Priority rules introduced by hierarchy are taken into account
- */
- public abstract List<TransitionActivation> select(EventOccurrence eventOccurrence);
-
-}

Back to the top