Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6a24ca6300393aa7d09dab6565a78723f54d5503 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
/*****************************************************************************
 * 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;

import java.io.IOException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.papyrus.FCM.Configuration;
import org.eclipse.papyrus.FCM.OperatingSystem;
import org.eclipse.papyrus.FCM.Target;
import org.eclipse.papyrus.FCM.util.MapUtil;
import org.eclipse.papyrus.acceleo.AcceleoDriver;
import org.eclipse.papyrus.codegen.extensionpoints.ILangSupport;
import org.eclipse.papyrus.codegen.extensionpoints.LanguageSupport;
import org.eclipse.papyrus.qompass.designer.core.Log;
import org.eclipse.papyrus.qompass.designer.core.Messages;
import org.eclipse.papyrus.qompass.designer.core.ModelManagement;
import org.eclipse.papyrus.qompass.designer.core.ProjectManagement;
import org.eclipse.papyrus.qompass.designer.core.StUtils;
import org.eclipse.papyrus.qompass.designer.core.Utils;
import org.eclipse.papyrus.qompass.designer.core.acceleo.EnumService;
import org.eclipse.papyrus.qompass.designer.core.deployment.AllocUtils;
import org.eclipse.papyrus.qompass.designer.core.deployment.DepCreation;
import org.eclipse.papyrus.qompass.designer.core.deployment.DepUtils;
import org.eclipse.papyrus.qompass.designer.core.deployment.Deploy;
import org.eclipse.papyrus.qompass.designer.core.deployment.DeployConstants;
import org.eclipse.papyrus.qompass.designer.core.extensions.InstanceConfigurator;
import org.eclipse.papyrus.qompass.designer.core.generate.GenerateCode;
import org.eclipse.papyrus.qompass.designer.core.generate.GenerationOptions;
import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterRuleApplication;
import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterStateMachines;
import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterTemplate;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.util.UMLUtil;

/**
 * This class executes all transformations during the instantiation of a
 * deployment plan, i.e. 1. The reification of connectors (including template
 * instantiation). This transformation targets a new model 2. Adding
 * get_p/connect_q operations to a class (transformation within same model) 3.
 * Remove all component types 4. distribute to nodes
 * 
 * @author ansgar
 * 
 */
public class InstantiateDepPlan {

	/**
	 * The location of the temporary model (relative to current project). TODO:
	 * make configurable?
	 */
	public static final String TEMP_MODEL_FOLDER = "tmpModel"; //$NON-NLS-1$

	/**
	 * Postfix of the temporary model (prefix = name of top-level package).
	 * TODO: make configurable?
	 */
	public static final String TEMP_MODEL_POSTFIX = "Tmp.uml"; //$NON-NLS-1$

	/**
	 * Progress monitor of Eclipse.
	 */
	protected IProgressMonitor monitor = null;

	protected int generationOptions;

	protected boolean generateCode;

	protected boolean generateCACOnly;

	protected Package srcModelComponentDeploymentPlan = null;

	protected Configuration configuration = null;

	protected IProject project;

	protected boolean modelIsObjectOriented = true;

	public void instantiate(Configuration configuration,
			IProgressMonitor monitor, IProject project, int genOptions) {
		this.configuration = configuration;
		srcModelComponentDeploymentPlan = configuration
				.getDeploymentPlan().getBase_Package();
		//
		if (srcModelComponentDeploymentPlan == null) {
			String message = String
					.format(Messages.InstantiateDepPlan_DepPlanStereotypeNotInitialized,
							configuration.getBase_Class().getName());
			displayError(Messages.InstantiateDepPlan_TransformationException,
					message);
		}

		this.project = project;
		if (project == null) {
			String projectName = configuration.getBase_Class().eResource()
					.getURI().toString();
			this.project = ResourcesPlugin.getWorkspace().getRoot()
					.getProject(projectName);
		}
		//
		instantiate(monitor, genOptions);
	}

	public void instantiate(Package pkg, IProgressMonitor monitor,
			IProject project, int genOptions) {
		configuration = null;
		srcModelComponentDeploymentPlan = pkg;
		//
		this.project = project;
		if (project == null) {
			String projectName = pkg.eResource().getURI().toString();
			this.project = ResourcesPlugin.getWorkspace().getRoot()
					.getProject(projectName);
		}

		//
		instantiate(monitor, genOptions);
	}

