首页 > 学院 > 开发设计 > 正文

EMF模型解析的策略分析

2019-11-17 04:38:23
字体:
来源:转载
供稿:网友
今天看到两种使用EMF解析.xml为EMF模型的策略:
一种是通过如下代码:
Word-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">EMF模型解析的策略分析
IFileEditorInput modelFile  =  (IFileEditorInput)getEditorInput();
EMF模型解析的策略分析URI resourceURI  =  URI.createPlatformResourceURI(modelFile.getFile().getFullPath().toString());;
EMF模型解析的策略分析 resource  =  editingDomain.getResourceSet().getResource(resourceURI,  true );
上面这种方式会引用一个AdapterFactoryEditingDomain类,但我们基于模型做编辑器时,有时并不需要用这个类,例如GEF,它具有自身的EditorDomain。

另外一种方式是使用EMF模型自动生成的PRocess,该类一般在模型的Util包下面,引用代码如下:
EMF模型解析的策略分析IFileEditorInput modelFile = (IFileEditorInput)getEditorInput();        
EMF模型解析的策略分析XMLProcessor processor =  new DesignXMLProcessor();            
EMF模型解析的策略分析 resource = processor.load(new InputSource(new InputStreamReader(modelFile.getFile().getContents(), "GBK")), null);
EMF模型解析的策略分析        

其实,对于EMF而言,上面两种解释方式,归根到底都需要EMF获得 业务模型相关的解析器,对于第一种方式,EMF是如何获取到业务模型的解析器呢?主要是通过扩展的方式,扩展定义在模型的plugin.xml中,代码片断如下图所示:
EMF模型解析的策略分析  <extension point="org.eclipse.emf.ecore.extension_parser">
EMF模型解析的策略分析    <parser 
EMF模型解析的策略分析       type="design" 
EMF模型解析的策略分析       class="com.neusoft.report.design.util.DesignResourceFactoryImpl" />
EMF模型解析的策略分析  </extension>

这样,解析.xml文件时,EMF从ResourceFactory注册中,根据相应的type,获取解析器(DesignResourceFactoryImpl),完成解析。进入讨论组讨论。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表