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 06:31 Go to next message
Peter Johnsen is currently offline Peter Johnsen
Messages: 50
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 06:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25740
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.
Re: Reading attribute value from EObject programmatically [message #966939 is a reply to message #966925] Thu, 01 November 2012 07:00 Go to previous messageGo to next message
Peter Johnsen is currently offline Peter Johnsen
Messages: 50
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 07:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25740
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?
Re: Reading attribute value from EObject programmatically [message #966961 is a reply to message #966956] Thu, 01 November 2012 07:23 Go to previous message
Peter Johnsen is currently offline Peter Johnsen
Messages: 50
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 17 03:34:59 EDT 2014

Powered by FUDForum. Page generated in 0.03149 seconds