	/**
	 * Instantiate a deployment plan, i.e. generate an intermediate model via a
	 * sequence of transformations
	 * 
	 * @param umlElement
	 *            a deployment plan (UML package) or a configuration (UML class)
	 * @param monitor
	 *            a progress monitor.
	 * 
	 * @param project
	 *            the current project. This information is used to store the
	 *            intermediate model in a subfolder (tmpModel) of the current
	 *            project
	 * @param genOptions
	 *            select whether to produce an intermediate model only, also
	 *            code, ... @see GenerationOptions
	 */
	private void instantiate(IProgressMonitor monitor, int genOptions) {
		try {
			initialize(monitor, genOptions);
			AcceleoDriver.clearErrors();
			executeTransformation();
		} catch (AcceleoException e) {
			displayError(Messages.InstantiateDepPlan_AcceleoErrors,
					Messages.InstantiateDepPlan_AcceleoErrorsCheckLog);
		} catch (final TransformationException e) {
			printAndDisplayErrorMessage(e,
					Messages.InstantiateDepPlan_TransformationException, false);
		} catch (final Exception e) {
			printAndDisplayErrorMessage(e,
					Messages.InstantiateDepPlan_ErrorsDuringTransformation,
					true);
		}
	}

	private void initialize(IProgressMonitor monitor, int genOptions)
			throws TransformationException {
		this.monitor = monitor;
		this.generationOptions = genOptions;
		this.generateCode = (genOptions & GenerationOptions.MODEL_ONLY) == 0;
		this.generateCACOnly = (genOptions & GenerationOptions.CAC_ONLY) != 0;

		RuleManagement.setConfiguration(configuration);
	}

	protected void executeTransformation() throws Exception {
		modelIsObjectOriented = true;
		ModelManagement intermediateModelManagement = null;
		
		InstanceSpecification mainInstance = DepUtils
				.getMainInstance(srcModelComponentDeploymentPlan);
		EList<InstanceSpecification> nodes = AllocUtils
				.getAllNodes(mainInstance);

		initiateProgressMonitor(generateCode, nodes);

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		// 1a: create a new model (and applies same profiles / imports)
		Model existingModel = srcModelComponentDeploymentPlan.getModel();
		TransformationContext.sourceRoot = existingModel;

		intermediateModelManagement = createTargetModel(existingModel,
				existingModel.getName(), true);

		// Declare that the new model is a derivedElement (kind of hack,
		// since the source element (attribute of derive element) remains
		// undefined). This is used to deactivate automatic transformations
		// that should not be applied to the generated model.

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		// get the temporary model
		Model intermediateModel = intermediateModelManagement.getModel();
		
		// create a package for global enumerations that are used by Acceleo code
		EnumService.createEnumPackage(intermediateModel);
		
		// create a lazy copier towards the intermediate model
		LazyCopier intermediateModelCopier = new LazyCopier(existingModel, intermediateModel, false, true);
		// add pre-copy and post-copy listeners to the copier
		intermediateModelCopier.preCopyListeners.add(FilterTemplate.getInstance());

		// 1b: reify the connectors "into" the new model
		monitor.subTask(Messages.InstantiateDepPlan_InfoExpandingConnectors);

		// obtain the component deployment plan in target model
		Package intermediateModelComponentDeploymentPlan = (Package) intermediateModelCopier
				.shallowCopy(srcModelComponentDeploymentPlan);
		intermediateModelCopier.createShallowContainer(srcModelComponentDeploymentPlan);
		
		ContainerTrafo.init();
		InstanceConfigurator.onNodeModel = false;
		MainModelTrafo mainModelTrafo = new MainModelTrafo(intermediateModelCopier,
				intermediateModelComponentDeploymentPlan);
		InstanceSpecification newMainInstance = mainModelTrafo
				.transformInstance(mainInstance, null);

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		TransformationUtil.applyInstanceConfigurators(newMainInstance);

		FlattenInteractionComponents.getInstance().flattenAssembly(
				newMainInstance, null);

		TransformationUtil.propagateAllocation(newMainInstance);

		intermediateModelManagement.saveModel(project, TEMP_MODEL_FOLDER,
				TEMP_MODEL_POSTFIX);

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		if (!generateCACOnly) {
			deployOnNodes(mainInstance, existingModel, intermediateModel,
					newMainInstance);
		}

		intermediateModelManagement.dispose();

		if (AcceleoDriver.hasErrors()) {
			throw new AcceleoException();
		}

	}

