EmfModel creation from a Resource object? [message #1852845] |
Tue, 07 June 2022 10:32  |
Eclipse User |
|
|
|
I have set up some Java code which modifies a model dynamically, and then I want to operate upon this with EGX/EGL, generating new code based upon the dynamically generated model elements.
The model file example is:
@namespace(uri="TestingMM", prefix="TestingMM")
package TestingPackage;
class TestingSpace {
attr String name;
val Test[*] performedTests;
}
class Test {
attr String name;
}
The model is loaded as a Resource, from which I use Java objects (produced from a genmodel) to operate upon it and modify it dynamically by adding new Tests to the TestingSpace.
Then I save the modified Resource over its original file. The sub-optimal aspect is that when I call some code written by another author to generate EGL, this code (which loads it as an EmfModel object) involves reloading the file to create a new EmfModel object.
The ideal would be to obtain an EmfModel object and call EGX/EGL from the in-memory Resource object, to avoid having to reload it from disk in this code.
Is it possible to obtain an EmfModel object from an existing Resource object?
Thanks very much,
James
|
|
|
|
Re: EmfModel creation from a Resource object? [message #1852852 is a reply to message #1852850] |
Wed, 08 June 2022 00:27  |
Eclipse User |
|
|
|
There is EObject.eResource to get an instance's resource, which uses EObject.eContainer to walk upward until reaching the resource, and Resource.getResourceSet to get that Resource's resource set. And of course there is ResourceSet.getResources, Resource.getContents, and EObject.eContents, for going in the other direction (and even ResourceSet.getAllContents, Resource.getAllContents, and EObject.eAllContents for walking the entire tree. So you can always get what you need from the context or get the context from what you already have.
|
|
|
Powered by
FUDForum. Page generated in 0.04283 seconds