Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EContentAdapter does not notify EAttributes List Elements changes previously added
EContentAdapter does not notify EAttributes List Elements changes previously added [message #932618] Thu, 04 October 2012 05:10 Go to previous message
Paco Blanco is currently offline Paco Blanco
Messages: 28
Registered: June 2012
Junior Member
I think I have found an EContentAdapter bug or at least I think it is a wrong behaviour

I have the next model:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="xxxxx//www.omg.org/XMI" xmlns:xsi="xxxxx//www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="xxxxx//www.eclipse.org/emf/2002/Ecore" name="example" nsURI="xxxxx//org.example.com/econtentadapter/" nsPrefix="">
  <eClassifiers xsi:type="ecore:EClass" name="Root">
    <eStructuralFeatures xsi:type="ecore:EReference" name="elements" upperBound="-1"
        eType="#//Element" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Element">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="stringValues" upperBound="-1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>

xxxxx is http:

And the next example that shows the "error":
public class EMFTest {
	public static int eContentAccessSequence = 0;	
	
	public void testSimpleEMFEContentAdapter() {
		int eContentAccessSequence = EMFTest.eContentAccessSequence;
		Root root = ExampleFactory.eINSTANCE.createRoot();
		MyEContentAdapter elementEContentAdapter = new MyEContentAdapter(root);		
		Element element = ExampleFactory.eINSTANCE.createElement();
		root.getElements().add(element);
		//Get the just created instance
		root.getElements().get(root.getElements().size() - 1).getStringValues().add("kk");
		if(++eContentAccessSequence == EMFTest.eContentAccessSequence) {
			System.out.println("Right");
		}
		elementEContentAdapter.dispose();
		
		MyEContentAdapter elementEContentAdapter1 = new MyEContentAdapter(root);
		element = ExampleFactory.eINSTANCE.createElement();
		root.getElements().add(element);
		//Get the second just created instance
		root.getElements().get(root.getElements().size() - 1).getStringValues().add("kk");
		if(++eContentAccessSequence == EMFTest.eContentAccessSequence) {
			System.out.println("Right");
		}
		//Get the first created instance
		root.getElements().get(root.getElements().size() - 2).getStringValues().add("kk");
		if(++eContentAccessSequence == EMFTest.eContentAccessSequence) {
			System.out.println("Right");
		} else {
			System.out.println("Wrong!!!!");
		}
		elementEContentAdapter1.dispose();
	}
	
	class MyEContentAdapter extends EContentAdapter {
		Root root;
		
		MyEContentAdapter(Root root) {
			this.root = root;
			addAdapter(this.root);
		}
		
		public void dispose() {
			removeAdapter(root);
		}
		
		@Override
		public void notifyChanged(Notification n) {
			super.notifyChanged(n);
			if(n.getEventType() != Notification.REMOVING_ADAPTER) {
				Object notifier = n.getNotifier();
				if (notifier instanceof Element) {
					handleElementNotification();			
				}
			}
		}
	    
	    private void handleElementNotification() {
	    	eContentAccessSequence++;
	    }
	}	
}


To test, create a main method to call the testSimpleEMFEContentAdapter over an EMFTest instance

In the first step, I add an EContentAdapter to a Root EObject. I add an Element and I add a String value to the StringValueList of the Element. This String addition is correctly notified. I dispose the EContentAdapter.
In the second step, I add a new EContentAdapter to the previously Root EObject. I add an new Element and add new String value. This addition is perfectly notified. But if I add/remove a String value from the String list of the previuosly Element added before the new EContentAdapter creation, no notification is done Sad

Is it a bug or a correct situation?

[Updated on: Thu, 04 October 2012 05:30]

Report message to a moderator

 
Read Message
Read Message
Read Message
Previous Topic:Reference depending on parent reference
Next Topic:[CDO] Ecore switch to not generate base class tables?
Goto Forum:
  


Current Time: Sat May 25 14:42:25 EDT 2013

Powered by FUDForum. Page generated in 0.01685 seconds