Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Reading attribute value from EObject programmatically
Reading attribute value from EObject programmatically [message #966908] Thu, 01 November 2012 10:31 Go to next message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
Hi,

I have an EObject of an EClass with an integer attribute named 'a'. Is is possible to
read the value for this attribute from the EObject, intuitively like this (pseudo code):

EObject o ... ;
EAttribute a = o.eClass.getAttribute( "a" );
int aValue = o.getValue( a );

I've searched the API, but couldn't find how to do this.
Re: Reading attribute value from EObject programmatically [message #966925 is a reply to message #966908] Thu, 01 November 2012 10:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Peter,

You can use o.eGet(a).

On 01/11/2012 11:31 AM, Peter Johnsen wrote:
> Hi,
>
> I have an EObject of an EClass with an integer attribute named 'a'. Is
> is possible to
> read the value for this attribute from the EObject, intuitively like
> this (pseudo code):
>
> EObject o ... ;
> EAttribute a = o.eClass.getAttribute( "a" );
> int aValue = o.getValue( a );
>
> I've searched the API, but couldn't find how to do this.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Reading attribute value from EObject programmatically [message #966939 is a reply to message #966925] Thu, 01 November 2012 11:00 Go to previous messageGo to next message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
Thanks for your prompt reply!

OK, but if I don't have the EAttribute object? That is, I only have the name of the attribute? Are there any EMF-ways to do this, or would I have to use reflection?
Re: Reading attribute value from EObject programmatically [message #966956 is a reply to message #966939] Thu, 01 November 2012 11:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Peter,

You need the EStructuralFeature, but as you showed in your own code, you
already know how to get that from the EObject's eClass().


On 01/11/2012 12:00 PM, Peter Johnsen wrote:
> Thanks for your prompt reply!
>
> OK, but if I don't have the EAttribute object? That is, I only have
> the name of the attribute? Are there any EMF-ways to do this, or would
> I have to use reflection?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Reading attribute value from EObject programmatically [message #966961 is a reply to message #966956] Thu, 01 November 2012 11:23 Go to previous message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
Ah, exactly! Thanks!
Previous Topic:EMF Notification: how to not get our own modifications?
Next Topic:EMF resource how to flush to disk
Goto Forum:
  


Current Time: Thu Apr 18 04:17:25 GMT 2024

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

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

Back to the top