Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EmfModel creation from a Resource object?
EmfModel creation from a Resource object? [message #1852845] Tue, 07 June 2022 14:32 Go to next message
James Harbin is currently offline James HarbinFriend
Messages: 3
Registered: June 2022
Junior Member
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 #1852850 is a reply to message #1852845] Tue, 07 June 2022 19:30 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Certainly.

Provided both producer and consumer are packaged as 'subroutines' that can be called from a shared main program, the consumer should be able to use the produced Resource in its ResourceSet, rather than create a new Resource in a new ResourceSet.

Regards

Ed Willink
Re: EmfModel creation from a Resource object? [message #1852852 is a reply to message #1852850] Wed, 08 June 2022 04:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
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.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Mixing UUIDs and positional identifiers in one model
Next Topic:Problem starting wizard in generated editor plugin. Unable to instantiate
Goto Forum:
  


Current Time: Thu May 02 11:18:15 GMT 2024

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

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

Back to the top