Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Solved] URI reference between XMI files
[Solved] URI reference between XMI files [message #1075538] Mon, 29 July 2013 15:46 Go to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
Hello everyone,

I have a slight problem with references between two XMI files, a model and a profile which is applied on it. It is OK with absolute or relative URIs within the Eclipse platform but I didn't manage to get working relative URIs outside Eclipse environment. I'm not sure about that, but it seems that the base URI is somewhat located in the workspace.

The URI below works both outside and inside the Eclipse environment :

file:/aaa/bbb/ccc/uml2src/database.profile.uml#_x2g4kKEJEeKGtN90QVAToA


but this one doesn't :

../uml2src/database.profile.uml#_OrGTsKEJEeKGtN90QVAToA


and I would like something like this :

file:../../aaa/bbb/ccc/uml2src/database.profile.uml#_x2g4kKEJEeKGtN90QVAToA


because my application has to work in standalone mode and the files are in separated folders.

Any help is welcome.
Thanks in advance.

[Updated on: Wed, 31 July 2013 14:16]

Report message to a moderator

Re: URI reference between XMI files [message #1075560 is a reply to message #1075538] Mon, 29 July 2013 16:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 29/07/2013 5:46 PM, Vincent Verdier wrote:
> Hello everyone,
>
> I have a slight problem with references between two XMI files, a model
> and a profile which is applied on it.
A UML problem...
> It is OK with absolute or relative URIs within the Eclipse platform
> but I didn't manage to get working relative URIs outside Eclipse
> environment.
That's mostly an issue of ensuring you have folder mappings defined for
the locations of the projects...
> I'm not sure about that, but it seems that the base URI is somewhat
> located in the workspace.
Hmmm...
>
> The URIs below works both outside and inside the Eclipse environment :
>
>
> file:/aaa/bbb/ccc/uml2src/database.profile.uml#_x2g4kKEJEeKGtN90QVAToA
>
>
> but this one doesn't :
>
>
> ./uml2src/database.profile.uml#_OrGTsKEJEeKGtN90QVAToA
>
>
> and I would like something like this :
>
>
> file:../../aaa/bbb/ccc/uml2src/database.profile.uml#_x2g4kKEJEeKGtN90QVAToA
>
>
>
> because my application has to work in standalone mode and the files
> are in separated folders.
>
Without more details it's hard to give detailed advice. I'd suggest
having a look at
org.eclipse.emf.ecore.resource.URIConverter.getURIMap()'s Javadoc.

When working stand alone with resources that are "normally" used in the
workspace, it's generally best to use platform:/resource URIs and define
URI mappings from platform:/resource/<project-name>/ to a physical
location such as file:/.../<project-name>/. Alternatively you can
populate
org.eclipse.emf.ecore.plugin.EcorePlugin.getPlatformResourceMap() with
mappings from project names to their physical location. The idea being
to use logical platform:/resource URIs to load your resource and to
ensure you have mappings for all the projects involved...
> Any help is welcome.
> Thanks in advance.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: URI reference between XMI files [message #1075903 is a reply to message #1075560] Tue, 30 July 2013 09:53 Go to previous messageGo to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
Thank you for your answer.

I had a look at the org.eclipse.emf.ecore.resource.URIConverter.getURIMap()'s Javadoc then I tried to implement the convertion :
Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
        
File dir = new File(""); // current location (directory where the standalone JAR belongs)
URI resourceURI = URI.createPlatformResourceURI("uml2src", true).appendSegment("");  
URI physicalURI = URI.createFileURI(dir.getAbsolutePath()).appendSegment("");
        
System.out.println("{" + resourceURI + ", " + physicalURI + "}");
        
uriMap.put(resourceURI, physicalURI);

What is printed by the sysout debug :
{platform:/resource/uml2src/, file:/aaa/bbb/ccc/uml2src/}

(aaa, bbb, ccc are of course obfuscated directories)

The result seems good but it is still not working, though my uml software displays this URI for the path to the profile :

platform:/resource/uml2src/database.profile.uml


I also looked at the XMI code and the paths to the profile are like below :

href="../uml2src/database.profile.uml"


Do I need to do something more with the org.eclipse.emf.ecore.plugin.EcorePlugin.getPlatformResourceMap() ?
Re: URI reference between XMI files [message #1075924 is a reply to message #1075903] Tue, 30 July 2013 10:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 30/07/2013 11:53 AM, Vincent Verdier wrote:
> Thank you for your answer.
>
> I had a look at the
> org.eclipse.emf.ecore.resource.URIConverter.getURIMap()'s Javadoc then
> I tried to implement the convertion :
>
> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
> File dir = new File(""); // current location (directory where
> the standalone JAR belongs)
You mention it's a jar....
> URI resourceURI = URI.createPlatformResourceURI("uml2src",
> true).appendSegment(""); URI physicalURI =
> URI.createFileURI(dir.getAbsolutePath()).appendSegment("");
> System.out.println("{" + resourceURI + ", " + physicalURI + "}");
> uriMap.put(resourceURI, physicalURI);
>
> What is printed by the sysout debug :
>
> {platform:/resource/uml2src/, file:/aaa/bbb/ccc/uml2src/}
>
> (aaa, bbb, ccc are of course obfuscated directories)
>
> The result seems good but it is still not working, though my uml
> software displays this URI for the path to the profile :
>
>
> platform:/resource/uml2src/database.profile.uml
So that looks better.
>
>
> I also looked at the XMI code and the paths to the profile are like
> below :
>
>
> href="../uml2src/database.profile.uml"
So it's properly resolving the URI to
platform:/resource/uml2src/database.profile.uml... So does
file:/aaa/bbb/ccc/uml2src/ exist in the file system? It sounds to me
like it doesn't, because you mention a jar. So if the jar that contains
database.profile.uml is abc.jar you should use a URI of the form
archive:file:/<path-to-jar>/abc.jar!/ so that all access to URIs
prefixed by platform:/resource/uml2src/ will be redirected to look in
the root of the abc.jar file.
>
>
> Do I need to do something more with the
> org.eclipse.emf.ecore.plugin.EcorePlugin.getPlatformResourceMap() ?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: URI reference between XMI files [message #1075980 is a reply to message #1075924] Tue, 30 July 2013 12:46 Go to previous messageGo to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
The profile file isn't embedded in the JAR. It is just in the same directory. Nevertheless, the possibility of having it inside the JAR would be interesting.

[EDIT]

I corrected the current directory fetching because it wasn't good in some cases.

File dir = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath()); // current location


But I still have the same problem...

[Updated on: Tue, 30 July 2013 13:06]

Report message to a moderator

Re: URI reference between XMI files [message #1075987 is a reply to message #1075980] Tue, 30 July 2013 13:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Vincent,

I really need to understand exactly the locations of things in your file
system. I.e., does the folder file:/aaa/bbb/ccc/uml2src/ really exist
and does it have the profile file in it. If so, you should be able to
load it...


On 30/07/2013 2:46 PM, Vincent Verdier wrote:
> The profile file isn't embedded in the JAR. It is just in the same
> directory. Nevertheless, the possibility of having it inside the JAR
> would be interesting.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: URI reference between XMI files [message #1076011 is a reply to message #1075987] Tue, 30 July 2013 14:14 Go to previous messageGo to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
The folders are organized as below (I shortened the paths in my previous post)
/aaa/bbb/ccc/ddd/eee/fff/

* model.uml

/aaa/bbb/ccc/xxx/yyy/uml2src/

* uml2src.jar
* database.profile.uml

In my Eclipse workspace I have two projects. The first one is the uml2src project and the second one is the model. So when I apply the profile on the model, it refers to the profile which is located in the uml2src project.

I don't think it is relevant but the standalone JAR is executed from a makefile.

PS: sorry for the odd folder names but they might contain some information that the company where I'm doing my internship wouldn't allow me to post them Sad

[Updated on: Tue, 30 July 2013 14:15]

Report message to a moderator

Re: URI reference between XMI files [message #1076519 is a reply to message #1076011] Wed, 31 July 2013 14:15 Go to previous message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
Problem solved Smile

Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();

if(!EMFPlugin.IS_ECLIPSE_RUNNING && ClassLoader.getSystemClassLoader().getResource(".") != null) {
    File dir = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath()); // current location
    URI resourceURI = URI.createURI("../uml2src", true).appendSegment("");
    URI physicalURI = URI.createFileURI(dir.getAbsolutePath()).appendSegment("");
    
    System.out.println("{" + resourceURI + ", " + physicalURI + "}");
    
    uriMap.put(resourceURI, physicalURI);
}


I had to use ../uml2src as the logic URI instead of just uml2src.

Thank you anyway.

[Updated on: Wed, 31 July 2013 14:15]

Report message to a moderator

Previous Topic:Unset on isMany containment-ref doesn't trigger detachment
Next Topic:XCore generators
Goto Forum:
  


Current Time: Tue Apr 23 13:58:37 GMT 2024

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

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

Back to the top