Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EObject.eIsSet and default value
EObject.eIsSet and default value [message #653435] Wed, 09 February 2011 18:26 Go to next message
keller_jens is currently offline keller_jensFriend
Messages: 21
Registered: March 2010
Location: Germany
Junior Member
Hi,
I have a question related to EObject.eIsSet and default values.

In my ecore I have an EClass "Property" that has an attribute "maxLength".
The attribute is optional (lowerbound=0, upperbound=1) and as default value literal I specified 256.
The EType is Int [int].

Now at runtime there are two cases interesting for me:
a) <property name="whatever" maxLength="256"/>
b) <property name="whatever2"/>

Now whatever.getMaxLength() and whatever2.getMaxLength() return the same value, which is what I expected. For whatever2 the default value should be taken as the attribute was not specified in the XML.

But I expected that whatever.eIsSet(maxLengthFeature) returns "true", and whatever2.eIsSet(maxLengthFeature) returns "false", but this is not the case.

How can I distinguish these two cases:
a) an attribute is not set, so I just get the default value
b) an attribute is set, but coincidentally the value is just the same as the default value

Am I using the wrong method(s) or do I need to change my model (e.g. using Integer instead of the native int)?
Re: EObject.eIsSet and default value [message #653480 is a reply to message #653435] Wed, 09 February 2011 21:47 Go to previous messageGo to next message
Alan McMorran is currently offline Alan McMorranFriend
Messages: 55
Registered: July 2009
Member
It sounds like the EAttribute is not 'unsettable'. By default an
attribute will always return the default value when it's type is a
primitive since a variable with a primitive type can't be set as null
in Java. If I remember rightly eSet by default will check if the eGet
return type is a null or empty list, so for an attribute with primitive
types the internal variable will be initialised to the default value
(where as a String attribute for example will be initialised to null,
or an EReference will be an empty EList for 0..n or null for 0..1)

If you make 'unsettable' be true then it will track whether the
attribute value has been set or not and eSet will check this flag as
well as the value. It should then work correctly for attributes with a
primitive type.

Alan

On 2011-02-09 19:26:58 +0100, Jens Keller said:

> Hi,
> I have a question related to EObject.eIsSet and default values.
>
> In my ecore I have an EClass "Property" that has an attribute "maxLength".
> The attribute is optional (lowerbound=0, upperbound=1) and as default
> value literal I specified 256.
> The EType is Int [int].
>
> Now at runtime there are two cases interesting for me:
> a) <property name="whatever" maxLength="256"/>
> b) <property name="whatever2"/>
>
> Now whatever.getMaxLength() and whatever2.getMaxLength() return the
> same value, which is what I expected. For whatever2 the default value
> should be taken as the attribute was not specified in the XML.
>
> But I expected that whatever.eIsSet(maxLengthFeature) returns "true",
> and whatever2.eIsSet(maxLengthFeature) returns "false", but this is not
> the case.
>
> How can I distinguish these two cases:
> a) an attribute is not set, so I just get the default value
> b) an attribute is set, but coincidentally the value is just the same
> as the default value
>
> Am I using the wrong method(s) or do I need to change my model (e.g.
> using Integer instead of the native int)?
Re: EObject.eIsSet and default value [message #653620 is a reply to message #653435] Thu, 10 February 2011 13:01 Go to previous message
keller_jens is currently offline keller_jensFriend
Messages: 21
Registered: March 2010
Location: Germany
Junior Member
Thanks Alan, that did the trick.
Previous Topic:Overriding EcoreUtil.copy behaviour to make a truly 'self-contained' copy
Next Topic:[CDO] Exception using Resource Import
Goto Forum:
  


Current Time: Tue Apr 16 17:38:21 GMT 2024

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

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

Back to the top