Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ResourceSet and relative path problem
ResourceSet and relative path problem [message #544043] Thu, 01 July 2010 12:48 Go to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello,

I have a problem with model relative paths when using elements of
external ecore models within an ecore model. I have the three following
ecore models:

models/model1.ecore
models/model2.ecore
models/model3.ecore

I load each model with the following code from the directory above the
models directory (my java application is launched from this directory):

ResourceSet resourceSet = new ResourceSetImpl();
FResourceFactory resourceFactory = (...);
resourceSet.getResourceFactoryRegistry()
.getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION,
resourceFactory);

final Resource resource =
resourceSet.createResource(URI.createURI(modelPath));
resource.load(null);
EcoreUtil.resolveAll(resource);

return (EObject) EcoreUtil.getObjectByType(
resource.getContents(),
EcorePackage.eINSTANCE.getEObject());

Then I set some properties of model3's elements with some of model1's
and model2's elements. This properly works.

But when I try then to open model3 with the reflexive editor I have an
error since paths aren't properly set. For example, I have something
like in the href attribute:

<someProperty xmi:type="ecore:EReference"
href="./models/model1.ecore#//Element/properties"/>

I don't know how to fix this issue. Are there some configurations to be
done at the resource set level?

Thanks very much by advance for your help.
Thierry
Re: ResourceSet and relative path problem [message #544062 is a reply to message #544043] Thu, 01 July 2010 13:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Thierry,

Comments below.


Thierry Templier wrote:
> Hello,
>
> I have a problem with model relative paths when using elements of
> external ecore models within an ecore model. I have the three
> following ecore models:
>
> models/model1.ecore
> models/model2.ecore
> models/model3.ecore
>
> I load each model with the following code from the directory above the
> models directory (my java application is launched from this directory):
>
> ResourceSet resourceSet = new ResourceSetImpl();
> FResourceFactory resourceFactory = (...);
> resourceSet.getResourceFactoryRegistry()
> .getExtensionToFactoryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION,
> resourceFactory);
>
> final Resource resource =
> resourceSet.createResource(URI.createURI(modelPath));
I always explain to people that they should use absolute URIs with
absolute paths if they expect relative paths within the loaded resources
to work. Are you doing that?
> resource.load(null);
> EcoreUtil.resolveAll(resource);
>
> return (EObject) EcoreUtil.getObjectByType(
> resource.getContents(),
> EcorePackage.eINSTANCE.getEObject());
>
> Then I set some properties of model3's elements with some of model1's
> and model2's elements. This properly works.
>
> But when I try then to open model3 with the reflexive editor I have an
> error since paths aren't properly set. For example, I have something
> like in the href attribute:
>
> <someProperty xmi:type="ecore:EReference"
> href="./models/model1.ecore#//Element/properties"/>
>
> I don't know how to fix this issue. Are there some configurations to
> be done at the resource set level?
Be sure to use a path like file:/c:/folder/models/model1.ecore or
platform:/resource/project/models/model1.ecore to load the resources.
>
> Thanks very much by advance for your help.
> Thierry


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ResourceSet and relative path problem [message #544094 is a reply to message #544062] Thu, 01 July 2010 14:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello Ed,

Thanks very much for your quick answer.

I made a test with absolute paths and it works fine. But it's not
exactly what I want... As a matter of fact, I don't want to have
absolute paths within model files since I want to be able to move the
three files in another place (following the same structuring) and to
have the links on files in the new place and not in the previous place.
Do you see what I mean?

Otherwise what do you exactly mean by absolute URI and how to create them?

Thanks very much,
Thierry

> Thierry,
>
> Comments below.
>
> (...)
>
> I always explain to people that they should use absolute URIs with
> absolute paths if they expect relative paths within the loaded resources
> to work. Are you doing that?
>> (...)
> Be sure to use a path like file:/c:/folder/models/model1.ecore or
> platform:/resource/project/models/model1.ecore to load the resources.
Re: ResourceSet and relative path problem [message #544097 is a reply to message #544094] Thu, 01 July 2010 15:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Thierry,

Comments below.

Thierry Templier wrote:
> Hello Ed,
>
> Thanks very much for your quick answer.
>
> I made a test with absolute paths and it works fine. But it's not
> exactly what I want... As a matter of fact, I don't want to have
> absolute paths within model files since I want to be able to move the
> three files in another place (following the same structuring) and to
> have the links on files in the new place and not in the previous
> place. Do you see what I mean?
Yes. Did you look at the actual serialization. You should notice the
paths in the serialization are relative. If you always uses absolute
URIs for loading the resources the serialization will always use
relative paths whenever possible.
>
> Otherwise what do you exactly mean by absolute URI and how to create
> them?
An absolute URI is one with a scheme.
>
> Thanks very much,
> Thierry
>
>> Thierry,
>>
>> Comments below.
>>
>> (...)
>>
>> I always explain to people that they should use absolute URIs with
>> absolute paths if they expect relative paths within the loaded
>> resources to work. Are you doing that?
>>> (...)
>> Be sure to use a path like file:/c:/folder/models/model1.ecore or
>> platform:/resource/project/models/model1.ecore to load the resources.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ResourceSet and relative path problem [message #550142 is a reply to message #544097] Thu, 29 July 2010 09:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Thanks very much, Ed, for your answer and sorry for my very long one.

With your hints, I made it work. However, I need to add entries as
described below:

resourceSet.getURIConverter().getURIMap().put(
URI.createPlatformResourceURI(modelPath, true),
URI.createURI(getURIMapping(modelPath)));

Is it normal?
Thierry

> Thierry,
>
> Comments below.
>
> Thierry Templier wrote:
>> Hello Ed,
>>
>> Thanks very much for your quick answer.
>>
>> I made a test with absolute paths and it works fine. But it's not
>> exactly what I want... As a matter of fact, I don't want to have
>> absolute paths within model files since I want to be able to move the
>> three files in another place (following the same structuring) and to
>> have the links on files in the new place and not in the previous
>> place. Do you see what I mean?
> Yes. Did you look at the actual serialization. You should notice the
> paths in the serialization are relative. If you always uses absolute
> URIs for loading the resources the serialization will always use
> relative paths whenever possible.
>>
>> Otherwise what do you exactly mean by absolute URI and how to create
>> them?
> An absolute URI is one with a scheme.
>>
>> Thanks very much,
>> Thierry
>>
>>> Thierry,
>>>
>>> Comments below.
>>>
>>> (...)
>>>
>>> I always explain to people that they should use absolute URIs with
>>> absolute paths if they expect relative paths within the loaded
>>> resources to work. Are you doing that?
>>>> (...)
>>> Be sure to use a path like file:/c:/folder/models/model1.ecore or
>>> platform:/resource/project/models/model1.ecore to load the resources.
Re: ResourceSet and relative path problem [message #550202 is a reply to message #550142] Thu, 29 July 2010 13:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Thierry,

Comments below.


Thierry Templier wrote:
> Thanks very much, Ed, for your answer and sorry for my very long one.
>
> With your hints, I made it work. However, I need to add entries as
> described below:
>
> resourceSet.getURIConverter().getURIMap().put(
> URI.createPlatformResourceURI(modelPath, true),
> URI.createURI(getURIMapping(modelPath)));
I think the whole problem is the use of relative URIs. Once you've done
this, it's very likely you'll end up with inappropriate/incorrect
relative paths in the documents (because exactly the URI on the resource
is used in the serialized documents) such that an absolute URI will no
longer be able to load it correctly either (because it isn't really a
proper URI relative to the location of the document itself). This will
leave you in a state where you just don't know what's the right thing to
do. The solution, is always use absolute URIs when saving and when
loading so that the documents themselves will have correct relative URIs.
>
> Is it normal?
> Thierry
>
>> Thierry,
>>
>> Comments below.
>>
>> Thierry Templier wrote:
>>> Hello Ed,
>>>
>>> Thanks very much for your quick answer.
>>>
>>> I made a test with absolute paths and it works fine. But it's not
>>> exactly what I want... As a matter of fact, I don't want to have
>>> absolute paths within model files since I want to be able to move
>>> the three files in another place (following the same structuring)
>>> and to have the links on files in the new place and not in the
>>> previous place. Do you see what I mean?
>> Yes. Did you look at the actual serialization. You should notice the
>> paths in the serialization are relative. If you always uses absolute
>> URIs for loading the resources the serialization will always use
>> relative paths whenever possible.
>>>
>>> Otherwise what do you exactly mean by absolute URI and how to create
>>> them?
>> An absolute URI is one with a scheme.
>>>
>>> Thanks very much,
>>> Thierry
>>>
>>>> Thierry,
>>>>
>>>> Comments below.
>>>>
>>>> (...)
>>>>
>>>> I always explain to people that they should use absolute URIs with
>>>> absolute paths if they expect relative paths within the loaded
>>>> resources to work. Are you doing that?
>>>>> (...)
>>>> Be sure to use a path like file:/c:/folder/models/model1.ecore or
>>>> platform:/resource/project/models/model1.ecore to load the resources.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] InputStream
Next Topic:Attribute ID = true slows down performance Pt. II
Goto Forum:
  


Current Time: Thu Apr 25 10:49:58 GMT 2024

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

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

Back to the top