繁体   English   中英

在eclipse中从ecore文件读取eobject

[英]reading the eobjects from the ecore file in eclipse

我有一个包含类eobjects的ecore文件。现在,我想读取该ecore文件并从该ecore文件中获取所有类eobjects。

您是说要用自定义后缀重新加载特定的xmi文件吗?

这是在特定位置(路径)加载ecore文件并返回根EObject的方法的示例

public static EObject loadYourModel(String path) {
    /*Initialzie Models*/
    YourPackage.eINSTANCE.eClass();

    /*register your xmi resources*/
    final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> m = reg.getExtensionToFactoryMap();
    /*put all your different ecore file suffixes in the map; suffix = YourPackage.eNAME*/
    m.put(YourPackage.eNAME, new XMIResourceFactoryImpl());
    /*you can put all different package names here*/

    /*Create a new Resource set to store the EObjects from the file*/
    ResourceSet resSet = new ResourceSetImpl();

    /*get the resource of your ecore file*/
    Resource resource = resSet.getResource(URI.createURI(path), true);
    /*Get the first element = root of your model hierachy*/
    EObject root = resource.getContents().get(0);
    return root;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM