Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Default Values of simpleContent(Does EMF support default values?)
Default Values of simpleContent [message #643366] Mon, 06 December 2010 16:33 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi, I've been looking at an issue involving default values, if I have a schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.com/ElementSimpleDefault" targetNamespace="http://example.com/ElementSimpleDefault">
	<xsd:element name="elementWithDefault" type="tns:NewType" default="10"/>
	<xsd:complexType name="NewType">
		<xsd:simpleContent>
			<xsd:extension base="xsd:integer">
				<xsd:attribute name="NewAttribute" type="xsd:string"/>
				<xsd:attribute name="NewAttribute1" type="xsd:string"/>
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
</xsd:schema>


And then get it to load the following XML:

<default:elementWithDefault
	xmlns:default="http://example.com/ElementSimpleDefault"
	NewAttribute="attrib"
	NewAttribute1="attrib1"/>


Then it will fail with the exception:

org.eclipse.emf.ecore.xmi.IllegalValueException: Value '' is not legal.


This seems to be caused by the fact that the default value of "10" is not being used when it is not specified in any input XML.

Is this a know issue - or am I doing something wrong some-where?

Thanks

Rob
Re: Default Values of simpleContent [message #643402 is a reply to message #643366] Mon, 06 December 2010 18:09 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Rob,

This looks to be one of those horrible cases that just doesn't map
well. Complex types map to EClasses, features with an EClass as their
type must be an EReference, and an EReference doesn't support a default
value. In the end, the "value" feature of NewType in Ecore needs to
specify a default, but there's no way to specify that in the schema and
there's no way for it to be different depending on where it's used so
that doesn't solve the problem either. Even the difference between

<default:elementWithDefault
xmlns:default="http://example.com/ElementSimpleDefault"
NewAttribute="attrib"
NewAttribute1="attrib1"/>

and

<default:elementWithDefault
xmlns:default="http://example.com/ElementSimpleDefault"
NewAttribute="attrib"
NewAttribute1="attrib1"></default:elementWithDefault

is very subtle. Is the former correct and the latter incorrect? If
it's correct, does that make it impossible to specify an empty string
when there is a default?

I'm not sure this problem is fixable...


Rob wrote:
> Hi, I've been looking at an issue involving default values, if I have
> a schema:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:tns="http://example.com/ElementSimpleDefault"
> targetNamespace="http://example.com/ElementSimpleDefault">
> <xsd:element name="elementWithDefault" type="tns:NewType"
> default="10"/>
> <xsd:complexType name="NewType">
> <xsd:simpleContent>
> <xsd:extension base="xsd:integer">
> <xsd:attribute name="NewAttribute" type="xsd:string"/>
> <xsd:attribute name="NewAttribute1" type="xsd:string"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
> </xsd:schema>
>
> And then get it to load the following XML:
>
> <default:elementWithDefault
> xmlns:default="http://example.com/ElementSimpleDefault"
> NewAttribute="attrib"
> NewAttribute1="attrib1"/>
>
> Then it will fail with the exception:
>
> org.eclipse.emf.ecore.xmi.IllegalValueException: Value '' is not legal.
>
> This seems to be caused by the fact that the default value of "10" is
> not being used when it is not specified in any input XML.
>
> Is this a know issue - or am I doing something wrong some-where?
>
> Thanks
>
> Rob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to create an apply a UML2 stereo-type using EMF in a standalone app?
Next Topic:Anonymous Enumerations Always Get Default Value
Goto Forum:
  


Current Time: Thu Mar 28 15:19:18 GMT 2024

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

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

Back to the top