|
Re: EObject.eIsSet and default value [message #653480 is a reply to message #653435] |
Wed, 09 February 2011 21:47 |
Alan McMorran 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)?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03555 seconds