views:

274

answers:

1

I have a backend system which i access via a REST based API and i am returned a resource. This is an EMF resource (an XMI representation). The problem is that i cannot, at design time, assume the metamodel for this resource - as the metamodel in the backend system can change without notice.

I am wondering if i can, first, read the metamodel (the .ecore file) from the backend, generate the code and then, read the models. This will, admittedly, be slower, but i will have to read the metamodel only once per session and this will not make me commit to a fixed metamodel. Will this work? Or is there a better way to achieve what i want?

Also, will this work for the UI? Can i generate the editor code at runtime (EMF.Edit), just before reading the model from the backend and display the model with the appropriate visualization?

Would Dynamic EMF help solve my problem?

+1  A: 

Using EMF to generate code from models on the fly sounds hairy. Especially when you turn around and run it. But I guess it would work provided that you run it in a new Eclipse instance.

Dynamic EMF is a possible alternative. However applications that use the dynamic approach are more difficult to write and tend to require more debugging. (By using dynamic EMF you sacrifice a lot of static type safety.) And I'm not sure about the model editor issue.

Actually, I'm a little bit puzzled how you would use the generated Java classes for an in-memory model instance. If the metamodel is changing, then so are the signatures of the generated classes. How can you write code to work against an API that changes all the time? If you say "I generate it" consider that your generator has to use dynamic EMF.

If I were you, I'd ask on the EMF mailing lists. In my experience, if you ask sensible questions (i.e. that are not too speculative) you'll get reasonable answers.

Stephen C