Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Do I need to generate the code of the meta model to explore/edit existing models
Do I need to generate the code of the meta model to explore/edit existing models [message #1811227] Thu, 29 August 2019 07:08 Go to next message
Afe Fer is currently offline Afe FerFriend
Messages: 8
Registered: August 2019
Junior Member
Hi,

This is more an academic/theoretical question.
Here is a scenario :
I want to devellop a tool (maybe a plugin) that edits models generated by other tools.
I dont know the exact meta model but I have the ecore file.
My tool does not need to generate any code. Just explore/edit models with respect to the ecore file.

In theory, I have all the necessaty elements I need to do this directly from the xmi file. right?
So I can imagine that there is already an API that takes the ecore file and generates a sort of parser for its models and I would (just) implement my tool to work directly with the xmi file.
Is there a such EMF API? (of course I dont want to explore the models files like xmi files)

Is it better to generate the code first and why? Because for me it seems like something complex because I have to save the generated code somewhere in my disk, import the packages dynamicaly, and use the reflective API to create every single object in the model and use reflection again to inspect it.

If you have any pointers to existing code that implemenst either solution, let me know please.

Thank you in advance

Re: Do I need to generate the code of the meta model to explore/edit existing models [message #1811232 is a reply to message #1811227] Thu, 29 August 2019 09:11 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
In general you do not need a generated model. But the data you read needs to (and does) specify the Ecore model(s) of the instance data. That's generally done via the namespace and generally the namespaces are registered in the EPackage.Registry.INSTANCE. However, the instance resource can be based on a dynamic Ecore model, in which case it will (generally must) specify the location of the Ecore model resource(s), using an xsi:schemaLocation attribute. In that case, the *.ecore models are read first, and then the instance resource is processed.

Regardless of how the instance resource is specified, the loaded resource's getContents() is just an list of EObjects, and for any EObject x, you can use x.eClass() to determine its Ecore model.

Generated models can represent the instances more efficiently and of course then you have an API against which you can develop and application. But most of the EMF infrastructure does not care whether there is a generated model or not, and base all behavior on the API available for EObject/InternalEObject.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to tell Ressource.getResource to look for the meta model in a local file
Next Topic:How to create genmodel from ecore programmatically without using headless invocation/eclipse plugins
Goto Forum:
  


Current Time: Fri Apr 26 07:14:53 GMT 2024

Powered by FUDForum. Page generated in 0.04481 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top