View Christos Tranoris's profile on LinkedIn

Visit The Model Driven Software Network

Who's online

There are currently 0 users and 13 guests online.

Recent comments


Syndicate content

Textual DSLs Tutorial: Xtext, existing ecore models and persistent objects with Hibernate

In this short post, I would like to show you how easy it is to integrate persistent objects with Xtext (my favorite toy the last few months). For this experiment I used Eclipse Helios milestone build (and relevant updates of emf, teneo, hibernate) and xtext build 0.8.0M3. I also have used mySQL for the storage.
The reason of this tutorial is that I wanted a solution where my DSL can easily include predefined persistent objects and of course appear in the famous content assist editor.
First things first: Make yourself familiar with emf database persistency with Teneo and Hibernate and of course with Xtext
It is assumed that you have done one of the EMF Library tutorials to generate the model, edit and editor code and then please read this EMF Hibernate tutorial for making a library editor.
For the following example I have named the library mylib, the editor file has the extension .mylib and I created a database in mysql named mylib. Thus, I defined in my ecore model the following: Name: mylib, Ns Prefix: org.eclipse.example.mylib and Ns URI: http:///org/eclipse/example/mylib.ecore
Finally, after running (Run As..)the Eclipse Application, you should create a new My.mylib file and you may add some data like the following picture shows. The data are also persistent in the mySql database mylib.

 Now we must create some xtext based grammar. I created a new xtext project named gr.softwareagility.mylib.libdsl with DSL file extension libdsl. My project structure looks like the following:

And here is a really short xText grammar, just to display our purpose: Notice here that I leave the generate keyword because I need a mix of existing and a generated ecore.

For gr.softwareagility.mylib.libdsl, gr.softwareagility.mylib.libdsl.ui plugins add dependency to the plugin of the model. Edit the mwe file in the proper place like the following:
<!-- generates Java API for the generated EPackages -->
<fragment class="org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment" genModels="platform:/resource/gr.softwareagility.mylib/model/mylib.genmodel"/>

Generate your grammar with xtext. Note also that in the plugin.xml (where you have the hibernate libraries) insert also on Eclipse-RegisterBuddy the gr.softwareagility.mylib.libdsl.ui and run the Eclipse Application.
If you encounter errors when lunching the application, have in mind that the plugin that loads the database must be started first. So for this example open first the my.mylib file (just to start the database) and then edit the .libdsl file.
Here how it should look like while editing the file:

Notice how the writers come from the database as valid objects in the content assist.
A few important remarks: You will notice that books doesn't appear in content assist. The reason is that they don't have a "name:EString" attribute. Of course you can do further magic with Scoping and ProposalProviders

Posted in Submitted by tranoris on November 24, 2009 - 02:58.


  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.