	private void deployOnNodes(InstanceSpecification mainInstance,
			Model existingModel, Model tmpModel, InstanceSpecification newRootIS)
			throws TransformationException, InterruptedException {

		// not deploy on each node
		DepCreation.initAutoValues(newRootIS);

		EList<InstanceSpecification> nodes = AllocUtils.getAllNodes(newRootIS);
		if (nodes.size() > 0) {
			InstanceConfigurator.onNodeModel = true;
			for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++) {
				InstanceSpecification node = nodes.get(nodeIndex);

				deployNode(mainInstance, existingModel, tmpModel, newRootIS,
						nodes, nodeIndex, node);
			}
		} else {
			throw new TransformationException(
					Messages.InstantiateDepPlan_InfoNoneAllocated);
		}
	}

	private void deployNode(InstanceSpecification mainInstance,
			Model existingModel, Model tmpModel,
			InstanceSpecification newRootIS,
			EList<InstanceSpecification> nodes, int nodeIndex,
			InstanceSpecification node) throws TransformationException,
			InterruptedException {
		ModelManagement genModelManagement = createTargetModel(existingModel,
				MapUtil.rootModelName, false);
		Model generatedModel = genModelManagement.getModel();

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		// new model has name "root" and contains a package with the
		// existing model
		// Package originalRoot = genModel.createNestedPackage
		// (existingModel.getName ());
		LazyCopier targetCopy = new LazyCopier(tmpModel, generatedModel, true, true);
		// TODO: distribution to nodes is currently not done. How
		// can it be realized with a copy filter ?
		targetCopy.preCopyListeners.add(FilterStateMachines.getInstance());
		targetCopy.preCopyListeners.add(FilterRuleApplication.getInstance());

		monitor.setTaskName(String.format(
				Messages.InstantiateDepPlan_InfoDeployingForNode,
				node.getName()));

		ILangSupport langSupport = configureLanguageSupport(mainInstance,
				existingModel, node);

		Deploy deployment = new Deploy(targetCopy, langSupport, node,
				nodeIndex, nodes.size());
		InstanceSpecification nodeRootIS = deployment
				.distributeToNode(newRootIS);
		TransformationUtil.updateDerivedInterfaces(nodeRootIS);

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		removeDerivedInterfacesInRoot(generatedModel);

		CompImplTrafos.transform(
				deployment.getBootloader(), targetCopy, generatedModel,
				modelIsObjectOriented);

		// --------------------------------------------------------------------
		checkProgressStatus();
		// --------------------------------------------------------------------

		destroyDeploymentPlanFolder(generatedModel);

		if (generateCode) {
			GenerateCode codeGenerator = new GenerateCode(
					langSupport.getProject(), langSupport, genModelManagement,
					monitor);
			boolean option = (generationOptions & GenerationOptions.ONLY_CHANGED) != 0;
			codeGenerator.generate(node, getTargetLanguage(mainInstance),
					option);
		}

		genModelManagement.dispose();
	}

	private ILangSupport configureLanguageSupport(
			InstanceSpecification mainInstance, Model existingModel,
			InstanceSpecification node) throws TransformationException {
		ILangSupport langSupport = LanguageSupport
				.getLangSupport(getTargetLanguage(mainInstance));
		langSupport.resetConfigurationData();

		String modelName = getModelName(existingModel, node);
		IProject genProject = ProjectManagement.getNamedProject(modelName);
		if ((genProject == null) || !genProject.exists()) {
			genProject = langSupport.createProject(modelName, getTargetOS(node));
		} else {
			langSupport.setProject(genProject);
			if ((generationOptions & GenerationOptions.REWRITE_SETTINGS) != 0) {
				langSupport.setSettings(getTargetOS(node));
			}
		}
		return langSupport;
	}

	protected String getTargetOS(InstanceSpecification node) {
		Target target = UMLUtil.getStereotypeApplication(node, Target.class);
		if(target == null) {
			// get information from node referenced by the instance
			target = UMLUtil.getStereotypeApplication(DepUtils.getClassifier(node), Target.class);
		}
		if(target != null) {
			OperatingSystem os = target.getUsedOS();
			if(os != null) {
				return os.getBase_Class().getName();
			}
		}
		return null;
	}
	
	private void destroyDeploymentPlanFolder(Model generatedModel) {
		PackageableElement deploymentPlanFolder = generatedModel
				.getPackagedElement(DeployConstants.depPlanFolderHw);
		if (deploymentPlanFolder != null) {
			deploymentPlanFolder.destroy();
		}
	}

	private void removeDerivedInterfacesInRoot(Model generatedModel) {
		// 2b: remove derived interfaces in root: derived interfaces
		// that can not be placed in the same package as the port type (e.g.
		// since read-only type from system library), are put in a top-level
		// package called "derivedInterfaces". Due to the copying of imports,
		// the top-level package has changed which implies that new derived
		// interfaces are put into a different package and the derivedInterfaces
		// package in the original root becomes obsolete. Delete this obsolete
		// package, if existing.
		for (PackageableElement packagedElement : generatedModel
				.getPackagedElements()) {
			if (packagedElement instanceof Package) {
				NamedElement derivedInterfaces = ((Package) packagedElement)
						.getPackagedElement("derivedInterfaces"); //$NON-NLS-1$
				if (derivedInterfaces instanceof Package) {
					derivedInterfaces.destroy();
				}
			}
		}
	}

	private String getModelName(Model existingModel, InstanceSpecification node) {
		String modelName = existingModel.getName() + "_" + node.getName(); //$NON-NLS-1$
		if (configuration != null) {
			modelName += "_" + configuration.getBase_Class().getName(); //$NON-NLS-1$
		} else {
			modelName += "_" + srcModelComponentDeploymentPlan.getName(); //$NON-NLS-1$
		}
		return modelName;
	}

	private String getTargetLanguage(InstanceSpecification mainInstance) {
		Classifier cl = DepUtils.getClassifier(mainInstance);
		String targetLanguage = DepUtils.getLanguageFromPackage(cl
				.getNearestPackage());
		if (targetLanguage == null) {
			targetLanguage = "C++"; //$NON-NLS-1$
		}
		return targetLanguage;
	}

	private void initiateProgressMonitor(boolean generateCode,
			EList<InstanceSpecification> nodes) {
		// -- calc # of steps for progress monitor
		// 1 (tmpModel creation) + 1 (reification) + 1 (tmpModel save)
		// 5x on each deployed node (see below)
		// problem? Connector reification is a single, relatively long step
		int steps = 3;
		steps += 5 * nodes.size();
		if (generateCode) {
			steps += nodes.size();
		}
		monitor.beginTask(Messages.InstantiateDepPlan_InfoGeneratingModel,
				steps);
	}

	private void checkProgressStatus() throws InterruptedException {
		if (monitor.isCanceled()) {
			throw new InterruptedException();
		}
		monitor.worked(1);
	}

	private void printAndDisplayErrorMessage(Exception e, final String title,
			final boolean consultConsole) {
		String message = e.toString();
		if (consultConsole) {
			message = message + "\n\n" //$NON-NLS-1$
					+ Messages.InstantiateDepPlan_ConsultConsole;
		}

		printAndDisplayErrorMessage(e, title, message, consultConsole);
	}

	private void printAndDisplayErrorMessage(Exception e, final String title,
			final String message, final boolean consultConsole) {
		e.printStackTrace();
		displayError(title, message);
		Log.log(Status.ERROR, Log.DEPLOYMENT, "", e); //$NON-NLS-1$
	}

	private void displayError(final String title, final String message) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				Shell shell = new Shell();
				MessageDialog.openInformation(shell, title, message);
			}
		});
	}

	/**
	 * Create a new empty model from an existing model that applies the same
	 * profiles and has the same imports
	 * 
	 * @param existingModel
	 * @return
	 */
	public ModelManagement createTargetModel(Model existingModel, String name,
			boolean copyImports) throws TransformationException {
		ModelManagement mm = new ModelManagement();
		Model newModel = mm.getModel();
		newModel.setName(name);

		try {
			// copy profile application
			for (Profile profile : existingModel.getAppliedProfiles()) {
				// reload profile in resource of new model
				monitor.subTask(Messages.InstantiateDepPlan_InfoApplyProfile
						+ profile.getQualifiedName());

				if (profile.eResource() == null) {
					String profileName = profile.getQualifiedName();
					if (profileName == null) {
						if (profile instanceof MinimalEObjectImpl.Container) {
							URI uri = ((MinimalEObjectImpl.Container) profile)
									.eProxyURI();
							if (uri != null) {
								throw new TransformationException(
										String.format(
												Messages.InstantiateDepPlan_CheckInputModelProfileNoRes,
												uri));
							}
						}
						throw new TransformationException(
								Messages.InstantiateDepPlan_CheckInputModelProfileNoResNoName);
					}
					throw new TransformationException(
							String.format(
									Messages.InstantiateDepPlan_CheckInputModelProfile3,
									profileName));
				}

				Resource profileResource = null;
				try {
					profileResource = ModelManagement.getResourceSet()
							.getResource(profile.eResource().getURI(), true);
				} catch (WrappedException e) {
					// read 2nd time (some diagnostic errors are raised only
					// once)
					Log.log(Status.WARNING,
							Log.DEPLOYMENT,
							"Warning: exception in profile.eResource() " + e.getMessage()); //$NON-NLS-1$
					profileResource = ModelManagement.getResourceSet()
							.getResource(profile.eResource().getURI(), true);
				}
				Profile newProfileTop = (Profile) profileResource.getContents()
						.get(0);
				Profile newProfile;
				String qname = profile.getQualifiedName();
				if ((qname != null) && qname.contains("::")) { //$NON-NLS-1$
					// profile is a sub-profile within same resource
					// TODO: should Copy class copy profile applications?
					// Should be handled in shallowContainer class.
					// if we put profile/newProfile pair into copy map, copy
					// would find (and copy profile
					// applications in sub-folders
					qname = qname.substring(qname.indexOf("::") + 2); //$NON-NLS-1$
					newProfile = (Profile) Utils.getQualifiedElement(
							newProfileTop, qname);
				} else {
					newProfile = newProfileTop;
				}
				newProfile.getMember("dummy"); // force profile loading //$NON-NLS-1$
				newModel.applyProfile(newProfile);
			}
		} catch (IllegalArgumentException e) {
			throw new TransformationException(
					Messages.InstantiateDepPlan_IllegalArgumentDuringCopy
							+ e.toString());
		}

		// copy imports (and load resources associated - TODO: might not be
		// necessary)
		// While this is useful in general, it implies that code for imported
		// models
		// has been generated and compiled (for the right target) into a
		// library. This may be
		// quite tedious, unless automatically managed.
		// Therefore we do not activate this option in a first pass of the model
		// transformations.
		if (copyImports) {
			for (Package importedPackage : existingModel.getImportedPackages()) {
				if (importedPackage == null) {
					throw new TransformationException(
							Messages.InstantiateDepPlan_CheckInputImportPkg);
				}
				if (importedPackage.eResource() == null) {
					String errorMsg = Messages.InstantiateDepPlan_CheckInputImportPkgNoRes;
					if (importedPackage instanceof MinimalEObjectImpl.Container) {
						URI uri = ((MinimalEObjectImpl.Container) importedPackage)
								.eProxyURI();
						if (uri != null) {
							errorMsg += " - URI: " + uri.devicePath(); //$NON-NLS-1$
						}
					}
					throw new TransformationException(errorMsg);
				}
				newModel.createPackageImport(importedPackage);
				monitor.subTask(String.format(
						Messages.InstantiateDepPlan_InfoImportPackage,
						importedPackage.getName()));

				try {
					importedPackage.eResource().load(null);
					newModel.getMember("dummy"); // force loading of model //$NON-NLS-1$
				} catch (IOException e) {
					throw new TransformationException(e.getMessage());
				}

			}
		}

		StUtils.copyStereotypes(existingModel, newModel);

		return mm;
	}
}

Back to the top