Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Setting EReference
Setting EReference [message #1736132] Sun, 26 June 2016 23:11 Go to next message
UmaShankar Subramani is currently offline UmaShankar SubramaniFriend
Messages: 194
Registered: December 2011
Location: SWEDEN
Senior Member
I created my own EMFResource and added objects to it programmatically.
Everything works fine. But whenever I set an EReference to any of the EObjects, it gets added to the object at first. But after adding it to the resource, it becomes null again. I do not know what am I doing wrong while setting the EReference. But setting the EReference works fine when I do it from the editor. When I tried to find out the difference between the two, I found that the "eFlags=131076 (in MinimalEObjectImpl) class" for the editor change and "eFlags=0" for the change which I made Programmatically.

Because of this difference, the eNotificationRequired() method returns false. So the EReference is not set.

The code below shows how I set the EReference.


//Setting EReference "upDatedElement"

for(EStructuralFeature eReference:extendedClass.getEAllStructuralFeatures())
{
if(eReference.getName().equals("upDatedElement"))
{


extendedObject.eSet(eReference, linkObject );

}
}

[Updated on: Sun, 26 June 2016 23:26]

Report message to a moderator

Re: Setting EReference [message #1736181 is a reply to message #1736132] Mon, 27 June 2016 10:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31914
Registered: July 2009
Senior Member
Comments below.


On 26.06.2016 19:11, UmaShankar Subramani wrote:
> I created my own EMFResource and added objects to it programmatically.
> Everything works fine. But whenever I set an EReference to any of the
> EObjects, it gets added to the object at first. But after adding it
> to the resource, it becomes null again.
By default, cross resource containment is not supported, so adding an
object to a resource's contents will remove it from its containment
reference. Mostly likely you shouldn't be adding the object to the
resource's contents because that's likely redundant, i.e., the object
will be serialized if it is directly contained by a resource or if is
indirectly contained (via containment references) by any object directly
contained by a resource. You can also set the GenModel property
Containment Proxies to true if you want to allow an object to be both in
a containment reference and contained directly be a resource.
> I do not know what am I doing wrong while setting the EReference. But
> setting the EReference works fine when I do it from the editor. When
> I tried to find out the difference between the two, I found that the
> "eFlags=131076 (in MinimalEObjectImpl) class" for the editor change
> and "eFlags=0" for the change which I made Programmatically.
>
> The code below shows how I set the EReference.
>
> //Setting EReference "upDatedElement"
>
> for(EStructuralFeature
> eReference:extendedClass.getEAllStructuralFeatures())
> {
> if(eReference.getName().equals("upDatedElement"))
> {
> extendedObject.eSet(eReference, linkObject );
> }
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Problems with concurrent transactions
Next Topic:[Xcore] Proposed way of adding adapters to new instances
Goto Forum:
  


Current Time: Tue Jun 22 02:46:30 GMT 2021

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

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

Back to the top