Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Removing EList element doesn't kill References from Other Objects
icon5.gif  Removing EList element doesn't kill References from Other Objects [message #519328] Mon, 08 March 2010 14:19 Go to next message
El Mariachi is currently offline El MariachiFriend
Messages: 11
Registered: February 2010
Junior Member
Hi there! I'm having a real annoying Problem.

Let's imagine the following very simple ecore diagram called Mdl:

http://www.monsterup.com/upload/1268056978130.png

Let's consider a B object is referencing an A object. If a remove A from the ArrayOfA, the B object is still referencing the removed A object.

code example :

//========================================//

Root oRoot = MdlFactory.eInstance.createRoot();
A oA = MdlFactory.eInstance.createA();
B oB = MdlFactory.eInstance.createB();

oRoot.getArrayOfA.add(oA);
oRoot.getArrayOfB.add(oB);
oB.setRefA(oA );

oRoot.getArrayOfA().remove(oA );

if(oB.getRefA() != null)
System.out.println("Still Existing!!!");
else
System.out.println("Deleted");

//========================================//

In this case, the removed object A, still exist for object B.
So is there something to configure in the genmodel to change this behavior?

Is there a way to found all the EObjects refrenced by an EObject?

Thanks!


Emiliano El Mariachi
Re: Removing EList element doesn't kill References from Other Objects [message #519349 is a reply to message #519328] Mon, 08 March 2010 10:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

El Mariachi wrote:
> Hi there! I'm having a real annoying Problem.
>
> Let's imagine the following very simple ecore diagram called Mdl:
>
> http://www.monsterup.com
>
> Let's consider a B object is referencing an A object. If a remove A
> from the ArrayOfA, the B object is still referencing the removed A
> object.
>
> code example :
> //========================================//
>
> Root oRoot = MdlFactory.eInstance.createRoot();
> A oA = MdlFactory.eInstance.createA();
> B oB = MdlFactory.eInstance.createB();
>
> oRoot.getArrayOfA.add(oA);
> oRoot.getArrayOfB.add(oB);
> oB.setRefA(oA );
>
> oRoot.getArrayOfA().remove(oA );
>
> if(oB.getRefA() != null)
> System.out.println("Still Existing!!!");
> else
> System.out.println("Deleted");
>
> //========================================//
>
> In this case, the removed object A, still exist for object B.
> So is there something to configure in the genmodel to change this
> behavior?
No.
>
> Is there a way to found all the EObjects refrenced by an EObject?
A delete command normally finds all references and removes them. A
remove command doesn't do that though. EcoreUtil.delete is the
non-command way to do this. Have a look in DeleteCommand how it uses a
cross referencer to find all references to clean them all up.
>
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Removing EList element doesn't kill References from Other Objects [message #519672 is a reply to message #519349] Tue, 09 March 2010 16:28 Go to previous message
El Mariachi is currently offline El MariachiFriend
Messages: 11
Registered: February 2010
Junior Member
Thanks a lot, the delete command is working fine.
I simply wrote the following code :

EcoreUtil.delete(m_oA);
instead of
oRoot.getArrayOfA().remove(oA );

All the objects referencing oA are now null as expected.

Thanks!!!


Emiliano El Mariachi
Previous Topic:[Validation] Dynamic constraints?
Next Topic:"bfbtype.bfbtype#//@bFBType" to bFBType.name
Goto Forum:
  


Current Time: Fri Apr 19 08:48:24 GMT 2024

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

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

Back to the top