Chapter 23. How to define a domain model

23.1. Goal

This tutorial explains how to define a domain model for a specific domain. What a domain model is, can be read in the user manual in the semantics section(Chapter 6, Semantics in the OpenEngSB). The structure of a domain model is an interface which extends the OpenEngSBModel.

23.2. Time to complete

If you are already familiar with the OpenEngSB about 10 minutes. If you are not familiar with the OpenEngSB please read this manual from the start or check the homepage for further information.

23.3. Prerequisites

For information about how to get started as contributor to the OpenEngSB project and how to get the current OpenEngSB source please read the contributor section of the manual: Part V, “OpenEngSB Contributor Detail Informations”.

23.4. Step 1 - Plan the structure of the model

The first thing to do is to think about the structure of the model you need. Think about which informations are needed and should be included. (e.g. if you want to create a domain model for an appointment domain, the domain model will contain informations like start time, end time, title, ...).

Also give a think about if there exists a field which has the potential to be the id of a model. Such a field has to be unique for a specific domain and connector combination. Such an id can be defined through an annotation with the name OpenEngSBModel.

23.5. Step 2 - Write the model

Writing a model is quite simple. A domain model is an interface, which contains only pairs of getter and setter methods. The method names define the internal names of the fields of the model. Example model:

            interface Appointment extends OpenEngSBModel {
                 @OpenEngSBModelId
                 void setId(Integer id);
                 Integer getId();
                 
                 void setStartTime(Date startTime);
                 Date getStartTime();
                 
                 void setEndTime(Date endTime);
                 Date getEndTime();
                 
                 ...
            }
        

This model defines a part of a domain model for an appointment domain. In this model we also have defined the id of the model, with the name id. You can see that through the set annotation.

23.6. Step 3 - Add the model to a domain

The last step is to add the model to the specific domain. For that you simply have to add the model to the model package in the specific domain. Now the model is ready to use in the connectors for the specific domain.

23.7. Step 4 - Use the model

The last step is to use the model. For that you have to use a util class which is placed in the core/common bundle called ModelUtils. An instantiation of a model looks like this:

            Appointment appointment = ModelUtils.createEmptyModelObject(Appointment.class);
        

After that you can use the appointment object like a normal instantiated object.