Exposed ControlledVisitors to advices and give access to execution stack
Change-Id: I78b55a6b89b3a87ee5fc9b92b07a058d6ed83df8
Signed-off-by: Sebastien Revol <sebastien.revol@cea.fr>
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/BasicControllerAdvice.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/BasicControllerAdvice.java
index 541d979..0fe4a00 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/BasicControllerAdvice.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/BasicControllerAdvice.java
@@ -13,6 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.moka.externalcontrol.advice;
+import org.eclipse.papyrus.moka.externalcontrol.controller.IExternallyControlledVisitor;
import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;
import org.eclipse.uml2.uml.Element;
@@ -30,6 +31,7 @@
protected V delegatedVisitor;
protected E element;
+ protected IExternallyControlledVisitor<V> controlledVisitor;
public BasicControllerAdvice(E element, V delegatedVisitor) {
this.element= element;
@@ -61,6 +63,14 @@
// do Nothing...
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void setControlledVisitor(IExternallyControlledVisitor<? extends ISemanticVisitor> visitor) {
+ controlledVisitor =(IExternallyControlledVisitor<V>) visitor;
+
+ }
+
}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/IControllerAdvice.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/IControllerAdvice.java
index e510c0f..2e0bd98 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/IControllerAdvice.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/advice/IControllerAdvice.java
@@ -13,6 +13,9 @@
*****************************************************************************/
package org.eclipse.papyrus.moka.externalcontrol.advice;
+import org.eclipse.papyrus.moka.externalcontrol.controller.IExternallyControlledVisitor;
+import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;
+
public interface IControllerAdvice {
public Double getDuration();
@@ -20,4 +23,7 @@
public void doFinishAction();
public boolean canStart();
public boolean canFinish();
+
+ public void setControlledVisitor(IExternallyControlledVisitor< ? extends ISemanticVisitor> visitor);
+
}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledCallingVisitor.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledCallingVisitor.java
deleted file mode 100644
index 95a0d39..0000000
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledCallingVisitor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*****************************************************************************
- *
- * Copyright (c) 2017 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:
- * CEA LIST Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.moka.externalcontrol.controller;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.papyrus.moka.externalcontrol.advice.IControllerAdvice;
-import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;
-
-public abstract class AbstractExternallyControlledCallingVisitor<T extends ISemanticVisitor> extends AbstractExternallyControlledVisitor<T > {
-
-
- protected List<ISemanticVisitor> suspendedVisitors = new ArrayList<ISemanticVisitor>();
-
- public AbstractExternallyControlledCallingVisitor(T visitor, ExternalController controller, List<IControllerAdvice> advices) {
- super(visitor, controller, advices);
- }
-
-
-
-}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java
index 0896746..6837dc9 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/AbstractExternallyControlledVisitor.java
@@ -35,7 +35,6 @@
protected List<IToken> suspendedTokens;
- protected FUMLExecutionStack stack = new FUMLExecutionStack();
protected Set<AbstractExternallyControlledVisitor<? extends ISemanticVisitor>> suspendedChildren = new HashSet<AbstractExternallyControlledVisitor<? extends ISemanticVisitor>>();
@@ -52,8 +51,14 @@
protected abstract void doSemanticAction();
- protected abstract AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent();
+ public abstract IExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent();
+
+
+ @Override
+ public List<IControllerAdvice> getRegisteredAdvices() {
+ return advices;
+ }
public boolean hasSuspendedChildren(){
return ! suspendedChildren.isEmpty();
@@ -67,18 +72,20 @@
suspendedChildren.remove(child);
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
protected void resumeExecution(){
- AbstractExternallyControlledVisitor<? extends ISemanticVisitor> parent = getStackParent();
- if (parent != null){
- parent.removeSuspendedChild(this);
+ IExternallyControlledVisitor<? extends ISemanticVisitor> parent = getStackParent();
+ if (parent instanceof AbstractExternallyControlledVisitor){
+ ((AbstractExternallyControlledVisitor)parent).removeSuspendedChild(this);
}
doResumeExecution();
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
protected void suspendForControl() {
- AbstractExternallyControlledVisitor<? extends ISemanticVisitor> parent = getStackParent();
- if (parent != null){
- parent.addSuspendedChild(this);
+ IExternallyControlledVisitor<? extends ISemanticVisitor> parent = getStackParent();
+ if (parent instanceof AbstractExternallyControlledVisitor){
+ ((AbstractExternallyControlledVisitor)parent).addSuspendedChild(this);
}
controller.suspendForControl(this);
}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/FUMLExecutionStack.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/FUMLExecutionStack.java
deleted file mode 100644
index 26ecb30..0000000
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/FUMLExecutionStack.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*****************************************************************************
- *
- * Copyright (c) 2017 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:
- * CEA LIST Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.moka.externalcontrol.controller;
-
-import java.util.Stack;
-
-import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;
-
-public class FUMLExecutionStack extends Stack<AbstractExternallyControlledVisitor<? extends ISemanticVisitor>> {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
-}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/IExternallyControlledVisitor.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/IExternallyControlledVisitor.java
index 7dd363a..8490f55 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/IExternallyControlledVisitor.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/controller/IExternallyControlledVisitor.java
@@ -13,10 +13,12 @@
*****************************************************************************/
package org.eclipse.papyrus.moka.externalcontrol.controller;
+import java.util.List;
+
import org.eclipse.papyrus.moka.externalcontrol.advice.IControllerAdvice;
import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;
-public interface IExternallyControlledVisitor<T extends ISemanticVisitor> {
+public interface IExternallyControlledVisitor<T extends ISemanticVisitor> extends ISemanticVisitor{
public boolean isExecutionAllowed();
@@ -24,6 +26,8 @@
public void registerAdvice(IControllerAdvice advice);
+ public List<IControllerAdvice> getRegisteredAdvices();
+
public T getDelegatedVisitor();
public ExternalController getController();
@@ -31,4 +35,5 @@
public void setController(ExternalController controller);
public ControlledVisitorStep getState();
-}
+
+ }
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/AbstractExternallyControlledActionActivation.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/AbstractExternallyControlledActionActivation.java
index d211e28..de92753 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/AbstractExternallyControlledActionActivation.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/AbstractExternallyControlledActionActivation.java
@@ -63,7 +63,7 @@
@SuppressWarnings("unchecked")
@Override
- protected AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent() {
+ public AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent() {
IActivityExecution execution = getActivityExecution();
if (execution instanceof AbstractExternallyControlledVisitor<? >){
return (AbstractExternallyControlledVisitor<? extends ISemanticVisitor>) execution;
@@ -73,6 +73,8 @@
}
+
+
@Override
public void run() {
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java
index 4ed15de..c6f14a3 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternalControlExecutionFactory.java
@@ -20,6 +20,7 @@
import org.eclipse.papyrus.moka.externalcontrol.advice.IControllerAdvice;
import org.eclipse.papyrus.moka.externalcontrol.advice.IControllerAdviceFactory;
import org.eclipse.papyrus.moka.externalcontrol.controller.ExternalController;
+import org.eclipse.papyrus.moka.externalcontrol.controller.IExternallyControlledVisitor;
import org.eclipse.papyrus.moka.fuml.Semantics.Activities.IntermediateActivities.IActivityEdgeInstance;
import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.IExecutionFactory;
import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ISemanticVisitor;
@@ -71,23 +72,34 @@
ISemanticVisitor delegatedVisitor = delegatedExecutionFactory.instantiateVisitor(element);
-
+ IExternallyControlledVisitor<? extends ISemanticVisitor> controlledVisitor= null;
+
List<IControllerAdvice> adviceList = getControllerAdvices(element, delegatedVisitor);
if(delegatedVisitor instanceof ActivityExecution){
- return new ExternallyControlledActivityExecution((ActivityExecution)delegatedVisitor, controller, adviceList);
+
+ controlledVisitor= new ExternallyControlledActivityExecution((ActivityExecution)delegatedVisitor, controller, adviceList);
}else if (delegatedVisitor instanceof CallActionActivation) {
- return new ExternallyControlledCallActionActivation((CallActionActivation) delegatedVisitor, controller, adviceList);
+ controlledVisitor= new ExternallyControlledCallActionActivation((CallActionActivation) delegatedVisitor, controller, adviceList);
}
- if (!adviceList.isEmpty()) {
+ if (!adviceList.isEmpty()&& controlledVisitor == null) {
if (delegatedVisitor instanceof ActivityEdgeInstance) {
- return new ExternallyControlledActivityEdgeInstance((IActivityEdgeInstance) delegatedVisitor, controller, adviceList);
+ controlledVisitor= new ExternallyControlledActivityEdgeInstance((IActivityEdgeInstance) delegatedVisitor, controller, adviceList);
} else if (delegatedVisitor instanceof ActionActivation) {
- return new ExternallyControlledActionActivation((ActionActivation) delegatedVisitor, controller, adviceList);
+ controlledVisitor= new ExternallyControlledActionActivation((ActionActivation) delegatedVisitor, controller, adviceList);
}
}
+ if (controlledVisitor != null) {
+ for (IControllerAdvice advice : adviceList) {
+ advice.setControlledVisitor(controlledVisitor);
+ }
+
+ return controlledVisitor;
+ }
+
+
return delegatedVisitor;
}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityEdgeInstance.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityEdgeInstance.java
index 90da661..7819cbc 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityEdgeInstance.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityEdgeInstance.java
@@ -47,7 +47,7 @@
@SuppressWarnings("unchecked")
@Override
- protected AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent() {
+ public AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent() {
//TODO to be implemented
return null;
}
diff --git a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityExecution.java b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityExecution.java
index ee96617..95d075e 100644
--- a/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityExecution.java
+++ b/bundles/core/tools/org.eclipse.papyrus.moka.externalcontrol/src/org/eclipse/papyrus/moka/externalcontrol/semantics/ExternallyControlledActivityExecution.java
@@ -58,12 +58,12 @@
protected AbstractExternallyControlledVisitor<? extends ISemanticVisitor> stackParent;
@Override
- protected AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent() {
+ public AbstractExternallyControlledVisitor<? extends ISemanticVisitor> getStackParent() {
return stackParent;
}
//This operation is normally called by the ExternallyControlledCallActionActivation which created this execution
- protected void setStackParent(AbstractExternallyControlledVisitor<? extends ISemanticVisitor> parent) {
+ public void setStackParent(AbstractExternallyControlledVisitor<? extends ISemanticVisitor> parent) {
this.stackParent = parent;
}
@@ -76,6 +76,8 @@
// When this is complete, copy the values on the tokens offered by
// output parameter nodes to the corresponding output parameters.
Activity activity = (Activity) (this.getTypes().get(0));
+
+
Debug.println("[execute] Activity " + activity.getName() + "...");
// Debug.println("[execute] context = " + this.context.objectId());
Debug.println("[event] Execute activity=" + activity.getName());