Skip to main content


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 09:10 Go to next message
Paco Blanco is currently offline Paco BlancoFriend
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 09:30]

Report message to a moderator

Re: EContentAdapter does not notify EAttributes List Elements changes previously added [message #932642 is a reply to message #932618] Thu, 04 October 2012 09:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Paco,

It looks to me that your string list is unique so adding the same string
again does nothing. So if you want to allow duplicate strings in the
list, you have to change to model so that isUnique is false for the
"stringValues" feature.


On 04/10/2012 11:10 AM, Paco Blanco wrote:
> I think I have found an EContentAdapter bug or 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>
>
>
> 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 a EMFTest instance
>
> In the first step, I add an EContentAdapter to a Root EObject. I add
> an Element and I manage 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 :(
>
> Is it a bug or a correct situation?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EContentAdapter does not notify EAttributes List Elements changes previously added [message #932903 is a reply to message #932642] Thu, 04 October 2012 14:58 Go to previous message
Paco Blanco is currently offline Paco BlancoFriend
Messages: 28
Registered: June 2012
Junior Member
OMG Neutral
I am so stupid....
Previous Topic:Reference depending on parent reference
Next Topic:[CDO] Ecore switch to not generate base class tables?
Goto Forum:
  


Current Time: Fri Apr 26 20:36:00 GMT 2024

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

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

Back to the top