[英]Loading multiple xmi files with EMF
I've been using EMF for three weeks. 我已经使用EMF三周了。 I already created my meta-model and an instance using the running Eclipse application.
我已经使用正在运行的Eclipse应用程序创建了元模型和实例。 Now my problem is that I have multiple XMI files saved by the running instance of Eclipse and I want to parse them in order to create another text file processing the data in the xmi files.
现在的问题是,我正在运行的Eclipse实例保存了多个XMI文件,我想对其进行解析,以便创建另一个处理xmi文件中数据的文本文件。 To do so I'm using XMIResource API of EMF and when I load a file without cross-references to other xmi documents everything goes well.
为此,我使用的是EMF的XMIResource API,当我加载没有交叉引用到其他xmi文档的文件时,一切都会顺利进行。 However when I load a xmi document with cross-references to other xmi documents all the cross-references are not saved properly in my Java model.
但是,当我加载带有对其他xmi文档的交叉引用的xmi文档时,所有交叉引用都无法正确保存在我的Java模型中。
I used this piece of code to load the xmi files: 我使用这段代码来加载xmi文件:
XMIResource resourceInTy = new XMIResourceImpl(URI.createURI("file:/runtime-New_configuration/ApplicationInstance/instancesTypes.model"));
resourceInTy.load(null);
Environment env1 = (Environment) resourceInTy.getContents().get(0);
XMIResource resourceContRel = new XMIResourceImpl(URI.createURI("file:/runtime-New_configuration/ApplicationInstance/ContextRelations.model"));
resourceContRel.load(null);
Environment env2 = (Environment) resourceContRel.getContents().get(0);
env.setTypes(env1.getTypes());
env.setInstances(env1.getInstances());
env.setContextRelations(env2.getContextRelations());
As you can see the object "Environment" is my root object of all the meta-model that should contain all the EList objects properly set after I parse the xmi files. 如您所见,对象“ Environment”是所有元模型的根对象,该元模型应包含在解析xmi文件后正确设置的所有EList对象。
The problem here is that inside the EList "ContextRelations" there should be a reference to another object called "Parameter" that has a reference to the object Type. 这里的问题是,在EList“ ContextRelations”内部,应该有对另一个称为“ Parameter”的对象的引用,该对象具有对对象Type的引用。 If I try to retrieve type a null reference comes out!
如果我尝试检索类型,则会出现空引用! I deeply searched for another question about this problem but the closest one I found was a no-answered question available at this link: Loading Multiple files using EMF resource load?
我深入搜索了有关此问题的另一个问题,但我发现最接近的一个问题是此链接上没有可用的问题: 使用EMF资源加载来加载多个文件?
Here there are the two xmi files: ContextRelations.model 这里有两个xmi文件:ContextRelations.model
<parameters number="5">
<type href="instancesTypes.model#//@types.0"/>
</parameters>
<parameters number="6">
<type href="instancesTypes.model#//@types.4"/>
</parameters>
<contextRelations name="in"parameters="//@parameters.0//@parameters.1">
<initialComplexEvent href="Events.model#//@events.0"/>
<endingComplexEvent href="Events.model#//@events.1"/>
</contextRelations>
InstancesTypes.model InstancesTypes.model
<types name="Emp"/>
<types name="Cam"/>
<types name="Comp"/>
<types name="Fi"/>
<types name="Loc"/>
<types name="St"/>
<types name="Read"/>
<instances name="Alice" type="//@types.0"/>
<instances name="r01" type="//@types.4"/>
<instances name="Bob" type="//@types.0"/>
<instances name="cctv1" type="//@types.1"/>
<instances name="doc" type="//@types.3"/>
<instances name="m1" type="//@types.2"/>
<instances name="m2" type="//@types.2"/>
<instances name="m3" type="//@types.2"/>
<instances name="nfc01" type="//@types.6"/>
<instances name="usb1" type="//@types.5"/>
Secondary question: 次要问题:
As you can see I use three root objects: env1 and env2 are used as temporary variables that put their contents in the main root object (env). 如您所见,我使用三个根对象:env1和env2用作临时变量,将其内容放入主根对象(env)。 I do that because I don't know how to parse all the xmi files simultaneously creating just one root object.
之所以这样做,是因为我不知道如何解析所有xmi文件,而仅创建一个根对象。
Anybody can help me please? 有人可以帮我吗?
I solved the problem thanks to this web page: http://www.bar54.de/2012/04/emf-load-model-with-eproxyuri-references/ 我通过此网页解决了问题: http : //www.bar54.de/2012/04/emf-load-model-with-eproxyuri-references/
Basically I had to create a resource set putting all the resources inside the set in order to solve the proxies (cross-references). 基本上,我必须创建一个资源集,将所有资源放入集合中以解决代理(交叉引用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.