Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » File vs. platform URI in combination with ResourceSet
File vs. platform URI in combination with ResourceSet [message #538416] Mon, 07 June 2010 11:18 Go to next message
Jens von Pilgrim is currently offline Jens von Pilgrim
Messages: 293
Registered: July 2009
Senior Member
Hi,

after some annoying hours of debugging I found a weird bug in my code.
I'm using a TransactionalEditingDomain (TED) with a ResourceSet (RS) for
loading, modifying and saving my models. So far, so good. I have
implemented two methods for selecting a resource, but in both cases the
resources are identified using an URI. However, in one case the URI is a
platform URI, while in the second case it's a file URI. E.g.,
- platform:/resource/test/my.model
- file:/Users/jens/workspaces/runtime/test/my.model
These two URIs are different, but both reference the very same file and
model.

The models loaded contain cross references. Unfortunately it seems to
make a difference for the RS (or TED?) whether a resource has been
loaded using a platform or file URI -- in the second case something goes
wrong with the cross references. This is really hard to debug, since the
model elements are similar but only different instances are (wrongly)
created (not so mention proxies..). Apparently, cross references use
platform URIs (always?), and so the RS (or whatever) re-loads a model
although it is already loaded (with the file URI).

Maybe it was a little bit naive to assume that URIs are automatically
normalized... So, I normalize the URIs myself:

URIConverter converter = new ExtensibleURIConverterImpl();
URI fileURI =
URI.createFileURI(ResourcesPlugin.getWorkspace().getRoot().g etLocation().toOSString()+File.separator);
URI platformURI = URI.createPlatformResourceURI("/", false);
converter.getURIMap().put( fileURI, platformURI);
theURI = converter.normalize(URI.createFileURI(filename));

Now, my application is working and no model elements are loaded twice
due to different URIs.

I'm wondering whether my solution is OK, or if there is a "best
practice" for that kind of problem? Actually it would be nice if URIs
were automatically normalized by the RS.

Cheers,

Jens

P.S.: I'd almost say cross or inter-model references might prove to be
modeling's Achilles' heel... :-(
Re: File vs. platform URI in combination with ResourceSet [message #538449 is a reply to message #538416] Mon, 07 June 2010 12:11 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25999
Registered: July 2009
Senior Member
Jens,

Comments below.

Jens v.P. wrote:
> Hi,
>
> after some annoying hours of debugging I found a weird bug in my code.
> I'm using a TransactionalEditingDomain (TED) with a ResourceSet (RS)
> for loading, modifying and saving my models. So far, so good. I have
> implemented two methods for selecting a resource, but in both cases
> the resources are identified using an URI. However, in one case the
> URI is a platform URI, while in the second case it's a file URI. E.g.,
> - platform:/resource/test/my.model
> - file:/Users/jens/workspaces/runtime/test/my.model
> These two URIs are different, but both reference the very same file
> and model.
With file systems that support symbolic links you could have more cases
of that...
>
> The models loaded contain cross references. Unfortunately it seems to
> make a difference for the RS (or TED?) whether a resource has been
> loaded using a platform or file URI -- in the second case something
> goes wrong with the cross references. This is really hard to debug,
> since the model elements are similar but only different instances are
> (wrongly) created (not so mention proxies..). Apparently, cross
> references use platform URIs (always?), and so the RS (or whatever)
> re-loads a model although it is already loaded (with the file URI).
>
> Maybe it was a little bit naive to assume that URIs are automatically
> normalized... So, I normalize the URIs myself:
>
> URIConverter converter = new ExtensibleURIConverterImpl();
> URI fileURI =
> URI.createFileURI(ResourcesPlugin.getWorkspace().getRoot().g etLocation().toOSString()+File.separator);
>
> URI platformURI = URI.createPlatformResourceURI("/", false);
> converter.getURIMap().put( fileURI, platformURI);
> theURI = converter.normalize(URI.createFileURI(filename));
>
> Now, my application is working and no model elements are loaded twice
> due to different URIs.
You're assuming that all projects are actually contained by the
workspace root. But projects themselves can be links.
>
> I'm wondering whether my solution is OK, or if there is a "best
> practice" for that kind of problem?
No, it's not a good thing in general.
> Actually it would be nice if URIs were automatically normalized by the
> RS.
There is a limit to how much normalization we do by default, especially
when "expensive" file system access is required.

Taking a step back... Why are you using direct file system URIs in the
first place? (Especially for things actually in the workspace.)
>
> Cheers,
>
> Jens
>
> P.S.: I'd almost say cross or inter-model references might prove to be
> modeling's Achilles' heel... :-(
Previous Topic:EMF Change : referenceValue proxy not resolved
Next Topic:[Validation] Problem instantiating constraint class in JavaConstraintParser: uses extension's Namesp
Goto Forum:
  


Current Time: Wed Aug 20 14:47:55 EDT 2014

Powered by FUDForum. Page generated in 0.01504 seconds