Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353493 - Dynamic EObject is not removed from resource if added to another containment reference.
Summary: Dynamic EObject is not removed from resource if added to another containment ...
Status: RESOLVED INVALID
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: 2.7.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-01 09:04 EDT by sth2000 CLA
Modified: 2011-08-01 16:16 EDT (History)
0 users

See Also:


Attachments
JUnit test plugin, which tests the mentioned bug. (4.23 KB, application/zip)
2011-08-01 09:04 EDT, sth2000 CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description sth2000 CLA 2011-08-01 09:04:26 EDT
Created attachment 200653 [details]
JUnit test plugin, which tests the mentioned bug.

I have the following situation: A car object is contained in one resource, a wheel object in another. The car has a containment reference for wheels. When the wheel is added to the car's wheels reference, the wheel should be removed from its containing resource, obviously. This works if I use generated code. It does not work with dynamic EObjects. The following JUnit plugin test case makes this more clear:

ResourceSet rs = new ResourceSetImpl();
Resource r1 = rs.createResource(URI.createURI("r1"));
Resource r2 = rs.createResource(URI.createURI("r2"));

Resource mmr = rs.getResource(				URI.createPlatformPluginURI("/emfTest/models/carExample.ecore", true), true);

EPackage ePackage = (EPackage) mmr.getContents().get(0);
EClass carEClass = (EClass) ePackage.getEClassifier("Car");
EClass wheelEClass = (EClass) ePackage.getEClassifier("Wheel");

/*
 * Create a car and add it to r1
 */
EObject car = ePackage.getEFactoryInstance().create(carEClass);
r1.getContents().add(car);

/*
 * create a wheel and add it to r2
 */
EObject wheel = ePackage.getEFactoryInstance().create(wheelEClass);
r2.getContents().add(wheel);

/*
 * Now, add the wheel to the car's wheels reference, which is a containment reference
 */
((EList<EObject>) car.eGet(carEClass.getEStructuralFeature("wheels"))).add(wheel);

/*
 * Now, the wheel should not be a root element of r2.
 * This assertions fails in case of dynamic EObjects.
 */
assertTrue(!r2.getContents().contains(wheel));


I have attached this code as a JUnit test plugin, which also includes the carExample.ecore file.
Comment 1 Ed Merks CLA 2011-08-01 16:16:30 EDT
This is how proxy resolving containment references are supposed to work.  If you want the behavior you're expecting, you'll need to set resolveProxies to false.