Skip to main content
summaryrefslogtreecommitdiffstats
blob: c705d243fa0100e7fa177c26d2fa1769c25e5d74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.eclipse.papyrus.qompass.modellibs.core.bindinghelpers;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.FCM.util.IBindingHelper;
import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener;
import org.eclipse.papyrus.qompass.designer.core.templates.BindingUtils;
import org.eclipse.papyrus.qompass.designer.core.templates.TemplateUtils;
import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier;
import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException;
import org.eclipse.papyrus.qompass.modellibs.core.Activator;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.TemplateBinding;

/**
 * Bind an operation to an actual, i.e. evaluate the Acceleo template within the opaque behavior associated with
 * the operation.
 */
public class BindOperation implements IBindingHelper, PreCopyListener {

	private TemplateBinding binding;
	
	@Override
	public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) {
		
		if(sourceEObj instanceof Operation) {
			Operation operation = (Operation) sourceEObj;
			Classifier actual = TemplateUtils.getFirstActualFromBinding(binding);

			Operation newOperation = BindingUtils.instantiateOperation(copy, actual, operation);
			for(Behavior method : operation.getMethods()) {
				if(method instanceof OpaqueBehavior) {
					try {
						Behavior newBehavior =
							BindingUtils.instantiateBehavior(copy, actual, (OpaqueBehavior)method);
						newBehavior.setSpecification(newOperation);
					}
					catch (TransformationException e) {
						Activator.log.error(e);
					}
				}
			}
			return newOperation;
		}
		return sourceEObj;
	}

	@Override
	public void handleElement(TemplateBinding binding, Element object) {
		this.binding = binding;
	}
}

Back to the top