[EMF Compare] Comparing models without resources [message #620975] |
Sun, 24 May 2009 03:27 |
Patrick Konemann Messages: 116 Registered: July 2009 |
Senior Member |
|
|
Cheers,
I wonder if it is at all possible to compare just two in-memory models with EMF Compare?
Regarding the API, it should be, since MatchService.doMatch takes EObjects and not Resources.
However, the match engine uses the resources (which are not set in the example below) to perform the comparison.
My use case is a comparison of partial models, i.e. the compared EObjects are contained in another, larger model.
For example, two sub-packages in a UML model.
Any suggestions and comments are appreciated.
Patrick
// this creates two simple EObjects for comparison, but a NullPointer is raised because the resources are not set
MatchService.doMatch(createDynamicObject("a"), createDynamicObject("b"), Collections.<String, Object> emptyMap());
/** Just to create a simple EObject just having a name. */
private EObject createDynamicObject(String name) {
// create the wrapper containment reference
final EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
attr.setName("name");
attr.setEType(EcorePackage.Literals.ESTRING);
// create the wrapper class
final EClass namedClass = EcoreFactory.eINSTANCE.createEClass();
namedClass.setName("DynamicNamedElement");
namedClass.getEStructuralFeatures().add(attr);
// create a package for our wrapper class
final EPackage simplePackage = EcoreFactory.eINSTANCE.createEPackage();
simplePackage.setName("dynamic");
simplePackage.setNsPrefix("dynamic");
simplePackage.setNsURI("http://www.example.org/dynamic");
simplePackage.getEClassifiers().add(namedClass);
// validate what we just created
if (Diagnostician.INSTANCE.validate(simplePackage).getCode() == Diagnostic.OK) {
// instantiate our class, fill the children and return it
final EObject namedClassInstance = simplePackage.getEFactoryInstance().create(namedClass);
namedClassInstance.eSet(attr, name);
return namedClassInstance;
} else {
return null; // TODO: better error handling required here
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.01739 seconds