Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Diff/Merge » How do I force the merge of all attributes in a UML file?
How do I force the merge of all attributes in a UML file? [message #1727954] Tue, 29 March 2016 19:12 Go to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
In a model I have de following elements:
<ownedOperation xmi:id="_kkNnkOYZEeW6MLHFLMalQA" name="withdrawWithoutLimit">
<ownedParameter xmi:id="_kkNnkeYZEeW6MLHFLMalQA" name="amount" type="__EEsJH-OEeO41f7pJZDqVw"/>
</ownedOperation>

This element has the properties id, name, and one has type. But after merge this elements of one model to another model the result has only id properties, like this:

<ownedOperation xmi:id="_kkNnkOYZEeW6MLHFLMalQA">
<ownedParameter xmi:id="_kkNnkeYZEeW6MLHFLMalQA"/>
</ownedOperation>

How do I force all properties being merged?
I have been using diffmerge programmatic.
Re: How do I force the merge of all attributes in a UML file? [message #1728045 is a reply to message #1727954] Wed, 30 March 2016 14:51 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
Hello Wesley,

I cannot reproduce the problem. Can you provide more information about your environment: version of Eclipse, of UML, of EMF Diff/Merge, and what UML editor/modeler you are using if any. A precise reproduction scenario (merge steps, match/diff/merge policies) would also be useful.
Re: How do I force the merge of all attributes in a UML file? [message #1728057 is a reply to message #1728045] Wed, 30 March 2016 16:20 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
My environment is:
Eclipse Modeling Tools, Version: Kepler Service Release 2, Build id: 20140224-0627
EMF-DiffMerge-0.5.0.v20150608-0931
mdt-uml2-Update-5.1.2

Here is the code I am using:

IEditableModelScope referenceScope = new FragmentedModelScope(reference, false);
IEditableModelScope targetScope = new FragmentedModelScope(target, false);
IComparison comparison = new EComparisonImpl(targetScope, referenceScope);
comparison.compute(null, null, null, null);		
Collection<IDifference> diffsReference = comparison.getDifferences(Role.REFERENCE);
Collection<IDifference> diffs = comparison.merge(diffsReference, Role.TARGET, true, null);


Attached you will find an image with the differences between the two UML files.
Re: How do I force the merge of all attributes in a UML file? [message #1728292 is a reply to message #1728057] Fri, 01 April 2016 16:24 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
How exactly did you proceed to install mdt-uml2-Update-5.1.2 on Kepler Modeling SR2? Did you specify additional update sites?
Re: How do I force the merge of all attributes in a UML file? [message #1728312 is a reply to message #1728292] Fri, 01 April 2016 20:15 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
I am using it as external jar file. In the image you can see with jars I am using.
Re: How do I force the merge of all attributes in a UML file? [message #1728572 is a reply to message #1728312] Tue, 05 April 2016 13:46 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
Just to confirm that the core behavior is OK: if you execute "EObject myCopy = EcoreUtil.copy(<your_UML_operation>);", does myCopy have its name properly set?
Re: How do I force the merge of all attributes in a UML file? [message #1728596 is a reply to message #1728572] Tue, 05 April 2016 17:27 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
To test if it is working I got the EObject from differences I have. I've used the following code:


comparison.compute(null, null, null, null);
Collection<IDifference> diffsReference = comparison.getDifferences(Role.REFERENCE);

for (IDifference d : diffsReference) {
	System.out.print("Current: ");
	System.out.println( ((AnyTypeImpl) ((EElementPresenceImpl)d).getElement()).toString() );
	
	
	EObject myCopy = EcoreUtil.copy( ((EElementPresenceImpl)d).getElement() );
	System.out.print("copy: ");
	System.out.println( myCopy.toString() );
}


An excerpt of the output:

Current: org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@44d52de2 (mixed: [ecore.xml.type:text=
        , ownedParameter=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@95e33cc (mixed: [], anyAttribute: [name=amount, type=__EEsJH-OEeO41f7pJZDqVw]), ecore.xml.type:text=
      ], anyAttribute: [name=withdrawWithoutLimit])
copy: org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@61fe30 (mixed: [ecore.xml.type:text=
        , ownedParameter=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@c9d0d6 (mixed: [], anyAttribute: [name=amount, type=__EEsJH-OEeO41f7pJZDqVw]), ecore.xml.type:text=
      ], anyAttribute: [name=withdrawWithoutLimit])


It copies all the properties.

Re: How do I force the merge of all attributes in a UML file? [message #1728841 is a reply to message #1728572] Thu, 07 April 2016 19:01 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
Some data is being missed during the merging process:

Original EObject:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@194fad1 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@45d84a20 (name: Class) (instanceClassName: null) (abstract: false, interface: false)) (mixed: [], anyAttribute: [name=Consortium])

EObject After merging:
packagedElement=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@1187c9e8 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@45d84a20 (name: Class) (instanceClassName: null) (abstract: false, interface: false)) (mixed: null, anyAttribute: null)]


You can see that the elements are the same "org.eclipse.emf.ecore.impl.EClassImpl@45d84a20", but there are no values for mixed and anyAttribute properties.
Re: How do I force the merge of all attributes in a UML file? [message #1729348 is a reply to message #1728841] Wed, 13 April 2016 09:41 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
Sorry for the delay. It seems that when you load the UML model, it is not recognized as such but only as XML data. Elements are of type AnyType whereas they should be of type Class, Operation, etc. I am rather confident that this is the cause of the problem. Does the model originate from an export by a proprietary UML tool? If you create a UML model from scratch with the Eclipse UML APIs (UMLFactory.eINSTANCE.createModel(), etc.), serialize it, then open it in a text editor, does it look the same as the UML model files you are trying to merge? In particular, are the XML headers identical?
Re: How do I force the merge of all attributes in a UML file? [message #1729560 is a reply to message #1729348] Fri, 15 April 2016 13:41 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
I have been using UML examples available on this web page: https://github.com/but4reuse/but4reuse/wiki/Examples (Banking System UML model variants)

To load de resources the code is:
	
public static Resource getResourceUML(URI uri) {
		try {
			ResourceSet rs = new ResourceSetImpl();
			rs.getPackageRegistry().put(UMLPackage.eNS_URI,
					UMLPackage.eINSTANCE);
			rs.getResourceFactoryRegistry()
					.getExtensionToFactoryMap()
					.put(UMLResource.FILE_EXTENSION,
							UMLResource.Factory.INSTANCE);

			Resource resource = rs.getResource(uri, true);

			resource.load(null);
			return resource;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}


I have done some tests to load de model differently, but without success. How do you recommend to load de models?
Re: How do I force the merge of all attributes in a UML file? [message #1729568 is a reply to message #1729560] Fri, 15 April 2016 14:36 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
There seems to be some initialization behavior missing. You may want to have a look at this: http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F
Re: How do I force the merge of all attributes in a UML file? [message #1729570 is a reply to message #1729568] Fri, 15 April 2016 14:54 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
Other than that, what seems strange to me is that you are using all required bundles are jar libraries of a standalone Java application, including Equinox itself. While EMF and MDT UML2 can be used in standalone Java applications, there seems to be a deeper dependency to the Eclipse platform in your case. You may thus consider creating a headless RCP application instead of a Java application, so you can cleanly manage your dependencies as bundles (plug-ins) and more easily prevent issues related to the consistency of the whole. Unless the fix suggested above is enough to solve your problem. Razz
Re: How do I force the merge of all attributes in a UML file? [message #1731563 is a reply to message #1729570] Fri, 06 May 2016 19:27 Go to previous messageGo to next message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
I have tryed to load the model using the instructions you recomend, but it is still not working.

Whe I use the following piece of code (UMLResource) it returns an exception: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with uri 'http://www.eclipse.org/uml2/4.0.0/UML' not found. (file:///home/wesley/workspaceMars/br.ufpr.inf.gres.ModelMerge/model/Bank_1.uml, 2, 179)

try {
	ResourceSet resourceSet = new ResourceSetImpl();
	resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
	Map<URI,URI> uriMap = resourceSet.getURIConverter().getURIMap();
	URI uri = URI.createURI("jar:file:/home/wesley/eclipseMars/plugins/org.eclipse.uml2.uml.resources_5.1.0.v20160201-0816.jar!/");
	uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
	uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
	uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
	
	UMLResource resource = new UMLResourceImpl(uriModel);
	resource.load(uriMap);
			
	return resource;
} catch (Exception e) {
	e.printStackTrace();
	return null;
}


When I use the Resouce class it return elements of org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl.

try {
	ResourceSet resourceSet = new ResourceSetImpl();
	resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
	Map<URI,URI> uriMap = resourceSet.getURIConverter().getURIMap();
	URI uri = URI.createURI("jar:file:/home/wesley/eclipseMars/plugins/org.eclipse.uml2.uml.resources_5.1.0.v20160201-0816.jar!/");
	uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
	uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
	uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
	
	Resource resource = resourceSet.getResource(uriModel, true);
	resource.load(uriMap);
			
	return resource;
} catch (Exception e) {
	e.printStackTrace();
	return null;
}


The above code returns:
org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@305ffe9e uri='model/Bank_1.uml'
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@15043a2f (eClass: org.eclipse.emf.ecore.impl.EClassImpl@4a83a74a (name: Model) (instanceClassName: null) (abstract: false, interface: false)) (mixed: [ecore.xml.type:text=...
Re: How do I force the merge of all attributes in a UML file? [message #1731685 is a reply to message #1729348] Mon, 09 May 2016 09:09 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 89
Registered: January 2012
Member
The message indicates that your model was serialized with uml2 4.0.0 and that the corresponding metamodel was not found in your application. The version you have in your application is uml2 5.1.0. So it seems you need to either align the metamodel versions, or migrate your models to 5.1.0.
Re: How do I force the merge of all attributes in a UML file? [message #1732018 is a reply to message #1731685] Wed, 11 May 2016 19:22 Go to previous message
Wesley Klewerton is currently offline Wesley KlewertonFriend
Messages: 11
Registered: March 2016
Junior Member
Olivier, after following all recommendations you kindly gave me it finally works! Thanks.
Previous Topic:How to use DiffMerge/Patterns
Next Topic:How to get the common elements between two models
Goto Forum:
  


Current Time: Tue Feb 20 21:25:38 GMT 2018

Powered by FUDForum. Page generated in 0.02715 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software