【问题标题】:reading the eobjects from the ecore file in eclipse从eclipse中的ecore文件中读取eobjects
【发布时间】:2016-11-03 11:33:08
【问题描述】:

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

【问题讨论】:

    标签: eclipse eclipse-emf eclipse-emf-ecore


    【解决方案1】:

    您的意思是要重新加载带有自定义后缀的特定 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      相关资源
      最近更新 更多