|
|
|
|
Re: Xtext project from ECore with abstract types [message #1067077 is a reply to message #1067058] |
Fri, 05 July 2013 17:20 |
Vincent De Bry Messages: 55 Registered: May 2013 |
Member |
|
|
Ed, thanks to try helping me.
Actually, I was first surprised that the XText project creation from the Ecore does not generate a rule for CTSensEvent, for example.
So I defined it (and the type 'Decimal') by myself like this
Decimal returns ecore::EBigDecimal:
INT;
CTSentEvent returns ComponentType::CTSentEvent:
'eventSent' period=Decimal;
I am first wondering if it is normal that I have to define it manually, as everything is in the Ecore.
Then, as CTSentEvent inherits from CTEvent, I would expect that the attribute 'parameter' from CTEvent would be immediatly proposed during file edition, by the content assist. As it does not work like that, I ment I should define a rule for CTEvent like:
CTEvent returns ComponentType::CTEvent:
parameter=CTQualifiedField;
and do so that rule CTSentEvent inherits from CTEvent (but how ? I don't know !)
The only solution I have found seems to duplicate the inherited attribtes in each rule associated to a super type, like:
Decimal returns ecore::EBigDecimal:
INT;
CTSentEvent returns ComponentType::CTSentEvent:
'eventSent' period=Decimal
parameter=CTQualifiedField
...;
But doing so, I am loosing the interest of having a super type, I mean ...
What do you mean ?
Thank you very much.
|
|
|
|
|
|
Re: Xtext project from ECore with abstract types [message #1067523 is a reply to message #1067511] |
Tue, 09 July 2013 08:30 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Vincent,
Here's a complete example of what I had in mind. Note the ecore
annotation to suppress the feature maps for substitution groups and the
type specifies for the "all_operations" element.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
ecore:ignoreSubstitutionGroups="true">
<xsd:complexType name="CT_operation" abstract="true">
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="CT_event" abstract="true">
<xsd:complexContent>
<xsd:extension base="CT_operation">
<xsd:sequence>
<xsd:element name="parameter" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="CT_sent_event">
<xsd:complexContent>
<xsd:extension base="CT_event">
<xsd:attribute name="period" type="xsd:decimal" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="CT_received_event">
<xsd:complexContent>
<xsd:extension base="CT_event"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="all_operations" abstract="true" type="CT_event"/>
<xsd:element name="event_received" type="CT_received_event"
substitutionGroup="all_operations">
<xsd:unique name="param_event_received">
<xsd:selector xpath="parameter"/>
<xsd:field xpath="@name"/>
</xsd:unique>
</xsd:element>
<xsd:element name="event_sent" type="CT_sent_event"
substitutionGroup="all_operations">
<xsd:unique name="param_event_sent">
<xsd:selector xpath="parameter"/>
<xsd:field xpath="@name"/>
</xsd:unique>
</xsd:element>
<xsd:complexType name="CT_operations">
<xsd:sequence>
<xsd:element ref="all_operations" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
And yes, the result is that you end up with a single getAllOperations
feature that contains CTEvent instances, which can be either CTSentEvent
or CTReceivedEvent instances so processing will require iterating over
the whole list and doing instanceof checks. Given that Xtext doesn't
support feature maps (as far as I know) and given that you need to
preserve/represent the mixed order of these things, you need such an
overall feature.
If your real schema specifies elementFormDefault="unqualified" then this
new representation will result in the use of qualified element names
because you've made the element global rather than local, so I'm not
sure this solutions pans out for you.
On 09/07/2013 10:02 AM, Vincent De Bry wrote:
> Hi Ed,
>
> You are right, my adaptation does not match my need. So I tried to use
> substitution groups but I probably did not caught something as with
> the following adapted XSD, I still get a EFeatureMapEntry in my Ecore
> and, moreover, no feature for "event_received" and "event_sent" but a
> single feature on "all_operations" instead :(
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="unqualified"
> attributeFormDefault="unqualified">
>
> <xsd:complexType name="CT_operation" abstract="true">
> <xsd:attribute name="name" type="xsd:string" use="required"/>
> </xsd:complexType>
>
> <xsd:complexType name="CT_event" abstract="true">
> <xsd:complexContent>
> <xsd:extension base="CT_operation">
> <xsd:sequence>
> <xsd:element name="parameter" type="xsd:string" minOccurs="0"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="CT_sent_event">
> <xsd:complexContent>
> <xsd:extension base="CT_event">
> <xsd:attribute name="period" type="xsd:decimal" use="optional"/>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="CT_received_event">
> <xsd:complexContent>
> <xsd:extension base="CT_event"/>
> </xsd:complexContent>
> </xsd:complexType>
>
>
>
> <xsd:element name="all_operations" abstract="true"/>
>
> <xsd:element name="event_received" type="CT_received_event"
> substitutionGroup="all_operations">
> <xsd:unique name="param_event_received">
> <xsd:selector xpath="parameter"/>
> <xsd:field xpath="@name"/>
> </xsd:unique>
> </xsd:element>
>
> <xsd:element name="event_sent" type="CT_sent_event"
> substitutionGroup="all_operations">
> <xsd:unique name="param_event_sent">
> <xsd:selector xpath="parameter"/>
> <xsd:field xpath="@name"/>
> </xsd:unique>
> </xsd:element>
>
> <xsd:complexType name="CT_operations">
> <xsd:sequence>
> <xsd:element ref="all_operations" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> </xsd:schema>
>
>
> could you please help me pointing what is wrong ?
> note That I also did not succeed in defining intermediate subsitution
> groups for replacing "operations_in_transaction" and
> "operations_not_in_transaction" :(
>
> Thanks
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04327 seconds