[Solved] URI reference between XMI files [message #1075538] |
Mon, 29 July 2013 15:46 |
Vincent Verdier 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 #1075924 is a reply to message #1075903] |
Tue, 30 July 2013 10:37 |
Ed Merks Messages: 33216 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 |
Vincent Verdier 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 #1076519 is a reply to message #1076011] |
Wed, 31 July 2013 14:15 |
Vincent Verdier Messages: 12 Registered: April 2013 |
Junior Member |
|
|
Problem solved
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
|
|
|
Powered by
FUDForum. Page generated in 0.04555 seconds