Introduction
In this post I will introduce the various Ecore Model Components and their properties. Previously, we saw how to update an Ecore Model. Now I will explain what each component represents and how to set its properties. Each section describes one of the child components of the Ecore model. They are also called nodes. You can add new child nodes to the parent node by right clicking on it (Translations), then clicking on the New Child option and selecting the desired node type. In one of the upcoming posts I will demonstrate how we can generate C++ classes from the Ecore model.

Ecore Model components – EAnnotation
The main usage of EAnnotations is for extended modeling that influences Java code generation or XSD serialization. The EAnnotation component can be added to both the parent node and any other child node like EClass. There are three types of EAnnotation (as of the time of writing this post), which can be added. The first one is generic and comes with no predefined options. Can be used to crate user-defined options. The other two have some predefined options, which can be set.

The GenModel EAnnotation has more options, which can affect the generated code. You can see what each option does by selecting that option. Information about it is displayed in the bottom bar. My suggestion is to play with this options and see what they do to the generated Java classes.

I haven’t played with the EAnnotations too much and since I am using the generated Java classes only to process my inputs for the code generation, I never felt the urge to add or change annotations. I always stick with the default generated EAnnotations
Ecore Model components – EClass
The EClass component is used to define your everyday classes. In my practice I have had to add classes quite often. There are situations when you want to add a new component, which wasn’t originally in the XSD model. That component might later be added to the .xml files which we are using to generate code from and that is why we will need classes for them so they are processed correctly. There are few properties, which can be set for the class component, most important of which are:
Properties of the EClass
- Abstract – Whether the class is abstract one. If the class is abstract we can’t make instances of it.
- ESuper Types – These are the classes or interfaces, which our classes inherits from. When you click on this field you will see three dots button on the right side, which you can click to get the list of all available classes to inherit from.
- Interface – Whether our class is an interface. If it is, then no implementation will be generated for it.
- Name – The name of the class.

Go ahead and add one new class and name it as you prefer. Don’t set any other properties.
Children components of the EClass components we can add are the following
- EAnnotation – Same as described above.
- EOperation – This is for adding methods to the given class.
- EAttribute – This is for adding normal member variables.
- EReference – This component is used for member variables which are of reference type. Think of it as a way to add a pointer or reference member variable.

When you add an operation to the EClass, as a child you can add EParameters component to it. The EParameter acts as an argument for that operation (method).
The more important properties for the EOperation component are
- EException – Provides an exception that might be thrown from the method.
- EType – The return type of the method.
- Name – The name of the method.
- Lower/Upper Bound – These properties provide you a way to set how many values can be returned from method. These can be used in order to make the return type of the method an array. Use -1 for the Upper Bound in order to make infinite count of values.
The more important properties of the EParameter component
- EType – The type of the argument.
- Name – The name of the argument.
- Lower/Upper Bound – These properties provide you a way to set how many values will the argument have. Use them in order to make the argument an array.
For the exercise go ahead and add one or more operations to the class you created earlier. Add arguments to them if prefer or leave them without arguments.

Next component that we can add to EClass is EAttribute. This component is used to define member variables of the class. The only sub-component you can add to an EAttribute is EAnnotation.
The following properties are what I consider important
- Changeable – Describes whether this member variable can be changed by the user or it is a constant.
- EType – The type of the variable. Setting this property also sets automatically the EAttributeType.
- Name – The name of the attribute.
- Lower/Upper Bound – Again as with the EParameter, these values define whether the member variable can have a multiple values (i.e. if it is an array or some sort of list).
Go ahead and create some member variables for your class. We will be using them later

The last child component type, which we can add to EClass is EReference. It is used to declare a member variable, which can refer to another variable. Think of it as way to declare a reference or a pointer (as in C/C++) to another variable. The EReference has the same options like the EAttribute plus few specific, which I don’t find very important for my needs. You can look at them yourself.
Just for the sake of the exercise add one or more EReference components to our newly created class:

Ecore Model components – EData
The next component type, which we can add to our Main model is EData Type. It is used to define a new data type, which we can use later as a return type for our operation or as a type for those operations’ arguments. Also can be used as the type of the class member variables. For the EData Type these are the two important properties which we can set:
- Name – This is the name of the new type
- Instance Type Name – This is the name of the real type, which our Data Type will be pre-defining.
Think of this is make a new type from existing one. It is like making a typedef in C/C++. Something similar to this:
typedef <Name> <Instance Type Name>
Create some EData Type on your side. See below how I have created a pre-defined the integer type and then used this new type inside my class to define a new member variable:

Ecore Model components – EEnum
The EEnum component is used to add enumerators to the Ecore model. This component has the same properties like the EData Type. For this it is more than enough only to set the Name property. Then you can add literals to this enum by adding them as children. Right click to it >> New Child >> EEnum Literal. The EEnum Literal component has the following properties:
- Name – the name of the literal which will be used.
- Literal – Similar to the Name property. I usually set the same values for both.
- Value – The integer value of the literal.
Go ahead and add some EEnum components to your model as I did below:

Ecore Model components – EPackage
This component lets us create a sub-package into the main package (Translations). This helps to combine classes and data into separate packages. Once placed, you can add the same components as we already did to the main package – EClasses, EEnums, etc.
Conclusion
In this post we saw what each component from the Ecore model does and what properties we can set for it. We also added new components to our main package (Translations). Later on we will be able to generate classes and data from these components. Don’t hesitate to contact me or ask questions in the comments section about all these components and their usage.
In the next post we will create our first Expand project, which later we will update with more and more functionality.

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.