Home » Modeling » EMF » Default value of EAttribute typed to an Enumeration
Default value of EAttribute typed to an Enumeration [message #431752] |
Thu, 23 July 2009 12:52  |
Eclipse User |
|
|
|
I noticed that the default value of an attribute that has been typed to a
Java enumeration ends up being the first member of that enumeration and
that isESet checks whether the attribute is different from the default
value (as opposed to checking against null).
The problem I am facing is if I have an attribute that is required
(cardinality 1..1), it doesn't have a default literal value, and I want to
set it to the first member of an enumeration. It turns out not getting
serialized because both cases fail (isESet || (keepDefaults &&
getDefaultLiteral() != null).
Is there a way to override this behavior (other than doing so in codegen)
to solve my problem?
Thanks,
JT
|
|
| | | | |
Re: Default value of EAttribute typed to an Enumeration [message #431767 is a reply to message #431761] |
Fri, 24 July 2009 07:30   |
Eclipse User |
|
|
|
--=-/Riwv3yOaf5JPGdE7NHz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi, John,
Myself, I always include an explicit "none" value in my enumerations, as
the first literal, when the enumeration needs to have optional
semantics. Sometimes I even go so far is implementing the "Null Object"
pattern by mixing in a common interface that defines an isUndefined()
operation, which usually is implemented in an enum as "this == NONE".
Would that help your situation? It would mean only updating your enums,
not your attributes of those types.
Cheers,
Christian
On Thu, 2009-07-23 at 23:57 +0000, John T.E. Timm wrote:
> Of course after spending all this time investigating the code templates
> and obsessing over getting an Enumeration based attribute to be null, I
> realized that I all really need is for the attribute to be marked as
> "unsettable" to add unset to the value space. How embarrasing. :) Anyways,
> I see now that regardless of what I set the value to, if I call setXXX, it
> will mark it as set and will be serialized as such. Unfortunately, I have
> literally hundreds of attributes in my model that need to be changed.
>
> Thakns,
>
> JT
>
--=-/Riwv3yOaf5JPGdE7NHz
Content-Type: text/html; charset="utf-8"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, John,<BR>
<BR>
Myself, I always include an explicit "none" value in my enumerations, as the first literal, when the enumeration needs to have optional semantics. Sometimes I even go so far is implementing the "Null Object" pattern by mixing in a common interface that defines an isUndefined() operation, which usually is implemented in an enum as "this == NONE".<BR>
<BR>
Would that help your situation? It would mean only updating your enums, not your attributes of those types.<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Thu, 2009-07-23 at 23:57 +0000, John T.E. Timm wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Of course after spending all this time investigating the code templates
and obsessing over getting an Enumeration based attribute to be null, I
realized that I all really need is for the attribute to be marked as
"unsettable" to add unset to the value space. How embarrasing. :) Anyways,
I see now that regardless of what I set the value to, if I call setXXX, it
will mark it as set and will be serialized as such. Unfortunately, I have
literally hundreds of attributes in my model that need to be changed.
Thakns,
JT
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>
--=-/Riwv3yOaf5JPGdE7NHz--
|
|
| |
Re: Default value of EAttribute typed to an Enumeration [message #431776 is a reply to message #431774] |
Fri, 24 July 2009 12:03   |
Eclipse User |
|
|
|
Ed:
What it came down to was that I actually didn't need null. What I really
needed was the "unset" value. The isUnsettable property takes care of this
for me.
Thanks,
JT
Ed Merks wrote:
> John,
> I'm not sure in the end if you got what you wanted. You could make it
> unsettable and you could specify an explicit default. If you really
> want null to be a value, you have to create another EDataType that wraps
> the generated enumeration type; any model with EEnums generated from XML
> Schemas does this automatically to support nillable elements...
> John T.E. Timm wrote:
>> Of course after spending all this time investigating the code
>> templates and obsessing over getting an Enumeration based attribute to
>> be null, I realized that I all really need is for the attribute to be
>> marked as "unsettable" to add unset to the value space. How
>> embarrasing. :) Anyways, I see now that regardless of what I set the
>> value to, if I call setXXX, it will mark it as set and will be
>> serialized as such. Unfortunately, I have literally hundreds of
>> attributes in my model that need to be changed.
>>
>> Thakns,
>>
>> JT
>>
|
|
|
Re: Default value of EAttribute typed to an Enumeration [message #431777 is a reply to message #431767] |
Fri, 24 July 2009 12:09  |
Eclipse User |
|
|
|
Hi Christian,
Thank you for your suggestions. I am modeling various controlled
vocabularies that are part of a standard with these enumerations. I think
that adding an explicit "none" value could work well in my situation but I
would like to leave the actual enumerations alone if possible. In my
application, I decided that I care more about the "unset" value. At first
I thought that getting the Enumeration to be null was the only way, but
with the isUnsettable option, the generated code keeps track of a separate
"unset" value which I feel should work well.
Thanks,
JT
Christian W. Damus wrote:
> Hi, John,
> Myself, I always include an explicit "none" value in my enumerations, as
> the first literal, when the enumeration needs to have optional
> semantics. Sometimes I even go so far is implementing the "Null Object"
> pattern by mixing in a common interface that defines an isUndefined()
> operation, which usually is implemented in an enum as "this == NONE".
> Would that help your situation? It would mean only updating your enums,
> not your attributes of those types.
> Cheers,
> Christian
> On Thu, 2009-07-23 at 23:57 +0000, John T.E. Timm wrote:
>> Of course after spending all this time investigating the code templates
>> and obsessing over getting an Enumeration based attribute to be null, I
>> realized that I all really need is for the attribute to be marked as
>> "unsettable" to add unset to the value space. How embarrasing. :) Anyways,
>> I see now that regardless of what I set the value to, if I call setXXX, it
>> will mark it as set and will be serialized as such. Unfortunately, I have
>> literally hundreds of attributes in my model that need to be changed.
>>
>> Thakns,
>>
>> JT
>>
|
|
|
Goto Forum:
Current Time: Tue Jul 08 18:04:27 EDT 2025
Powered by FUDForum. Page generated in 0.27439 seconds
|