Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XML schema import and EEnums
XML schema import and EEnums [message #417862] Thu, 27 March 2008 12:58 Go to next message
Tillmann Seidel is currently offline Tillmann SeidelFriend
Messages: 5
Registered: July 2009
Junior Member
Hi,

I have a problem with the XML schema import and EEnums.

In my schema, there is an simple enumeration type

<xsd:simpleType name="MyEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="a" />
<xsd:enumeration value="b" />
<xsd:enumeration value="c" />
</xsd:restriction>
</xsd:simpleType>

and I have an element which has an optional attribute of that type

<xsd:complexType name="MyElement">
<xsd:attribute name="value" use="optional" type="test:MyEnum"/>
</xsd:complexType>

After the XML schema import, my enumeration type is represented by an
EEnum. EMF automatically sets a default value for the type (apparently
the first one it can find, i.e. "a").
I modeled the attribute as optional in the XML schema in order to
differentiate between "not set" and "set to a". However EMF
automatically assumes the default value "a" if there is no value defined
in the XML.

I've found a comment by Ed about this problem in the newsgroup
( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 5993.html)
stating that EEnums are never nillable. Nillable elements use this
wrapper type instead of the EEnum directly.

Now I have two questions here:
- No matter whether the attribute in my schema is optional or required,
the generated type for my attribute is always the EEnum, never the
wrapper EDataType. Shouldn't it be the wrapper type if the attribute is
optional? Or did I misunderstand what is meant by "nillable elements"?
- The generated PropertySheetEntry for the enumeration type provides a
text field if I use the wrapper EDataType (instead of a Combo if I use
the EEnum). However I haven't found a way to set the attribute to null
in the text field. Is there a trick to do it or do I have to program the
sheet entry myself to allow users to set the value to null?

Thanks in advance
Tillmann
Re: XML schema import and EEnums [message #417864 is a reply to message #417862] Thu, 27 March 2008 15:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Tillmann,

Comments below.


Tillmann Seidel wrote:
> Hi,
>
> I have a problem with the XML schema import and EEnums.
>
> In my schema, there is an simple enumeration type
>
> <xsd:simpleType name="MyEnum">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="a" />
> <xsd:enumeration value="b" />
> <xsd:enumeration value="c" />
> </xsd:restriction>
> </xsd:simpleType>
>
> and I have an element which has an optional attribute of that type
>
> <xsd:complexType name="MyElement">
> <xsd:attribute name="value" use="optional" type="test:MyEnum"/>
> </xsd:complexType>
>
> After the XML schema import, my enumeration type is represented by an
> EEnum. EMF automatically sets a default value for the type (apparently
> the first one it can find, i.e. "a").
Yes, EMF treats EEnums as being like a Java primitive type and hence
ensures that a feature of that type will never return null.
> I modeled the attribute as optional in the XML schema in order to
> differentiate between "not set" and "set to a". However EMF
> automatically assumes the default value "a" if there is no value
> defined in the XML.
The feature should be unsettable though and hence you'll be able to test
MyElement.isSetValue().
>
> I've found a comment by Ed about this problem in the newsgroup
> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 5993.html)
> stating that EEnums are never nillable. Nillable elements use this
> wrapper type instead of the EEnum directly.
Yes, if it were a nillable element, we have a wrapper type for the EEnum
that makes it be just a plain old EDataType whose value is allowed to be
null.
>
> Now I have two questions here:
> - No matter whether the attribute in my schema is optional or
> required, the generated type for my attribute is always the EEnum,
> never the wrapper EDataType. Shouldn't it be the wrapper type if the
> attribute is optional? Or did I misunderstand what is meant by
> "nillable elements"?
Nillable means <xsd:element ... nillable="true"/>. Only in that case
will the wrapper type be used.
> - The generated PropertySheetEntry for the enumeration type provides a
> text field if I use the wrapper EDataType (instead of a Combo if I use
> the EEnum). However I haven't found a way to set the attribute to null
> in the text field. Is there a trick to do it or do I have to program
> the sheet entry myself to allow users to set the value to null?
Even if you set it to null, you'll still find when you call the getter,
it will return the first enum. To make the problem worse, the
properties view has very poor support for controlling unsettable
features. It's grossly difficult to explicitly set a feature's value to
the first enum; you'd need to set it to a different value and then to
the first value to explicitly set it to the first value. Hopefully if I
can get clear of the current insanity that's keeping me busy every
waking moment, I can address
https://bugs.eclipse.org/bugs/show_bug.cgi?id=222754 to make it easier.
>
> Thanks in advance
> Tillmann


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XML schema import and EEnums [message #417997 is a reply to message #417864] Tue, 01 April 2008 15:15 Go to previous message
Tillmann Seidel is currently offline Tillmann SeidelFriend
Messages: 5
Registered: July 2009
Junior Member
Hi Ed,

Thanks for the clarification. We got it done using the unsettable flag.

I hope you can get rid of the current insanity once in a while - I'm
eagerly keeping an eye on the developments of the properties view :)

Best regards
Tillmann

Ed Merks schrieb:
> Tillmann,
>
> Comments below.
>
>
> Tillmann Seidel wrote:
>> Hi,
>>
>> I have a problem with the XML schema import and EEnums.
>>
>> In my schema, there is an simple enumeration type
>>
>> <xsd:simpleType name="MyEnum">
>> <xsd:restriction base="xsd:string">
>> <xsd:enumeration value="a" />
>> <xsd:enumeration value="b" />
>> <xsd:enumeration value="c" />
>> </xsd:restriction>
>> </xsd:simpleType>
>>
>> and I have an element which has an optional attribute of that type
>>
>> <xsd:complexType name="MyElement">
>> <xsd:attribute name="value" use="optional" type="test:MyEnum"/>
>> </xsd:complexType>
>>
>> After the XML schema import, my enumeration type is represented by an
>> EEnum. EMF automatically sets a default value for the type (apparently
>> the first one it can find, i.e. "a").
> Yes, EMF treats EEnums as being like a Java primitive type and hence
> ensures that a feature of that type will never return null.
>> I modeled the attribute as optional in the XML schema in order to
>> differentiate between "not set" and "set to a". However EMF
>> automatically assumes the default value "a" if there is no value
>> defined in the XML.
> The feature should be unsettable though and hence you'll be able to test
> MyElement.isSetValue().
>>
>> I've found a comment by Ed about this problem in the newsgroup
>> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 5993.html)
>> stating that EEnums are never nillable. Nillable elements use this
>> wrapper type instead of the EEnum directly.
> Yes, if it were a nillable element, we have a wrapper type for the EEnum
> that makes it be just a plain old EDataType whose value is allowed to be
> null.
>>
>> Now I have two questions here:
>> - No matter whether the attribute in my schema is optional or
>> required, the generated type for my attribute is always the EEnum,
>> never the wrapper EDataType. Shouldn't it be the wrapper type if the
>> attribute is optional? Or did I misunderstand what is meant by
>> "nillable elements"?
> Nillable means <xsd:element ... nillable="true"/>. Only in that case
> will the wrapper type be used.
>> - The generated PropertySheetEntry for the enumeration type provides a
>> text field if I use the wrapper EDataType (instead of a Combo if I use
>> the EEnum). However I haven't found a way to set the attribute to null
>> in the text field. Is there a trick to do it or do I have to program
>> the sheet entry myself to allow users to set the value to null?
> Even if you set it to null, you'll still find when you call the getter,
> it will return the first enum. To make the problem worse, the
> properties view has very poor support for controlling unsettable
> features. It's grossly difficult to explicitly set a feature's value to
> the first enum; you'd need to set it to a different value and then to
> the first value to explicitly set it to the first value. Hopefully if I
> can get clear of the current insanity that's keeping me busy every
> waking moment, I can address
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=222754 to make it easier.
>>
>> Thanks in advance
>> Tillmann
Previous Topic:new attribute to a class on my model
Next Topic:efficient emf query
Goto Forum:
  


Current Time: Fri Apr 26 08:59:34 GMT 2024

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

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

Back to the top