Using EMF Resource to iterate over contents of model file [message #1779124] |
Wed, 03 January 2018 00:22  |
Eclipse User |
|
|
|
Hi,
I want to know if we can use EMF Resource to iterate over our model elements.
I have an ecore metamodel and a model that conforms to that metamodel. ResourceSet gives me the top most package but if I try to get the inner contents, it returns EClass instead of actual class.
I try below steps:
Resource resource = resourceSet.getResource(
URI.createURI("path to model file"), true);
ModelPackage mp = (ModelPackage) resource.getContents().get(0);
But it does not let me do this:
ModelSpec ms= (ModelSpec) mp.getModelSpec();
as mp.getModelSpec() is an EClassImpl (with name ModelSpec) and not ModelSpec. I want to further iterate over the contents of ModelSpec in my model file.
Note: ModelPackage is an EPackage in my ecore file and contains ModelSpec EClass.
|
|
|
|
|
Re: Using EMF Resource to iterate over contents of model file [message #1779211 is a reply to message #1779200] |
Thu, 04 January 2018 00:24   |
Eclipse User |
|
|
|
This looks kind of nonsensical. Firstly, I can only guess what "path of model" is, and that's the key detail. Secondly, unless you're running in a stand alone environment (not in an Eclipse/Equinox container), then resourceSet.getPackageRegistry().put("path of model",ModelPackage.eINSTANCE) is not needed, and if it were, you'd use the idiom ModelPackage.eINSTANCE.eClass() force the model to register itself in the global package registry, or you'd use resourceSet.getPackageRegistry().put(ModelPackage.eNSURI, ModelPackage.eINSTANCE) to register the model's namespace URI if there was some particular need to register it also in the resource set's package registry. Any call to resourceSet.getResource(<uri>, true), will return the resource of the generated model package if <uri> is equal to the eNSURI of any registered model, so no doubt what you're showing above will return the resource of the Ecore (meta) model not your instance model corresponding to that Ecore model. I imagine you want to be iterating over your instance model so you need to load that, (perhaps as you've shown, using a platform:/resource URI if you're running with an IWorkspace) and not map its URI to the Ecore model.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04493 seconds