服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 高级技术 > 设计模式 > 查看文档

emf模型解析的策略分析

今天看到两种使用emf解析.xml为emf模型的策略:
一种是通过如下代码:


ifileeditorinput modelfile  =  (ifileeditorinput)geteditorinput();
uri resourceuri 
=  uri.createplatformresourceuri(modelfile.getfile().getfullpath().tostring());;
resource  =  editingdomain.getresourceset().getresource(resourceuri,  true );
上面这种方式会引用一个adapterfactoryeditingdomain类,但我们基于模型做编辑器时,有时并不需要用这个类,例如gef,它具有自身的editordomain。

另外一种方式是使用emf模型自动生成的process,该类一般在模型的util包下面,引用代码如下:
ifileeditorinput modelfile = (ifileeditorinput)geteditorinput();        
xmlprocessor processor 
=  new designxmlprocessor();            
 resource 
= processor.load(new inputsource(new inputstreamreader(modelfile.getfile().getcontents(), "gbk")), null);
        

其实,对于emf而言,上面两种解释方式,归根到底都需要emf获得 业务模型相关的解析器,对于第一种方式,emf是如何获取到业务模型的解析器呢?主要是通过扩展的方式,扩展定义在模型的plugin.xml中,代码片断如下图所示:

扫描关注微信公众号