Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problems getting content of loaded resource
Problems getting content of loaded resource [message #430550] Wed, 27 May 2009 08:10 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I'm having a strange problem regarding demand-loading resources. I use
getResourceSet().getResource(uri, true); to load a resource identified
by a platform:/plugin/ resource. In some other part of the code I'm
listening to additions to the resources feature of the same resource
set. When a new resource appears, I look at the content of the newly
added resource using resource.getContents().size() and
resource.getContents().get(0); For some reason the contents is empty
because the platform:/plugin/ uri cannot be found.

However, the same resourceSet (actually an editingDomain) is used by an
Ecore editor, and if I asyncExec the code doing
resource.getContents().size() and resource.getContents().get(0), it
works! It's as if the editor get's a chance to load the contents using
some extra tricks for handling platform:/plugin/ uri's. If I knew this
trick I could use it myself, instead of having to wait for the editor to
do it for me!


Hallvard
Re: Problems getting content of loaded resource [message #430555 is a reply to message #430550] Wed, 27 May 2009 10:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060908070406040304040100
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hallvard,

Comments below.

Hallvard Tr


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problems getting content of loaded resource [message #430557 is a reply to message #430555] Wed, 27 May 2009 11:02 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Ed Merks wrote:
> Hallvard,
>
>> When a new resource appears, I look at the content of the newly
>> added resource using resource.getContents().size() and
>> resource.getContents().get(0); For some reason the contents is empty
>> because the platform:/plugin/ uri cannot be found.
> Did you determine this reason by looking at Resource.getErrors()?

I caught an exception saying the resource pointed at by the URI couldn't
be found. For me it looked like the resource had been loaded, but that
the content wasn't filled due to the above error. From looking at the
ResourceImpl code, I gathered that this is normal: A resource is
considered loaded also when it has tried, but failed?

> Keep in mind that when a resource is added to the resource set, it
> generally isn't loaded yet. I.e., this logic creates it and then later
> loads it:

OK, so first the resource is demand created, then adapters are notified
that it has been added, and then it is loaded? I thought it was loaded
before it was added.

But I still wonder about the URI not resolving or finding the the
resource. Perhaps I have misinterpreted the exception? Is there
something that triggers activation of the platform URI handler and this
is done by the editor and not by my code?

> So it sounds like you should really be listening to the resource set for
> resources being added, check if the added resource's isLoaded is true,
> and also listen to the new resource to see when it's loaded, unloaded,
> or otherwise has it's getContents modified...

I will.

Hallvard
Re: Problems getting content of loaded resource [message #430561 is a reply to message #430557] Wed, 27 May 2009 12:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Hallvard,

Comments below.

Hallvard Trætteberg wrote:
> Ed Merks wrote:
>> Hallvard,
>>
>>> When a new resource appears, I look at the content of the newly
>>> added resource using resource.getContents().size() and
>>> resource.getContents().get(0); For some reason the contents is empty
>>> because the platform:/plugin/ uri cannot be found.
>> Did you determine this reason by looking at Resource.getErrors()?
>
> I caught an exception saying the resource pointed at by the URI
> couldn't be found. For me it looked like the resource had been loaded,
> but that the content wasn't filled due to the above error. From
> looking at the ResourceImpl code, I gathered that this is normal: A
> resource is considered loaded also when it has tried, but failed?
Yes, this prevents repeated (expensive) attempts to load the resource.
>
>> Keep in mind that when a resource is added to the resource set, it
>> generally isn't loaded yet. I.e., this logic creates it and then
>> later loads it:
>
> OK, so first the resource is demand created, then adapters are
> notified that it has been added, and then it is loaded?
Yes.
> I thought it was loaded before it was added.
No.
>
> But I still wonder about the URI not resolving or finding the the
> resource.
Yes, that seems odd. A platform:/plugin URI is handled just as a "plain
old java.net.URL" for which the Eclipse platform registers a URL handler.
> Perhaps I have misinterpreted the exception?
Perhaps.
> Is there something that triggers activation of the platform URI
> handler and this is done by the editor and not by my code?
I think these handlers are registered during startup. Try creating just
a URL and calling openStream on it to see if that's working... That's
basically all the URIConverter will do...
>
>> So it sounds like you should really be listening to the resource set
>> for resources being added, check if the added resource's isLoaded is
>> true, and also listen to the new resource to see when it's loaded,
>> unloaded, or otherwise has it's getContents modified...
>
> I will.
>
> Hallvard


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF Error
Next Topic:Cannot cast from Boolean to InternalEObject
Goto Forum:
  


Current Time: Thu Apr 25 06:04:40 GMT 2024

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

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

Back to the top