Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 02a492bb162db82f7b72d6c9d122f090aa79b307 (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
56
/*****************************************************************************
 * Copyright (c) 2013 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:
 *  Ansgar Radermacher  ansgar.radermacher@cea.fr  
 *
 *****************************************************************************/

package org.eclipse.papyrus.qompass.designer.core.transformations.filters;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.qompass.designer.core.Utils;
import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener;
import org.eclipse.papyrus.qompass.designer.core.sync.CompImplSync;
import org.eclipse.papyrus.qompass.designer.core.transformations.Copy;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;

/**
 * Synchronize derived realizations (after copying). If re-synchronization is not done, the
 * relationship would point to wrong interface, if it is derived and depending on a formal parameter. 
 * (e.g. derived push interface with formal parameter T would be at wrong location).
 * TODO: need better explanation. Solution is quite a hack.
 */
public class FixTemplateSync implements CopyListener {

	public static FixTemplateSync getInstance() {
		if(instance == null) {
			instance = new FixTemplateSync();
		}
		return instance;
	}

	public EObject copyEObject(Copy copy, EObject targetEObj) {
		// if (copy.get(sourceEObj) isWithinTemplate)
		if (!(targetEObj instanceof Behavior)) {
			if((targetEObj instanceof Class) && Utils.isCompImpl((Class)targetEObj)) {
				Class implementation = (Class)targetEObj;
				CompImplSync.updatePorts(implementation);
				CompImplSync.syncRealizations(implementation);
				// commented out, since it causes dangling references
				// TODO: why needed originally? (
				// CompImplSync.syncDerivedOperations(implementation);
			}
		}
		return targetEObj;
	}

	private static FixTemplateSync instance = null;
}

Back to the top