|
Re: XML schema import and EEnums [message #417864 is a reply to message #417862] |
Thu, 27 March 2008 15:16 |
Ed Merks 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 |
Tillmann Seidel 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
|
|
|
Powered by
FUDForum. Page generated in 0.03715 seconds