Creating a In this blog we are going to create one Xpand project, which will be used to generate C++ and later Java classes for the objects, which we had in our XSD and XML files. Previously we saw the ecore model components.
Now in this blog post I will show you the steps, which we will go through in order to create an Xpand project, add the needed files and run the project. From this link you can get more information about Xpand. In the upcoming posts I will provide more information about Xpand, its functionalities, syntax and so on.
Create Xpand project
Following are the steps, which one should go through in order to create an Xpand project:
In Eclipse click File >> New >> Other…
In the popup window search for Xpand Project

If you are not able to find the Xpand Project template in that popup window, you will have to install the Xpand SDK, as we did in the this post.
After you select Xpand project, hit Next. In the next window you will have to give a name to your project. Write anything you want. Then from the Meta Models field select the option “Use project specific metamodels:” and from the given option below it select EMF Metamodels. Then click Finish.

That’s it. You have your first Xpand project. You should see the following project appearing in your workspace. We will now add the needed files to it.

Adding workflow to the Xpand project
Workflow file is used to describe the steps, which the code generator should go through in order to generate our code. These steps include reading of input files, calling the code generation function, outputting the result and so on. These steps are defined in a .mwe file. This file uses .xml kinda syntax.
Adding a workflow file
Let’s go ahead and add one workflow file. For a convenience reasons I like to put the separate file types into separate folder inside the src folder of the project. So go ahead and create one folder, named “workflow” inside the src folder. Right click on src >> New >> Other >> Folder and give it the name “workflow” then click Finish.
Once you have created a workflow folder, let’s create one workflow file. Right click on workflow >> New >> Other >> Workflow File. Give it some name like MyWorkflow.mwe and hit Finish.

Putting the logic into a workflow file
Now we need to put our logic into the workflow file. Below is an exemplary file, which we will use as a starter and will add more logic to it later. You can go ahead and copy it. So far this workflow is only able to read our Ecore model. Following is an explanation of the sections, which it has.
<workflow> <property name="modelFile" value="platform:/resource/com.xequtor.blog.ecore.model/model/Translations.ecore" /> <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" > <platformUri value=".."/> </bean> <component class="org.eclipse.emf.mwe.utils.Reader"> <uri value="${modelFile}" /> <modelSlot value="model" /> </component> </workflow>
Note: I suggest you to install “Eclipse XML Editor and Tools” to your Eclipse installation in order to be able to later edit the workflow files as an .xml file. This will be very helpful. Once you install those tools, you can right click on your .mwe file >> Open With >> Other >> XML Editor. Believe me, it looks better in XML Editor.
Explanation of the workflow file components
So here is an explanation of the workflow file that we have so far. The main component is the <workflow></workflow> component.
The property component
First child component that I have added is <property>. This component is used to define some user variables, which are used later in other parts of the workflow. In the above file I have defined the variable modelFile which in my case is the path to the Ecore model file. Using “platform:/resource/” in the path will add the path to your Eclipse workspace, where the projects reside. After it I have added the path to the project for the Ecore model, which we created previously. The way you define variables is to provide the “name” and “value“. You can add strings, integer, floats and so on type of properties. All of them are treated like strings so later on you should cast them.
The bean component
The next <bean></bean> component is some initial setup of the Java environment. It should be part of the workflow as a first step.
The component section
Inside <component></component> blocks we define the components which will take part in the code generation. We add the name of the class in the class property. Then inside child components you can set different properties of that class. In our case we have added a Reader class which will take care of reading our Ecore model file. Then we have set the path to the Ecore file, which will be read in the <uri /> block. Note that here we use the property, which we defined in the beginning of the workflow. The syntax to use a property is the following: ${name}. The second thing which we set is the modelSlot. This is the variable, where the content of the .ecore model file will be kept after it is read and parsed. The property name model is what we are going to use next in order to process the Ecore file. It is defined here and will be used later in the workflow.
Running the workflow of the Xpand project
So far our workflow has everything needed to be run. Next we are going to run it and verify that it works fine. In the upcoming posts we will add more content to it.
Note: If you have taken the exemplary workflow file, please, make sure to update the path in the “modelFile” variable accordingly. It should point to the project and folder, where you keep your .ecore model file. I have given it with the name of my project, but your project is probably with different name so make sure to update the workflow file.
In order to run the workflow, right click on it in the Model Explorer >> Run As >> 1 MWE Workflow:

After you run it, you will see some output in the Console. It will say that the workflow completed in some time. If everything is fine and no errors are printed in the console, you were able to read the Ecore model without a problem. Let me know in the comment section if you had any issues running the sample workflow
Conclusion
In this post I showed you how to create an Xpand project and how to add files to it. We added some initial workflow file, which will control our code generation. In the upcoming posts we will add more content to this workflow file. I will explain you more about the syntax of the workflow files and in some future posts I will also show you the newer MWE2 workflow.

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.