Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » generated EReference defaulting to changeable="false"
generated EReference defaulting to changeable="false" [message #414654] Fri, 16 November 2007 01:22 Go to next message
Ted Bashor is currently offline Ted BashorFriend
Messages: 6
Registered: July 2009
Junior Member
Hi, I'm generating ecore from an xsd and am finding that some of my
element lists are being marked as non-changeable by default (source xsd
and generated ecore below).

Found a cryptic note in
http://wiki.eclipse.org/Authoring_XML_Schemas_for_use_with_E MF
in the Mapping Element to Contained EReference section,
ecore:changeable="false|true*"
True by default
* may be false when featureMaps are involved (review needed)

Was wondering if there's a mechanism for getting this to default to true,
given that I'll likely have to do the xsd update -> ecore -> gmf ->
diagram several times. Thanks much.

XSD:
...
<xsd:element name="model" type="defaultModelType"
substitutionGroup="abstract-model"/>
<xsd:element name="abstract-model" abstract="true"
type="abstractModelType"/>
<xsd:complexType name="abstractModelType">
<xsd:sequence>
<xsd:element ref="abstract-exception-strategy" minOccurs="0"/>
<xsd:element ref="abstract-entrypoint-resolver" minOccurs="0"/>
<xsd:element ref="abstract-service" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="class" type="xsd:NMTOKEN"/>
</xsd:complexType>
...

ecore:
...
<eStructuralFeatures xsi:type="ecore:EAttribute"
name="abstractServiceGroup" unique="false"
upperBound="-1" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="group"/>
<details key="name" value="abstract-service:group"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference"
name="abstractService" upperBound="-1"
eType="#//AbstractServiceType" changeable="false" volatile="true"
transient="true"
derived="true" containment="true" resolveProxies="false">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="abstract-service"/>
<details key="namespace" value="##targetNamespace"/>
<details key="group" value="abstract-service:group"/>
</eAnnotations>
</eStructuralFeatures>
...
Re: generated EReference defaulting to changeable="false" [message #414676 is a reply to message #414654] Fri, 16 November 2007 11:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Ted,

I'll assume that every "abstract-*" element has abstract="true" because
it's the head of a substitution group. The problem is that you have
abstract elements so if you could simply do x.setAbstractModel(model) it
would be serialized as <xyz:abstract-model xsi:type="xyz:ModelType">
which is not a valid serialization. You'll need to use
x.getAbstractModelGroup().add(XyzPackage.Literals.DOCUMENT_R OOT__MODEL,
model) to serialize as <xyz:model>. So while substitution groups are
syntactic sugar in XML Schema, they are semantic rat poison in your
abstract model.


Ted Bashor wrote:
> Hi, I'm generating ecore from an xsd and am finding that some of my
> element lists are being marked as non-changeable by default (source
> xsd and generated ecore below).
> Found a cryptic note in
> http://wiki.eclipse.org/Authoring_XML_Schemas_for_use_with_E MF
> in the Mapping Element to Contained EReference section,
> ecore:changeable="false|true*" True by default
> * may be false when featureMaps are involved (review needed)
>
> Was wondering if there's a mechanism for getting this to default to
> true, given that I'll likely have to do the xsd update -> ecore -> gmf
> -> diagram several times. Thanks much.
>
> XSD:
> ...
> <xsd:element name="model" type="defaultModelType"
> substitutionGroup="abstract-model"/>
> <xsd:element name="abstract-model" abstract="true"
> type="abstractModelType"/>
> <xsd:complexType name="abstractModelType">
> <xsd:sequence>
> <xsd:element ref="abstract-exception-strategy" minOccurs="0"/>
> <xsd:element ref="abstract-entrypoint-resolver"
> minOccurs="0"/>
> <xsd:element ref="abstract-service" minOccurs="0"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> <xsd:attribute name="name" type="xsd:string" use="required"/>
> <xsd:attribute name="class" type="xsd:NMTOKEN"/>
> </xsd:complexType>
> ...
>
> ecore:
> ...
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="abstractServiceGroup" unique="false"
> upperBound="-1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="group"/>
> <details key="name" value="abstract-service:group"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="abstractService" upperBound="-1"
> eType="#//AbstractServiceType" changeable="false"
> volatile="true" transient="true"
> derived="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="abstract-service"/>
> <details key="namespace" value="##targetNamespace"/>
> <details key="group" value="abstract-service:group"/>
> </eAnnotations>
> </eStructuralFeatures>
> ...
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: generated EReference defaulting to changeable="false" [message #415105 is a reply to message #414676] Thu, 29 November 2007 21:11 Go to previous messageGo to next message
Ted Bashor is currently offline Ted BashorFriend
Messages: 6
Registered: July 2009
Junior Member
A belated thanks to Ed for the help, and thanks too for the colorful
metaphor - I enjoyed telling people substitution groups are semantic rat
poison :-)

A tip for EMF 2.3 newbies: looks like there's been some code change,
cause there doesn't seem to be a Literals in the generated Package, plus
FeatureMap.add(int, E) method wants a typed FeatureMap.Entry for the
second parameter.

You could do what Ed suggested a few different ways, but the following
worked for me.

FeatureMap map = container.getAbstractElementGroup();
map.add(XYZPackage.eINSTANCE.getDocumentRoot_ConcreteElement (),
concreteElement);
Re: generated EReference defaulting to changeable="false" [message #415106 is a reply to message #415105] Thu, 29 November 2007 21:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Ted,

I'm actually working on a new serialization feature that will deduce
substitution group elements during save. This way you can have your
syntactic sugar without the associated dose of rat poison in the API.
I'll open a bugzilla soon and describe the new support; maybe I'll have
time to write a blog again.

Note that there is a GenPackage property "Literals" that controls
whether the Literals interface is generated. For large models this
interface can exceed Java's byte code limits so the property defaults to
false in that case.


Ted Bashor wrote:
> A belated thanks to Ed for the help, and thanks too for the colorful
> metaphor - I enjoyed telling people substitution groups are semantic
> rat poison :-)
>
> A tip for EMF 2.3 newbies: looks like there's been some code change,
> cause there doesn't seem to be a Literals in the generated Package,
> plus FeatureMap.add(int, E) method wants a typed FeatureMap.Entry for
> the second parameter.
>
> You could do what Ed suggested a few different ways, but the following
> worked for me.
>
> FeatureMap map = container.getAbstractElementGroup();
> map.add(XYZPackage.eINSTANCE.getDocumentRoot_ConcreteElement (),
> concreteElement);
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Iteration over model elements
Next Topic:TransactionalEditingDomain in EMF generated editors
Goto Forum:
  


Current Time: Fri Apr 26 22:06:43 GMT 2024

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

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

Back to the top