Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Resource being loaded twice(Resource being loaded twice due to difference in the URIs)
Resource being loaded twice [message #1415268] Tue, 02 September 2014 12:58 Go to next message
Harivansh Kumar is currently offline Harivansh KumarFriend
Messages: 3
Registered: September 2014
Junior Member
Hi,

Please pardon me if this has already been answered. I have searched for some time and could not find a possible post for the same. If this has already been answered somewhere, I would be grateful if some one could point me in right direction.

Here is the what issue I am facing :

Using the following code to load some emf models :

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
new XMIResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new
XMIResourceFactoryImpl());

URI testURI = URI.createFileURI(<local_file_path_to_emf_model>);

XMIResource resource = (XMIResource) resourceSet.createResource(resURI);
.....
resource.load(myMap);
// resolves and loads the linked models and adds them to resourceSet.
EcoreUtil.resolveAll(resource.getResourceSet());


I have a scenario where I have two models A & B. A has references to B and B has references to A. So, it forms cyclic references.

When I provide model A as input to above code, it resolves references to model B perfectly, but since B has references to A, model A is loaded twice. When I digged deeper to figure why is this happening, found out this is due to different URIs for input model A and referenced model B, the difference being the escaping of the space in model name.

Input model A has the following URI :
C:/model%20A.xyz

while the referenced model A has the following URI :
C:/model A.xyz

To resolve this, I have been trying, unsuccessfully so far, to find a way to create URI for input model such that its represented in same form as for referenced model.

Any help would be much appreciated.


- Thanks
Harry
Re: Resource being loaded twice [message #1415297 is a reply to message #1415268] Tue, 02 September 2014 14:26 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
It's loaded twice because technically it's two different URIs. (Or even
more strict, one isn't even valid..)

Fix the references to the unescaped "model A" in model B and you're done
and fix the place where those unescaped uris were produced.

(You can also use the ResourceSet uri converter to have model A point to
model%20A, but that's kind of hacky no?)

Felix
Re: Resource being loaded twice [message #1415298 is a reply to message #1415268] Tue, 02 September 2014 14:27 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 02/09/2014 16:04, Harivansh Kumar wrote:

> XMIResource resource = (XMIResource) resourceSet.createResource(resURI);

And here you should better use resourceSet.getResource(...). Create will
always create a new one, even if one with the same uri already exists.
Re: Resource being loaded twice [message #1415343 is a reply to message #1415298] Tue, 02 September 2014 15:05 Go to previous messageGo to next message
Harivansh Kumar is currently offline Harivansh KumarFriend
Messages: 3
Registered: September 2014
Junior Member
Thanks for reply Felix.

Yes you are right, technically they are two different URIs owing to the presence of "%20".

Regarding fixing the model, that's not a possibility at the moment. Model generation is not under my control and hence, can't fix the references in "model B". Is there any other work around ? I have thought about removing the resources from resourceSet if they have the same URIs (using toFileString() method of URI).

About your other comment of using getResource(...), I think I was not clear enough with the usage. Here is how it works :

1. Supply input model to above code.
2. Create a resource using createResource using the URI created from input model path.
3. Use EcoreUtil.resolveAll(...) to resolve all the references made by the model A. (This also resolves the references from referenced model, i.e., resolves the references of model B to C, in case we had C too).
4. Go over objects in resultant ResourceSet and do some processing with each and every object.

I think it basically boils down to my questioning how the two resources are differentiatedin EcoreUtil.resolveAll(...) method and eventually loaded. I am guessing using their URIs. Hence, based on my assumption, I am trying to see if there is a way I can force the code to treat "URI with %20" and "URI without %20" to be identical for my particular case. Or better yet, I don't create the first URI (in step 2) which does not contain any "%20" at all.

I hope this sheds some more light.

- Thanks
Re: Resource being loaded twice [message #1415372 is a reply to message #1415343] Tue, 02 September 2014 16:14 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 02/09/2014 17:05, Harivansh Kumar wrote:


> Hence, based on my assumption, I
> am trying to see if there is a way I can force the code to treat "URI
> with %20" and "URI without %20" to be identical for my particular case.

Maybe a custom ResourceSet uri converter can help.

> Or better yet, I don't create the first URI (in step 2) which does not
> contain any "%20" at all.

IIRC, instead of using URI.createFileURI(), you use
URI.createURI(String) and nothing will be encoded..

Felix
Re: Resource being loaded twice [message #1415405 is a reply to message #1415372] Tue, 02 September 2014 17:58 Go to previous message
Harivansh Kumar is currently offline Harivansh KumarFriend
Messages: 3
Registered: September 2014
Junior Member
I took your advice and looked into using createURI(String) method instead. Used it as it is with model file absolute path as input, and got a malformedurlexception. Digged further and figured the string argument to createURI(...) method must have a protocol defined as well, for example "file". Hence, appended "file:/" to model file absolute path and passed the resulting string as argument to createURI(String) method. Voila! It worked. It did not encode the input model URI and identified the referenced one as duplicate and did not process it again.

Thanks a lot for your help Felix. Much appreciated Smile
Previous Topic:CDO integrate in Eclipse Luna
Next Topic:JET - Understanding @start and @end
Goto Forum:
  


Current Time: Sat Apr 20 16:17:38 GMT 2024

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

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

Back to the top