Eclipse Modeling Framework Introduction
In this and in the following posts I will introduce you to the Eclipse Modeling Framework and it’s capabilities. I will show you how to create Ecore models and generate code, based on those models. You can find more information about Ecore and EMF here and here. There is also a book about EMF available here.
This is a series of posts. Trough this series I will show you how to create all needed inputs and generate the code. I will work on the following example: There will be several .xml files which will contain translations for several languages used by one application to implement its localization. We will create a .xsd file, based on the provided .xml files. From that .xsd file we will create an Ecore model. Then we will write templates in Xpand which the generator will use to generate a C++ code. Don’t worry if you don’t know any of these terms I just mentioned. You will learn about them in the following posts.
How I met Eclipse Modeling Framework
I want to say a few words about my experience with Eclipse Modeling Framework and why I felt in love with it. Everything started with one new project, which our team won after one long quotation. Beside all the documentation regarding the customer requirements we received one XML file, which was describing one part of the system. It was the part I was involved in. We had the option to develop everything by hand or buy a 3rd party suppliers software. Needless to say that software was quite expensive. Of course, writing everything by hand wasn’t an option either. Previously we had written everything by hand and it was a big mess.
Can we C#?
So the best and most suitable option was for us to write some software, which will generate the code instead of developing by hand. Of course we didn’t quote such a task in the original quotation. So we had to somehow stay inside the quoted hours. I have some significant experience with C# and .Net and of course I went first that way. Quickly developed one application, which was able to parse the .xml file. But it was a mess. I was doing quick Proof of Concept. Everything seemed to work as expected, but the application grew very quick and maintaining it would be a nightmare. So what was my other options?
Enter Eclipse Modeling Framework
One day a colleague of mine introduced me to something called EMF – Eclipse Modeling Framework. He had some ready example using Xtend. That example was generating classes from something called Ecore model. I did a quick analysis of the demo project. Everything seemed simple, easy to understand and easy to implement. Then I was introduced to Xpand. I did one example on my own. For me it was easy to do it, just few steps and it was there.
What happens next?
Firstly, what I did after I’ve got familiar with EMF was to take the XML we had, create an XSD file from it. Then I created one Ecore model. I had everything I needed. I quickly created Ecore model, updated my example and I was ready to generate C++ classes. Now I had one part of the component that I wanted to develop. It was time to generate more code. Next thing I know I was developing my second Eclipse Modeling Framework project. That project was supposed to generate a huge amount of C++ code from the XML file we have received. Nothing was going to stop us.
Prerequisites
The most important thing that we need is Eclipse IDE. If you already have an Eclipse IDE, you should be able to just install the required packages and work with it. However, my preferred approach is to have a separate IDE for the Modeling. Fortunately, there is a designated version of Eclipse for this goal, which has all the tools you need. It goes by the name “Eclipse Modeling Tools” and you can download from here. This version was the latest one when I was writing this post. Please, make sure to check for a newer version. Also, just as a remainder, make sure to download from the correct link since the page contains multiple and one of them is for another version of the IDE:

In this post I will explain how to install the needed packages in your existing Eclipse IDE and how to prepare the Eclipse Modeling Tools if you decide to go with it.
Next, we need several .xml files, which will contain translations. Each .xml file will contain translated strings for a given language. You can make them yourself or download the files, which I have prepared for this series of posts. The download link is at the end of the post. If you are going to make them yourself, make sure they look like the following:
<?xml version="1.0" encoding="utf-8"?> <Translations> <TranslatedString name="app_file">File</TranslatedString> <TranslatedString name="app_new_file">New</TranslatedString> <TranslatedString name="app_open_file">Open File...</TranslatedString> <TranslatedString name="app_close_file">Close</TranslatedString> <TranslatedString name="app_edit">Edit</TranslatedString> <TranslatedString name="app_cut">Cut</TranslatedString> <TranslatedString name="app_copy">Copy</TranslatedString> <TranslatedString name="app_paste">Paste</TranslatedString> <TranslatedString name="app_find">Find</TranslatedString> <TranslatedString name="app_replace">Replace</TranslatedString> <TranslatedString name="app_help">Help</TranslatedString> <TranslatedString name="app_about">About</TranslatedString> </Translations>
Make at least two of these files for different languages. The strings and their names should be the same
Conclusion
The post gives a brief overview of what will be the output of the whole series of posts about Eclipse Modeling Framework. Once the reader gets through the whole series, he/she should be able to make Ecore models and generate code for his/her preferred programming language. Following the given link the user can find the IDE, specifically designed for EMF. In the next post we will see how to setup it. From the link at the end of the post you can download exemplary .xml files, which will be used in the forthcoming posts. Enjoy!

Passionate developer, loving husband and caring father. As an introvert programming is my life. I work as a senior software engineer in a big international company. My hobbies include playing computer games (mostly World of Warcraft), watching TV series and hiking.