Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ResourceSet and unloading of Resources
ResourceSet and unloading of Resources [message #414790] Wed, 21 November 2007 15:41 Go to next message
Christian Ernst is currently offline Christian ErnstFriend
Messages: 8
Registered: July 2009
Junior Member
Hi !

Is there a way to unload a Resource from the ResourceSet ?

The EcoreUtil.remove(obj) seems not to remove the Resource from the
ResourceSet.

In our case we have several Models with own Resources and
containment proxy as cross references.
The proxies in EMF allows to load parts of our
Object Graph transparently and each Resource
which is touched is added to the ResourceSet.

Example:
Object X from Model A is in Resource A
Object Y from Model B is in Resource B
Object Z from Model C is in Resource C

Object X -containment-> Object Y -containment-> Object Z

But our Resources are very heavy/expensive an we would like
get rid of the Resource B and Resource C in case X doesn't reference
anymore Object Y.


Our current solution to manually remove all Resource from the
ResourceSet which are in the containment graph:
-----------------------------------------------

ResourceSet set = getResourceSet();

EcoreUtil.remove(objectY);

Set<Resource> resources = new HashSet<Resource>();
Iterator iter = EcoreUtil.getAllContents(objectY, false);
while (iter.hasNext()) {
resources.add(((EObject) iter.next()).eResource());
}
set.getResources().removeAll(resources);
-----------------------------------------------

But is this really the way it should be done ?


cheers
Christian
Re: ResourceSet and unloading of Resources [message #414793 is a reply to message #414790] Wed, 21 November 2007 16:20 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Christian,

At any time, even if there are still references to it, you can use
Resource.unload to turn all the contained objects into proxies. The
resource will reload if any proxy to it needs to be resolved. Afterwards
you could also use resourceSet.getResources().remove(resource),
although, since the contents are empty, that wouldn't save a significant
amount of space. EcoreUtil.delete might be useful for you as well;
there's a new version of it in 2.4 that recursively deletes the
contained children.


Christian Ernst wrote:
> Hi !
>
> Is there a way to unload a Resource from the ResourceSet ?
>
> The EcoreUtil.remove(obj) seems not to remove the Resource from the
> ResourceSet.
>
> In our case we have several Models with own Resources and
> containment proxy as cross references.
> The proxies in EMF allows to load parts of our
> Object Graph transparently and each Resource
> which is touched is added to the ResourceSet.
>
> Example:
> Object X from Model A is in Resource A
> Object Y from Model B is in Resource B
> Object Z from Model C is in Resource C
>
> Object X -containment-> Object Y -containment-> Object Z
>
> But our Resources are very heavy/expensive an we would like
> get rid of the Resource B and Resource C in case X doesn't reference
> anymore Object Y.
>
>
> Our current solution to manually remove all Resource from the
> ResourceSet which are in the containment graph:
> -----------------------------------------------
>
> ResourceSet set = getResourceSet();
>
> EcoreUtil.remove(objectY);
>
> Set<Resource> resources = new HashSet<Resource>();
> Iterator iter = EcoreUtil.getAllContents(objectY, false);
> while (iter.hasNext()) {
> resources.add(((EObject) iter.next()).eResource());
> }
> set.getResources().removeAll(resources);
> -----------------------------------------------
>
> But is this really the way it should be done ?
>
>
> cheers
> Christian


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:XMLCalender:: NoClassDefFoundError
Next Topic:EMF URI : Http protocol support ?
Goto Forum:
  


Current Time: Thu Apr 25 10:45:27 GMT 2024

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

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

Back to the top