Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Recursive loading
Recursive loading [message #1043107] Wed, 17 April 2013 09:39 Go to next message
Mathieu MONTIN is currently offline Mathieu MONTINFriend
Messages: 26
Registered: October 2012
Junior Member
Hello everyone.

I'm currently working directly with EMF api.

When I load my model from an ecore file, it does not support references to other metamodels which is weird because when you load a model through eclipse itself, it does. How do I manage to load a model and all the models that are referenced inside (and recursively).

Thank's for you time.
Re: Recursive loading [message #1043174 is a reply to message #1043107] Wed, 17 April 2013 11:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Mathieu,

Load them into a resource set and be sure to use an absolute URI to load
the initial resource.


On 17/04/2013 11:39 AM, Mathieu MONTIN wrote:
> Hello everyone.
>
> I'm currently working directly with EMF api.
> When I load my model from an ecore file, it does not support
> references to other metamodels which is weird because when you load a
> model through eclipse itself, it does. How do I manage to load a model
> and all the models that are referenced inside (and recursively).
>
> Thank's for you time.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Recursive loading [message #1043202 is a reply to message #1043174] Wed, 17 April 2013 12:19 Go to previous messageGo to next message
Mathieu MONTIN is currently offline Mathieu MONTINFriend
Messages: 26
Registered: October 2012
Junior Member
Hello and thanks for your reply.

My code used to look like :
XMIResourceImpl model = new XMIResourceImpl(URI.createURI(pathname));
model.load(new HashMap<Object,Object>());

Now, it looks like :
ResourceSetImpl set = new ResourceSetImpl();
XMIResourceImpl model = (XMIResourceImpl) set.createResource(URI.createURI(pathname));

where pathname = ./example for instance.

In the first case, the model is loaded and works properly (but no recursive calls).
In the second case, the model is null even if the documentation of the method 'createResource' explicitely says that it's not possible.

This is the first time I'm loading a resource into a resourceSet (which should solve my initial problem) so maybe I've been mistaken somewhere.

Edit : concerning the absolute path, until now, my resource was successfully loaded with the path I wrote before, which is relative to the root of my project.

[Updated on: Wed, 17 April 2013 12:26]

Report message to a moderator

Re: Recursive loading [message #1043231 is a reply to message #1043202] Wed, 17 April 2013 12:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Mathieu,

Comments below.

On 17/04/2013 2:19 PM, Mathieu MONTIN wrote:
> Hello and thanks for your reply.
>
> My code used to look like :
> XMIResourceImpl model = new XMIResourceImpl(URI.createURI(pathname));
> model.load(new HashMap<Object,Object>());
So that's not using a resource set...
>
> Now, it looks like :
> ResourceSetImpl set = new ResourceSetImpl();
> XMIResourceImpl model = (XMIResourceImpl)
> set.createResource(URI.createURI(pathname));
>
> where pathname = ./example for instance.
That's not an absolute URI.
>
> In the first case, the model is loaded and works properly (but no
> recursive calls).
> In the second case, the model is null even if the documentation of the
> method 'createResource' explicitely says that it's not possible.
Because you haven't registered any resource factories.
> This is the first time I'm loading a resource into a resourceSet
> (which should solve my initial problem) so maybe I've been mistaken
> somewhere.
These are very basic questions. It doesn't seem as if you've read any
background information, not even the introductory overview.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Recursive loading [message #1043242 is a reply to message #1043231] Wed, 17 April 2013 13:09 Go to previous messageGo to next message
Mathieu MONTIN is currently offline Mathieu MONTINFriend
Messages: 26
Registered: October 2012
Junior Member
Sorry, I was not aware that I had to be an experimented user to post here.

Anyway, I did not register any factory because it was mentioned in the documentation that eclipse would use the default one if necessary, which should have worked considering that my file is a standard .ecore file.

After writing my previous message, I kept looking and finally tried to register the obvious factory (XMIResourceFactoryImpl). Looks like my model is not null anymore (as you already knew) but I keep thinking that it does not make any sense according to the documentation. It's not like I was trying to load a pdf file as an EMF resource.

That being said, I'll keep doing my tests to see if it actually worked the way I wanted. i just can't figure out why the path has to be absolute. But maybe this also is a basic question.

Thank you for your help anyway.

PS : I never said that my initial code was using resourceSets so I don't get your first comment.
Re: Recursive loading [message #1043264 is a reply to message #1043242] Wed, 17 April 2013 13:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Mathieu,

Comments below.

On 17/04/2013 3:09 PM, Mathieu MONTIN wrote:
> Sorry, I was not aware that I had to be an experimented user to post
> here.
No, but surely you can't expect that every single new inexperienced user
will get detailed information that's available in the FAQ and in
introductory material...
> Anyway, I did not register any factory because it was mentioned in the
> documentation that eclipse would use the default one if necessary,
> which should have worked considering that my file is a standard .ecore
> file.
Yes, if you run in an Eclipse environment, but you're running stand
alone aren't you?
> After writing my previous message, I kept looking and finally tried to
> register the obvious factory (XMIResourceFactoryImpl). Looks like my
> model is not null anymore (as you already knew) but I keep thinking
> that it does not make any sense according to the documentation. It's
> not like I was trying to load a pdf file as an EMF resource.
No, but it's not like you've looked at how the editor loads a resource
either...
>
> That being said, I'll keep doing my tests to see if it actually worked
> the way I wanted. i just can't figure out why the path has to be
> absolute. But maybe this also is a basic question.
You'll find I've explained that 100 times already in this newsgroup.
It's because relative cross document references can only be resolved
against an absolute URI to yet the absolute URI of the referenced
document...

> Thank you for your help anyway.
> PS : I never said that my initial code was using resourceSets so I
> don't get your first comment.
No, you didn't say much of anything so I had to guess at the common
mistakes, i.e., not using a resource set and not using an absolute URI.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Recursive loading [message #1043321 is a reply to message #1043264] Wed, 17 April 2013 14:58 Go to previous messageGo to next message
Mathieu MONTIN is currently offline Mathieu MONTINFriend
Messages: 26
Registered: October 2012
Junior Member
I've made my path absolute.

But still, linked models are not loaded.

For information I'm developping my application under an Eclipse platform.

You say that I did not say much, so feel free to ask for any further information.

I'll keep looking and post again here if I find anything interesting

[Updated on: Wed, 17 April 2013 15:01]

Report message to a moderator

Re: Recursive loading [message #1043330 is a reply to message #1043321] Wed, 17 April 2013 15:10 Go to previous message
Mathieu MONTIN is currently offline Mathieu MONTINFriend
Messages: 26
Registered: October 2012
Junior Member
Ok, I finally found a solution on an article somewhere on the web.

Thanks for your help.
Previous Topic:Alter the location and the background color of EditPart
Next Topic:[CDO] How CDO load the resources (models) in memory?
Goto Forum:
  


Current Time: Tue Mar 19 02:22:16 GMT 2024

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

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

Back to the top