Re: Xtend mirgration or how to perform M2M transformation with Xtend 2.x

534 views
Skip to first unread message

Sven Efftinge

unread,
Apr 9, 2013, 3:35:05 AM4/9/13
to xtend...@googlegroups.com
Hi Antoine,

I am not sure what exactly you need to understand, could you please ask more specifically?
Are you looking for the correct hook in Xtext or do you want to learn how to create and initialize objects?

Generally speaking you would write a method which gets passed in an EMF model and creates an EMF-XSD model.
The main difference to the old Xtend is that you now always write against java types, but with Xtext and XSD this is not a problem.

Sven


On Apr 8, 2013, at 10:20 AM, Antoine Logean <antoine...@opendata.ch> wrote:

Hi,

3 years ago we have developed a RCP client based on Xtext/Xtend 0.7. It as a very successful story and now it is time for an upgrate (I now this pretty late ...).  
Basically the client generates from a DSL instance an XSD file. For this we have used Xtend 0.7 that simply transform the DSL ecore model to an instance of XSD.ecore metamodel. The XSD serialisation is than an out-of-the-box feature of EMF. 
3 years ago was Xtend a powerful language dedicated to M2M transformation. Today many thing has changed and I was surprised to see that M2M transformations are no more in the feature list of Xtend. 

My question: how can I transform a DSL instance to an XSD file (using the XSD.ecore as metamodel). Belong M2M to the past :-) ? or is it still possible to do this with the wonderful toolkit Xtext/Xtend/Xpand ? Is it a better way to transform a DSL instance to an XSD file ?

I would be very interested to have some examples or tutorials regarding the processing of Xtext output. 

Thanks  in advance for your help and again congratulation for Xtext: it is really an amazing tool ! 

Antoine


--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Antoine Logean

unread,
Apr 9, 2013, 5:24:47 AM4/9/13
to xtend...@googlegroups.com
Hi Sven,

Nice to see that "the master" take time to answer dummy questions :-) Thanks a lot ! After having playing with Ruby during these last 3 years is my Java & EMF knowledge a little bit rosty ! Many thinks have changed. 

In the old solution (xtext/xtend 0.7) we have simply transform with Xtend the DSL instance to an XSD instance : 

<workflow>

<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri=".."/>
<component class="org.eclipse.xtext.MweReader" uri="${model_uri}">
<!-- this class will be generated by the xtext generator -->
<register class="de.uba.ics.FaktendatenStandaloneSetup"/>
</component>
<bean id="xsd_metamodel" class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel">
<schemaFile value="metamodel/xml.xsd" />
<schemaFile value="metamodel/xsd.xsd" />
</bean>

<component class="org.eclipse.xtend.XtendComponent">
<metaModel idRef="xsd_metamodel" />
<invoke value="templates::dsl2xsd::dsl2xsd(model)" />
<outputSlot value="xsd_model" />
</component>
<component class="org.eclipse.xtend.typesystem.xsd.XMLWriter">
<metaModel idRef="xsd_metamodel" />
<modelSlot value="xsd_model" />
<uri value="${targetDir}/${fileName}.xsd" />
</component>

</workflow>

with the Xtend transformation dsl2xsd.ext looking like this:

import xsd; 
import type; // for QName

import faktendaten;

extension org::eclipse::xtend::typesystem::xsd::lib::qname;
extension org::eclipse::xtend::typesystem::xsd::lib::map;

extension org::eclipse::xtend::util::stdlib::io;
extension templates::extensions;

String xsdNamespace() : "http://www.w3.org/2001/XMLSchema";

String defaultTargetNamespace() : "http://www.uba.de/2010/ics/faktendaten/";

String filename(XsdDocumentRoot r) :
r.schema.targetNamespace.split("/").last() + ".xsd"
;

String namespace(faktendaten::Model m) : defaultTargetNamespace() + m.name

String namespace(faktendaten::Type t) : ((Model)t.eContainer).namespace();

create XsdDocumentRoot dsl2xsd(Model m) :
this.createNamespacePrefixes(m) -> (
let s = new SchemaType :
s.setTargetNamespace(m.namespace()) ->
s.complexType.addAll(m.types.typeSelect(Type).createXsdType()) ->
m.hierarchy != null ? s.complexType.add(createXsdType(m.hierarchy)) : null ->
s.^import.addAll(m.imports.createImport())->
m.doc.value != null ? (
s.annotation.add(createAnnotationWithDocumentation(m.doc.value))
) : ( 
null 
) ->
this.setSchema(s)
)
;

create TopLevelComplexType createXsdType(Type t) :
this.setName(t.name) ->
...
;

...

The nice thing was that we do not had to write with Xpand the XSD generator. We simply transform the DSL-grammar (metamodel) to the XSD-metamodel and then let the org.eclipse.xtend.typesystem.xsd.XMLWriter do the job.

I assume that I have now to rewrite the M2M transformation within the MyDSLGenerator.xtend. and find the new XMLWriter. Right ?

Thanks for your help

Viele Grüsse aus Zürich

Antoine 

Pavel Tavoda

unread,
Apr 9, 2013, 7:20:13 AM4/9/13
to xtend...@googlegroups.com
Hello Antoine,
we are migrating big open source project Sculptor from old oAW to new Xtend2. You can find sources which are now translated nearly ONE-TO-ONE from old version to new. I did about 70% of work via simple search/replace (with sed). We now have extensions, transformation, check, text production in Xtend2. More examples you cand find:
Old oAW code:
New XTend2:

Transformations are in 'transformation' directory, extensions in 'extensions' and 'ext', text production is in 'templates'.

Hope this help

Pavel

Sven Efftinge

unread,
Apr 10, 2013, 2:46:59 AM4/10/13
to xtend...@googlegroups.com
When you have created an XSD model, it should be as simple creating an EMF resource (using the ResourceFactory for XSD, or the registry with a proper file extension)
and use it to save the model. If that doesn't work for you the EMF newsgroup can definitely help with that.

Antoine Logean

unread,
Apr 12, 2013, 4:52:27 AM4/12/13
to xtend...@googlegroups.com
Sven, Pavel,

I finally simply do a M2T and generate the XSD by using the MyDSLGenerator.xtend. It is much more simple. I realize that in my case the the DSL and the XSD has more or less the same tree structure and a M2M transformation make here no sense.

Tanks a lot for your help

Antoine  

Sven Efftinge

unread,
Apr 13, 2013, 11:02:26 AM4/13/13
to xtend...@googlegroups.com

On Apr 12, 2013, at 10:52 AM, Antoine Logean <antoine...@opendata.ch> wrote:

> Sven, Pavel,
>
> I finally simply do a M2T and generate the XSD by using the MyDSLGenerator.xtend. It is much more simple. I realize that in my case the the DSL and the XSD has more or less the same tree structure and a M2M transformation make here no sense.

Excellent :-)
Reply all
Reply to author
Forward
0 new messages