Detecting resource saves and loads [message #504612] |
Mon, 21 December 2009 13:42 |
Stephen McCants Messages: 92 Registered: July 2009 |
Member |
|
|
Hello,
I'm looking for a way to detect resource saves and loads, preferably without overriding
ResourceSetImpl or ResourceImpl, so that any type of resource can be supported. I'm not actually
interested in detecting loads, but only saves, however, in my current approach they appear as the
same thing (which is problematic).
Currently, I attach an Adapter to each ResourceSet. This Adapter, in turn, attaches Adapters to
each Resource created in the ResourceSet. Each Resource also as setTrackingModification(true)
called on it. The ResourceAdapter informs other objects about saves to the Resource. The intent is
to allow other parts of the code that are using a different resource set to refresh (reload) when
resources they care about are altered and saved.
My ResourceAdapter is listening to the changes to RESOURCE__IS_MODIFIED. When it is changed from
true to false, I assume that is a save (I don't currently support undos). Unfortunately, a load
does the exact same thing. ResourceImpl.load(InputStream, Map<?,?>) calls "setModified(false)" at
the end of its function. This is because the load likely set isModified to true during the course
of loading/modifying in the data. However, setModified(false) sends out notification. I'd override
this behavior and just set isModified = false, but load(InputStream, Map<?, ?>) is final.
At this point, I'm at a loss as to how to tell saves from loads. Any ideas?
Thanks in advance!
Sincerely,
Stephen McCants
|
|
|
Re: Detecting resource saves and loads [message #504662 is a reply to message #504612] |
Mon, 21 December 2009 23:21 |
Stephen McCants Messages: 92 Registered: July 2009 |
Member |
|
|
I got around the problem by using a ResourceHandler with a postLoad and postSave.
--Stephen
Stephen McCants wrote:
> Hello,
> I'm looking for a way to detect resource saves and loads, preferably
> without overriding ResourceSetImpl or ResourceImpl, so that any type of
> resource can be supported. I'm not actually interested in detecting
> loads, but only saves, however, in my current approach they appear as
> the same thing (which is problematic).
> Currently, I attach an Adapter to each ResourceSet. This Adapter,
> in turn, attaches Adapters to each Resource created in the ResourceSet.
> Each Resource also as setTrackingModification(true) called on it. The
> ResourceAdapter informs other objects about saves to the Resource. The
> intent is to allow other parts of the code that are using a different
> resource set to refresh (reload) when resources they care about are
> altered and saved.
> My ResourceAdapter is listening to the changes to
> RESOURCE__IS_MODIFIED. When it is changed from true to false, I assume
> that is a save (I don't currently support undos). Unfortunately, a load
> does the exact same thing. ResourceImpl.load(InputStream, Map<?,?>)
> calls "setModified(false)" at the end of its function. This is because
> the load likely set isModified to true during the course of
> loading/modifying in the data. However, setModified(false) sends out
> notification. I'd override this behavior and just set isModified =
> false, but load(InputStream, Map<?, ?>) is final.
> At this point, I'm at a loss as to how to tell saves from loads.
> Any ideas?
> Thanks in advance!
>
> Sincerely,
> Stephen McCants
|
|
|
Powered by
FUDForum. Page generated in 0.03068 seconds