简体   繁体   English

引用Ecore Eclasses。 是否可以从xmi实例引用eClasses?

[英]Referencing Ecore Eclasses. Is it possible to reference eClasses from xmi instances?

Is it possible to reference an eClass (meta-class in the ecore) from an instance (the model itself)? 是否可以从实例(模型本身)引用eClass(ecore中的元类)?

Let's suppose that I have an ecore meta-model M2.ecore containing a base class BASECLASS from which all the meta-classes (eClasses) derive. 让我们假设我有一个ecore元模型M2.ecore,它包含一个基类BASECLASS,所有的元类(eClasses)都派生自该类。 This is, BASECLASS is the superclass of all the eClasses of the M2.ecore meta-model. 也就是说,BASECLASS是M2.ecore元模型的所有eClasses的超类。 One of this classes called M, uses the BASECLASS, so there is an eReference between the eClass M and the BASECLASS: 其中一个名为M的类使用BASECLASS,因此eClass M和BASECLASS之间有一个eReference:

M2.ecore M2.ecore

ClassA ----inherits_from------|> BASECLASS
ClassM ----inherits_from------|> BASECLASS
ClassM ----uses-(eReference)---> BASECLASS

Then I have an instance INSTANCE_M of the eClass M that I want to link to eClasses of M2.ecore, for example: 然后我有一个eClass M的实例INSTANCE_M,我想链接到M2.ecore的eClasses,例如:

M2.xmi M2.xmi

INSTANCE_M -----eReference---> (M2.ecore).Class_A

This is, I want to link the classes of the meta-model. 这是,我想链接元模型的类。 Apparently, using the Sample Reflective Editor I can only link instances and never meta-classes. 显然,使用Sample Reflective Editor我只能链接实例而不能链接元类。

Why? 为什么? How to solve this problem? 如何解决这个问题呢?

Thank you in advance 先感谢您

First of all, I would say that your need goes (in a way) against the way EMF works. 首先,我会说你需要(在某种程度上)反对EMF的工作方式。 With EMF, you have a model defining some concepts (let's call it "metamodel") and its instances (let's call those "models"). 使用EMF,您有一个定义一些概念的模型(让我们称之为“元模型”)及其实例(让我们称之为“模型”)。 What you want is a model that would contain model elements and metamodel elements. 你想要的是一个包含模型元素和元模型元素的模型。 The concepts that can appear in your model, need to be defined in your metamodel but the metamodel is just a regular model. 可以在模型中出现的概念需要在元模型中定义,但元模型只是一个常规模型。 In a standard EMF workflow it is just an instance of the Ecore (meta) model and Ecore is also just an instance of an EMF model, itself. 在标准的EMF工作流程中,它只是Ecore(meta)模型的一个实例,Ecore也只是EMF模型的一个实例。 So you have this situation: 所以你有这种情况:

M2.xmi --instanceof--> M2.ecore --instanceof--> Ecore.ecore --instanceof--> Ecore.ecore... M2.xmi --instanceof - > M2.ecore --instanceof - > Ecore.ecore --instanceof - > Ecore.ecore ...

And you want in M2.xmi to manipulate instances of concepts defined in M2.ecore and instances of concepts defined in Ecore.ecore (one of those instances being your M2.ecore model). 并且您希望在M2.xmi中操作M2.ecore中定义的概念实例和Ecore.ecore中定义的概念实例(其中一个实例是您的M2.ecore模型)。

You can create you M2.ecore model as containing your concepts with for example an attribute "myMetaEntity" referencing a concept from Ecore.ecore. 您可以创建包含概念的M2.ecore模型,例如参考Ecore.ecore概念的属性“myMetaEntity”。 In the ecore editor, right click "load resource", then select from "registered packages" and select "http://www.eclipse.org/emf/2002/Ecore" and "Ok". 在ecore编辑器中,右键单击“load resource”,然后从“registered packages”中选择并选择“http://www.eclipse.org/emf/2002/Ecore”和“Ok”。 Once "imported", you can create references to elements from the Ecore.ecore model for example you can create an attribute myMetaEntity with the type "EClass". 一旦“导入”,您就可以创建Ecore.ecore模型中元素的引用,例如,您可以使用“EClass”类型创建属性myMetaEntity。 You can then use this to reference an EClass from the M2.ecore model but keep in mind that this attribute defined in M2.ecore would accept any instances of the "EClass" concepts even from M3.ecore or XYZ.ecore. 然后,您可以使用它来引用M2.ecore模型中的EClass,但请记住,M2.ecore中定义的此属性将接受来自M3.ecore或XYZ.ecore的“EClass”概念的任何实例。

If you just want a link from an instance to its metaclass you can use the method "eClass()" but if you really want to create "complex" links between instance elements and metaclasses you can't really, but you can create a metamodel importing the concepts from the meta-metamodel (I hate that name so much...), here Ecore.ecore, to gain the opportunity to manipulate both but it's also opening some kind of "pandora's box" because you can't say "you can manipulate instances of concept defined in Ecore.ecore only if those concepts are from M2.ecore". 如果您只想要一个从实例到其元类的链接,您可以使用方法“eClass()”,但如果您真的想在实例元素和元类之间创建“复杂”链接,那么您可能无法实现,但您可以创建一个元模型从meta-metamodel导入概念(我讨厌这个名字......),这里有Ecore.ecore,以获得操纵两者的机会,但它也打开某种“潘多拉盒子”,因为你不能说“只有当这些概念来自M2.ecore时,你才能操纵Ecore.ecore中定义的概念实例。

If you know what you are doing or if your users (or anyone not familiar with the subtlety of this problem) do not manipulate this because you will give them an API / an UI or something, you're fine but keep in mind you want to do something conceptually tricky (yet easy technically with EMF). 如果你知道自己在做什么,或者你的用户(或任何不熟悉这个问题的微妙之处的人)没有操纵这个,因为你会给他们一个API /一个用户界面或其他东西,你很好,但要记住你想要的做一些概念上棘手的事情(但在技术上很容易用EMF)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM