Creating a module – Basics

As with many objects that constitute a packaged module, module (the object) creation is two part: XML declaration and Java coding.

Module declaration

Module is the root element in the module.xml file.

1 <Module id="${project.name}" 
2   uid="794fecf1-cf25-4f3d-8d90-936f1ceda651" 
3   version="${project.version}" 
4   binaryversion="3.5.00" 
5   class="org.modelio.junitmodule.impl.JUnitModuleModule" schema-level="2">
  • id value is the internal name of the module. It is replaced at packaging with the module’s name from the pom.xml file.
  • uid value is a unique identifier. It is very important that the value shouldn’t be copied from another object (don’t copy the id from the example), nor modified after module delivery. If you are using a Maven project, this identifier is automatically generated during the module packaging.
  • version value in the V.R.C form, filled at packaging from the pom.xml file.
  • binaryversion format is the same as the version value, except it indicates the Modelio version this module needs.
  • class value is the name of the Java class that will represent the module.
  • schema-level value is used by Modelio at runtime for migration purpose.

The last files to edit are the manifest property files. There is one file per language supported with a default (without country code extension) that should be for English locale.

module.properties file will look like :

ModuleLabel=JUnit module
ModuleDescription=Builds and manages test case for classes based on JUnit framework.

module_fr.properties file for french will look like :

ModuleLabel=Module JUnit
ModuleDescription=Crée et gère les cas de test de classes basés sur JUnit

Module Java classes

A module contains :

  • A JUnitModule class that will represent your module at runtime. This class is called the main class of the Module. By convention it is always suffixed Module.
  • A JUnitLifeCycleHandler class and an association. This class is in charge of the implementation of the Module Session Services detailed below. The association is a simple delegate from the Module main class to this JUnitLifeCycleHandler class.

The UML model detailed diagram for these classes is presented below.

Illustration 6: Module and Session

Illustration 6: Module and Session

The operations defined in JUnitLifeCycleHandler are automatically called according to the stat Module runtime states and events.

We won’t dive into the gory details of these methods. We will see later (§7.7)that the start method will attach the module event listener to the Modelio event dispatch system. For more information on these methods.

The implementation of session services for our JUnit module is very simple.

 1package modelio.junit.impl;
 2
 3import java.util.Map;
 4
 5import org.modelio.api.module.lifecycle.DefaultModuleLifeCycleHandler;
 6import org.modelio.api.module.lifecycle.ModuleException;
 7import org.modelio.vbasic.version.Version;
 8
 9
10public class JUnitLifeCycleHandler extends DefaultModuleLifeCycleHandler {
11
12    public JUnitLifeCycleHandler(final JUnitModule module) {
13        super(module);
14    }
15
16    @Override
17    public boolean start() throws ModuleException {
18        return super.start();
19    }
20
21    @Override
22    public void stop() throws ModuleException {
23        super.stop();
24    }
25
26    /**
27     * @param mdaPath @return
28     */
29
30    public static boolean install(final String modelioPath, final String mdaPath) throws ModuleException {
31        return DefaultModuleLifeCycleHandler.install(modelioPath, mdaPath);
32    }
33
34    @Override
35    public boolean select() throws ModuleException {
36        return super.select();
37    }
38
39    @Override
40    public void upgrade(final Version oldVersion, final Map<String, String> oldParameters) throws ModuleException {
41        super.upgrade(oldVersion, oldParameters);
42    }
43
44    @Override
45    public void unselect() throws ModuleException {
46        super.unselect();
47    }
48
49}

<< Previous Index Next >>

module_mdac_and_session.png (26.1 KB) admin admin, 11 May 2016 17:32

ModuleLifeCycle.png (26.7 KB) Christophe Demeulemeester, 17 May 2016 15:04