Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Delete elements in a model?
Delete elements in a model? [message #479131] Sun, 09 August 2009 17:21 Go to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

How can I safely delete some elements in a model? I implemented some
transformations which, for example, generate new elements contained in a
specific root element. Therefore I want to delete all already existent
elements in the root element. Until now, I did it in that way:

public void generateServiceElements(ServiceAccessComponent sac){
sac.getOperation().clear();
//...
//add some new operations
}

But once in a while I get the following exception when saving the file
after transformations:

DanglingHREFException: The object 'MetaModel.impl.OperationImpl@1885c3a
(name: myOperation)' is not contained in a resource.

Before I cleared the existing elements I didn't get this exception. So I
could imagine that the elements of the EList<Operation> (received with
sac.getOperation()) aren't deleted really but only the list is cleared.
That's why the elements haven't got a container and the exception is
thrown. How can I clear the list adequate that all elements will be
deleted right?
Re: Delete elements in a model? [message #479140 is a reply to message #479131] Sun, 09 August 2009 18:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Gilbert,

Probably you want to use EcoreUtil.delete(eObject, true) for each object
in the list (which will also remove it from the list).


Gilbert Mirenque wrote:
> How can I safely delete some elements in a model? I implemented some
> transformations which, for example, generate new elements contained in a
> specific root element. Therefore I want to delete all already existent
> elements in the root element. Until now, I did it in that way:
>
> public void generateServiceElements(ServiceAccessComponent sac){
> sac.getOperation().clear();
> //...
> //add some new operations
> }
>
> But once in a while I get the following exception when saving the file
> after transformations:
>
> DanglingHREFException: The object 'MetaModel.impl.OperationImpl@1885c3a
> (name: myOperation)' is not contained in a resource.
>
> Before I cleared the existing elements I didn't get this exception. So I
> could imagine that the elements of the EList<Operation> (received with
> sac.getOperation()) aren't deleted really but only the list is cleared.
> That's why the elements haven't got a container and the exception is
> thrown. How can I clear the list adequate that all elements will be
> deleted right?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Delete elements in a model? [message #479144 is a reply to message #479140] Sun, 09 August 2009 19:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

I get an ConcurrentModificationException? But what is an concurrent
access? When the model is open in the generated editor?
Re: Delete elements in a model? [message #479147 is a reply to message #479144] Sun, 09 August 2009 19:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Gilbert,

Keep in mind that as each element in the list is deleted it's removed
from the list so if you are iterating over that very list and calling
delete on each element, you'll get an exception just like what you've
described. Either iterate over a copy of the list or use a counted loop
knowing that the list shrinks as a result of each delete call.


Gilbert Mirenque wrote:
> I get an ConcurrentModificationException? But what is an concurrent
> access? When the model is open in the generated editor?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Validation fails on required EAttribute (EEnum) with default literal value.
Next Topic:get EPackage from a EStructuralFeature
Goto Forum:
  


Current Time: Fri Apr 19 09:55:16 GMT 2024

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

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

Back to the top