How to completely remove a Resource from a ResourceSet? [message #1755254] |
Wed, 01 March 2017 16:58 |
Philipp Heisig Messages: 26 Registered: November 2014 |
Junior Member |
|
|
Hi,
I (programmatically) added some models to a wrong ResourceSet, which I want now to remove. As I couldn't find out where this information are stored or how to remove them via the Eclipse GUI, I tried to solve that programmatically by this code snippet:
ResourceSet resourceSet = pc.eResource().getResourceSet();
for (Resource res : resourceSet.getResources()) {
if(!(resff instanceof XMIResourceImpl)){
try {
resff.delete(((XMLResource) resff).getDefaultLoadOptions());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
However, it seems that something happened, but now I always the error "Problems encountered in file..... - Resource .. does not exist" when some action on the ResourceSet (e.g. open a (not deleted) model from the ResourceSet) occurs.
I'm wondering how I completely remove the resources from the ResourceSet?
[Updated on: Wed, 01 March 2017 17:04] Report message to a moderator
|
|
|
Re: How to completely remove a Resource from a ResourceSet? [message #1755262 is a reply to message #1755254] |
Wed, 01 March 2017 18:07 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
You're question is quite free of of any relevant context... In any case, resourceSet.getResources().remove(resource) will remove a resource from a resource set. The code you're showing would delete the underlying resource's contents from the file system, if it exists, but would not remove the resource from the resource set. The third URI looks very bogus, so probably nothing really exists at this URI.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02850 seconds