今天看到两种使用emf解析.xml为emf模型的策略:
一种是通过如下代码:
ifileeditorinput modelfile = (ifileeditorinput)geteditorinput();
uri resourceuri = uri.createplatformresourceuri(modelfile.getfile().getfullpath().tostring());;
resource = editingdomain.getresourceset().getresource(resourceuri, true ); 另外一种方式是使用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中,代码片断如下图所示:
闽公网安备 35060202000074号