Chinaunix首页 | 论坛 | 博客
  • 博客访问: 820869
  • 博文数量: 780
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-12 09:11
文章分类

全部博文(780)

文章存档

2011年(1)

2008年(779)

我的朋友
最近访客

分类:

2008-09-12 09:14:50

今天看到两种使用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中,代码片断如下图所示:
  <extension point="org.eclipse.emf.ecore.extension_parser">
    
<parser 
       type
="design" 
       
class="com.neusoft.report.design.util.DesignResourceFactoryImpl" />
  
extension>

这样,解析.xml文件时,EMF从ResourceFactory注册中,根据相应的type,获取解析器(DesignResourceFactoryImpl),完成解析。
【责编:Peng】

--------------------next---------------------

阅读(247) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~