如何在 Java 中以编程方式合并 EMF 模型?
有没有办法在 Java 中以编程方式将多个 Ecore 模型(2 个或更多)组合到一个 Ecore 模型中?所有模型都符合相同的元模型。
输入:
Model1 conforming to metamodelX
Model2 conforming to metamodelX
model3 conforming to metamodelX
model4 conforming to metamodelX
model5 conforming to metamodelX
输出:
modelOut conforming to metamodelX and merge of Model1, Model2, model3, model4, model5 ...
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 ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个用于处理 EMF 比较和合并的 Eclipse 项目,称为 EMF Compare。
这是他们提供的示例:
这确实提供了非常好的方法来处理模型合并和其他比较内容。您也可以手动完成更改。
这是他们提供的完整示例: 此处
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
您需要定义“合并”对您意味着什么。您可以轻松地将所有 EMF 模型附加到同一资源并序列化它们。
您可能希望在 model1 和 model2 之间建立等效关系。找到 model1 和 model2 之间相等的一些对象。
在此之后,您可以找到差异。
例如:
匹配步骤建立以下等价关系:
此步骤之后是差异步骤:
使用这些差异,您可以将它们应用到你的模型。仅应用“ADDED”差异将为您提供以下模型:
由您来确定“合并”的业务规则。您首先必须确定两个实体何时相同(匹配)。这可以基于唯一的键、它们在树中的位置,或者基于许多其他事物,具体取决于您的元模型。
结果,您将得到一个“差异”列表。由您来定义要应用哪些差异。
如果您将“合并”视为 SVN 合并(即 Model1 = Model0 + 更改,Model2 = Model0 + 其他更改),则
MergeService
已包含执行此操作的所有业务规则。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.