Is there a way to combine multiple Ecore models (2 or more) in a single Ecore model programmatically in Java? With all models conform to the same metamodel.
In:
Model1 conforming to metamodelX
Model2 conforming to metamodelX
model3 conforming to metamodelX
model4 conforming to metamodelX
model5 conforming to metamodelX
Out:
modelOut conforming to metamodelX and merge of Model1, Model2, model3, model4, model5 ...
There is Eclipse project for handling EMF comparing and Merging, called EMF Compare.
Here is example provided by them:
This really provides very good ways to handle model merging and other compare stuffs. You can also manually go through the changes.
Here is full example provided by them: Here
You will need to define what 'merge' means to you. You can easily attach all EMF models to the same resource and serialize them.
You will probably want to establish equivalencies between model1 and model2. Find some objects which are equal between model1 and model2. After this, you can find the differences.
As an example:
The matching step establishes the following equivalencies:
After this step comes the differences step:
Using those differences, you can apply them to your model. Applying only the 'ADDED' difference gives you the following model:
It's up to you to determine the business rules of 'merging'. You will first have to determine when two entities are the same (matching). This can be based on a unique key, on their place in the tree, or based on a lot of other things, depending on your metamodel.
As a result, you will have a list of 'differences'. It's up to you to define which differences to apply.
If you see 'merge' as an SVN Merge (i.e. Model1 = Model0 + changes, Model2 = Model0 + other changes), then the
MergeService
already contains all business rules to do this.