Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325858 - [Wizard template] Incorrect creation of model template when stereotyped elements are present
Summary: [Wizard template] Incorrect creation of model template when stereotyped eleme...
Status: RESOLVED FIXED
Alias: None
Product: Papyrus
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Patrick Tessier CLA
QA Contact: David Servat CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-21 10:03 EDT by David Servat CLA
Modified: 2011-01-26 06:47 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Servat CLA 2010-09-21 10:03:32 EDT
When a template model features stereotyped elements, these are not correctly created in the model. A simple copy from the template model seems to be performed, see the following method in InitFromTemplateCommand from org.eclipse.papyrus.wizards.template:
	private void initializeFromTemplate() {
		Resource templateResource = loadTemplateResource();
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
		for(EObject eObject : templateResource.getContents()) {
			eObjectsToAdd.add(EcoreUtil.copy(eObject));
		}
		for(EObject eObject : eObjectsToAdd) {
			myModelResource.getContents().add(eObject);
		}
	}

This simple copy produces a model file where references inside the stereotype properties (both baseClass and link to other model elements) are made to the template model and not the model created!

For instance, template model:
  <SystemModeling:SystemModel xmi:id="_emKFUMVlEd-CvZir4IWNcw" implementationLevel="_iz8UYMVlEd-CvZir4IWNcw" analysisLevel="_iIbSMMVlEd-CvZir4IWNcw" designLevel="_igX4IMVlEd-CvZir4IWNcw" base_Class="_cX-WgMVlEd-CvZir4IWNcw"/>

Created model (check out the platform:/ links)
 <SystemModeling:SystemModel xmi:id="_fD4bwMVoEd-li4xgZl8l7Q">
    <implementationLevel href="platform:/plugin/org.eclipse.papyrus.eastadl/resources/templates/model.uml#_iz8UYMVlEd-CvZir4IWNcw"/>
    <analysisLevel href="platform:/plugin/org.eclipse.papyrus.eastadl/resources/templates/model.uml#_iIbSMMVlEd-CvZir4IWNcw"/>
    <designLevel href="platform:/plugin/org.eclipse.papyrus.eastadl/resources/templates/model.uml#_igX4IMVlEd-CvZir4IWNcw"/>
    <base_Class href="platform:/plugin/org.eclipse.papyrus.eastadl/resources/templates/model.uml#_cX-WgMVlEd-CvZir4IWNcw"/>
  </SystemModeling:SystemModel>
Comment 1 David Servat CLA 2011-01-26 06:47:35 EST
Bug is fixed with the use of 
		eObjectsToAdd = (List<EObject>)EcoreUtil.copyAll(templateResource.getContents());
in InitializeTemplateCommand instead of
		for(EObject eObject : templateResource.getContents()) {
			eObjectsToAdd.add(EcoreUtil.copy(eObject));
		}

What happens is that for profiled UML models, the resource contents are made of several eObjects, e.g. a Model and extra eObjects representing stereotypes, for instance SystemModel in an EASTADL model. The code used previously would deal with each eObject in turn, not building a complete HashMap of the keys/values for the whole file, thus references contained in the stereotypes were simply copied from the original file (default behavior when references are not found during the copy). The use of copyAll enables to trea the whole set of eObjects as a whole and keep track of all references. Which does the trick.