Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Creating EmfModel instance from Java objects instead of loading from file
Creating EmfModel instance from Java objects instead of loading from file [message #1802704] Thu, 14 February 2019 09:57 Go to next message
Kelsey Brennan is currently offline Kelsey BrennanFriend
Messages: 7
Registered: February 2019
Junior Member
Hello,

I would like to be able to build a model within my Java application and then execute EVL on it. I want to avoid the extra I/O work of serializing the model to a file and then loading it again. Is this possible, and if so, what does that code look like?

MetamodelFactoryImpl factory = new MetamodelFactoryImpl();
Book myBook = factory.createBook();

EmfModel myModel = new EmfModel();
// Some missing code here to put my book in the model

EvlModule module = new EvlModule();
module.parse(new URI("my/evl/path/here"));
module.getContext().getModelRepository().addModel(myModel);
Re: Creating EmfModel instance from Java objects instead of loading from file [message #1802754 is a reply to message #1802704] Fri, 15 February 2019 08:15 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2182
Registered: July 2009
Location: York, UK
Senior Member

Hi Kelsey,

You'll first need to add myBook to a resource as shown in section 14 of [1], and you can then use the code in [2] to wrap the resource as an Epsilon-compatible model.

Cheers,
Dimitris

[1] https://www.vogella.com/tutorials/EclipseEMF/article.html
[2] https://www.eclipse.org/epsilon/doc/articles/in-memory-emf-model/
Re: Creating EmfModel instance from Java objects instead of loading from file [message #1802755 is a reply to message #1802754] Fri, 15 February 2019 08:21 Go to previous messageGo to next message
Kelsey Brennan is currently offline Kelsey BrennanFriend
Messages: 7
Registered: February 2019
Junior Member
That's exactly what I needed, thank you!
Re: Creating EmfModel instance from Java objects instead of loading from file [message #1816009 is a reply to message #1802755] Thu, 17 October 2019 08:08 Go to previous messageGo to next message
Hans Peter is currently offline Hans PeterFriend
Messages: 4
Registered: October 2019
Junior Member
Hi,

I would like to know how you worked afterwards with your EMF model in EOL?
In java I have already my resource and my goal is to get specific informations like this:

ProjectImpl dataRoot = (ProjectImpl) resource.getContents().get(0);

EList<ModelRoot> modelRootList = dataRoot.getOwnedModelRoots();
			
SystemEngineeringImpl mr = (SystemEngineeringImpl)modelRootList.get(0);
EList<ModellingArchitecture> ma = mr.getOwnedArchitectures();
SystemAnalysisImpl sa = (SystemAnalysisImpl) ma.get(1);
ActorPkgImpl actor_pkg_impl = (ActorPkgImpl) sa.getOwnedActorPkg();
EList<Actor> actors = actor_pkg_impl.getOwnedActors();   // this is my goal in EOL


I added my model like this:
InMemoryEmfModel model = new InMemoryEmfModel(resource);
model.setName("capella_model");
module.getContext().getModelRepository().addModel(model);


But right now I have no clue of how I do get my informations in EOL if I pass my resource EmfModel...

I thought I had to this like so:
https://www.eclipse.org/forums/index.php/t/855628/

But this worked out in a 'Method 'eContents' not found for: EmfModel [name=capella_model]' error

Could you please advice me of how I have to do those steps from java in EOL

Regards,
Hans
Re: Creating EmfModel instance from Java objects instead of loading from file [message #1816036 is a reply to message #1816009] Thu, 17 October 2019 18:44 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2182
Registered: July 2009
Location: York, UK
Senior Member

Hi Hans,

Off the top of my head, I'd try something like this in EOL:

var dataRoot = Project.all.first();
var modelRootList = dataRoot.ownedModelRoots;
...


Does this help?

Cheers,
Dimitris
Previous Topic:Epsilon's automatic generation of code from UML diagrams
Next Topic:EOL/ ETL debugging Tools?
Goto Forum:
  


Current Time: Sun Sep 22 17:43:20 GMT 2024

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

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

Back to the top