Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Two way references and Dyanmic Feature Delegation
Two way references and Dyanmic Feature Delegation [message #425544] Mon, 01 December 2008 12:37 Go to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Hi,

I think there may be a problem with 2 way reference generation using
Dynamic Feature Delegation generation.

I am generating the code under EMF 2.5 (2.5.0.v200811032126) with
Eclipse 3.5 ( I20081030-1917 ). I run under EMF 2.4 (2.4.1.v200808251517)
with Eclipse 3.4. This follows Ed's suggestion about cdo
( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 5397.html)

Take the simple library tuorial model and generate the model code using
Dynamic feature delegation.

BookImpl has an inverseAdd generated to cope with setting its author from
Writer which all looks as expected;

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseAdd(InternalEObject otherEnd, int
featureID, NotificationChain msgs) {
switch (featureID) {
case LibraryPackage.BOOK__AUTHOR:
Writer author = basicGetAuthor();
if (author != null)
msgs = ((InternalEObject)author).eInverseRemove(this,
LibraryPackage.WRITER__BOOKS, Writer.class, msgs);
return basicSetAuthor((Writer)otherEnd, msgs);
}
return super.eInverseAdd(otherEnd, featureID, msgs);
}


However if we look at basicSetAuthor we see

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetAuthor(Writer newAuthor,
NotificationChain msgs) {
msgs = eDynamicInverseRemove((InternalEObject)newAuthor,
LibraryPackage.BOOK__AUTHOR, msgs);
return msgs;
}

When I add a book to a writer the author property in the book is never set.
Is this a bug, or am I missing something?

public static void main(String[] args) {
Writer writer = LibraryFactory.eINSTANCE.createWriter();
writer.setName("Pierre Menard");
Book book = LibraryFactory.eINSTANCE.createBook();
book.setTitle("Quixote");
writer.getBooks().add(book);

System.out.println("Writer " + writer.getName() + " wrote " +
(writer.getBooks().isEmpty()?"nothing":writer.getBooks().iterator().next().getTitle()));
System.out.println("The Book " + book.getTitle() + " was written by " +
(book.getAuthor()==null?"no one":book.getAuthor().getName()));

System.out.println("");

Writer writer2 = LibraryFactory.eINSTANCE.createWriter();
writer2.setName("Cervantes");
Book book2 = LibraryFactory.eINSTANCE.createBook();
book2.setTitle("Don Quixote");
book2.setAuthor(writer2);

System.out.println("Writer " + writer2.getName() + " wrote " +
(writer2.getBooks().isEmpty()?"nothing":writer2.getBooks().iterator().next().getTitle()));
System.out.println("The Book " + book2.getTitle() + " was written by " +
(book2.getAuthor()==null?"no one":book2.getAuthor().getName()));
}

outputs:

Writer Pierre Menard wrote Quixote
The Book Quixote was written by no one

Writer Cervantes wrote Don Quixote
The Book Don Quixote was written by Cervantes


If I do that with a model (same environment) generated with Feature
Delegation None, I get what I expected;

Writer Pierre Menard wrote Quixote
The Book Quixote was written by Pierre Menard

Writer Cervantes wrote Don Quixote
The Book Don Quixote was written by Cervantes
Re: Two way references and Dyanmic Feature Delegation [message #425547 is a reply to message #425544] Mon, 01 December 2008 13:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
JF,

Comments below.

JF wrote:
> Hi,
>
> I think there may be a problem with 2 way reference generation using
> Dynamic Feature Delegation generation.
>
> I am generating the code under EMF 2.5 (2.5.0.v200811032126) with
> Eclipse 3.5 ( I20081030-1917 ). I run under EMF 2.4
> (2.4.1.v200808251517) with Eclipse 3.4. This follows Ed's suggestion
> about cdo
> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 5397.html)
>
> Take the simple library tuorial model and generate the model code
> using Dynamic feature delegation.
> BookImpl has an inverseAdd generated to cope with setting its author
> from Writer which all looks as expected;
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> @Override
> public NotificationChain eInverseAdd(InternalEObject otherEnd, int
> featureID, NotificationChain msgs) {
> switch (featureID) {
> case LibraryPackage.BOOK__AUTHOR:
> Writer author = basicGetAuthor();
> if (author != null)
> msgs =
> ((InternalEObject)author).eInverseRemove(this,
> LibraryPackage.WRITER__BOOKS, Writer.class, msgs);
> return basicSetAuthor((Writer)otherEnd, msgs);
> }
> return super.eInverseAdd(otherEnd, featureID, msgs);
> }
>
>
> However if we look at basicSetAuthor we see
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public NotificationChain basicSetAuthor(Writer newAuthor,
> NotificationChain msgs) {
> msgs = eDynamicInverseRemove((InternalEObject)newAuthor,
> LibraryPackage.BOOK__AUTHOR, msgs);
> return msgs;
> }
>
> When I add a book to a writer the author property in the book is never
> set.
> Is this a bug, or am I missing something?
Hmmm. Even at a glance it seems it should be eDynamicInverseAdd,
right? Could you try that and open a bugzilla with your findings?
>
> public static void main(String[] args) {
> Writer writer = LibraryFactory.eINSTANCE.createWriter();
> writer.setName("Pierre Menard");
> Book book = LibraryFactory.eINSTANCE.createBook();
> book.setTitle("Quixote");
> writer.getBooks().add(book);
>
> System.out.println("Writer " + writer.getName() + " wrote " +
> (writer.getBooks().isEmpty()?"nothing":writer.getBooks().iterator().next().getTitle()));
>
> System.out.println("The Book " + book.getTitle() + " was
> written by " + (book.getAuthor()==null?"no
> one":book.getAuthor().getName()));
>
> System.out.println("");
>
> Writer writer2 = LibraryFactory.eINSTANCE.createWriter();
> writer2.setName("Cervantes");
> Book book2 = LibraryFactory.eINSTANCE.createBook();
> book2.setTitle("Don Quixote");
> book2.setAuthor(writer2);
>
> System.out.println("Writer " + writer2.getName() + " wrote " +
> (writer2.getBooks().isEmpty()?"nothing":writer2.getBooks().iterator().next().getTitle()));
>
> System.out.println("The Book " + book2.getTitle() + " was
> written by " + (book2.getAuthor()==null?"no
> one":book2.getAuthor().getName()));
> }
>
> outputs:
>
> Writer Pierre Menard wrote Quixote
> The Book Quixote was written by no one
>
> Writer Cervantes wrote Don Quixote
> The Book Don Quixote was written by Cervantes
>
>
> If I do that with a model (same environment) generated with Feature
> Delegation None, I get what I expected;
>
> Writer Pierre Menard wrote Quixote
> The Book Quixote was written by Pierre Menard
>
> Writer Cervantes wrote Don Quixote
> The Book Don Quixote was written by Cervantes
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Two way references and Dyanmic Feature Delegation [message #425552 is a reply to message #425547] Mon, 01 December 2008 14:46 Go to previous message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
see bug 257075

https://bugs.eclipse.org/bugs/show_bug.cgi?id=257075
Previous Topic:deleting child in one class deletes this child in all classes
Next Topic:createXXX parameters in Factories
Goto Forum:
  


Current Time: Sat Apr 20 04:14:08 GMT 2024

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

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

Back to the top