Resource being loaded twice [message #1415268] |
Tue, 02 September 2014 08:58  |
Eclipse User |
|
|
|
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 #1415343 is a reply to message #1415298] |
Tue, 02 September 2014 11:05   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05253 seconds