
今天看到两种使用EMF解析.xml为EMF模型的策略:
一种是通过如下代码:
IFileEditorInput modelFile = (IFileEditorInput)getEditorInput();
URI resourceURI = URI.createPlatformResourceURI(modelFile.getFile().getFullPath().toString());;
resource = editingDomain.getResourceSet().getResource(resourceURI, true ); 上面这种方式会引用一个AdapterFactoryEditingDomain类,但我们基于模型做编辑器时,有时并不需要用这个类,例如GEF,它具有自身的EditorDomain。
IFileEditorInput modelFile = (IFileEditorInput)getEditorInput();
XMLProcessor processor = new DesignXMLProcessor();
resource = processor.load(new InputSource(new InputStreamReader(modelFile.getFile().getContents(), "GBK")), null);
<extension point="org.eclipse.emf.ecore.extension_parser">
<parser
type="design"
class="com.neusoft.report.design.util.DesignResourceFactoryImpl" />
</extension>