本文介绍了从日食中的ecore文件中读取eobjects的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ecore文件,其中包含类eobjects.Now我想读取该ecore文件,并从该ecore文件中获取所有类eobjects。解决方案
您是否意味着要使用自定义后缀重新装载特定的xmi文件?
以下是一个加载ecore的方法的示例文件在特定位置(路径)并返回您的根EObject
public static EObject loadYourModel(String path){
/ * Initialzie Models * /
YourPackage.eINSTANCE.eClass();
/ *注册你的xmi资源* /
final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
final Map< String,Object> m = reg.getExtensionToFactoryMap();
/ *将所有不同的ecore文件后缀放在地图中; suffix = YourPackage.eNAME * /
m.put(YourPackage.eNAME,new XMIResourceFactoryImpl());
/ *您可以将所有不同的包名称放在这里* /
/ *创建一个新的资源集,以从文件中存储EObjects * /
ResourceSet resSet = new ResourceSetImpl );
/ *获取您的ecore文件的资源* /
资源资源= resSet.getResource(URI.createURI(path),true);
/ *获取您的模型的第一个元素= root hierachy * /
EObject root = resource.getContents()。get(0);
返回根;
}
I have the ecore file which contains the class eobjects.Now i want to read that ecore file and get all the class eobjects from that ecore file.
解决方案
Do you mean you want to reload your specific xmi file with a custom suffix?
Here is an example of a method that loads an ecore file at a specific location (path) and returns your root 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;
}
这篇关于从日食中的ecore文件中读取eobjects的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!