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="${}" 
2   uid="794fecf1-cf25-4f3d-8d90-936f1ceda651" 
3   version="${project.version}.9022" 
4   binaryversion="" 
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 composed of two parts:
    1. module version in the V.R.C form, filled at packaging from the pom.xml file.
    2. the metamodel version (9022) retrieved as described in this section.
  • 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. file will look like :

ModuleLabel=JUnit module
ModuleDescription=Builds and manages test case for classes based on JUnit framework. 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 Mdac.
  • A JUnitSession 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 JUnitSession 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 JUnitSession 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 org.modelio.junit.impl;
 3import java.util.Map;
 5import org.modelio.api.log.ILogService;
 6import org.modelio.api.module.DefaultModuleSession;
 7import org.modelio.api.module.ModuleException;
 8import org.modelio.api.modelio.Modelio;
 9import org.modelio.vbasic.version.Version;
12 * Implementation of the IModuleSession interface.
13 * <br>This default implementation may be inherited by the module developers in order to simplify the code writing of the module session.
14 */
15public class JUnitSession extends DefaultModuleSession {
17    public JUnitSession(JUnitModule module) {
18        super(module);
19    }
21    public boolean start() throws ModuleException {
22        // get the version of the module
23        Version moduleVersion = this.module.getVersion();
25        // get the Modelio log service
26        ILogService logService = Modelio.getInstance().getLogService();
28        String message = "Start of " + this.module.getName() + " " + moduleVersion;
29, message);
30        return super.start();
31    }
33    public void stop() throws ModuleException {
34        super.stop();
35    }
37    public static boolean install(String modelioPath, String mdaPath) throws ModuleException {
38        return DefaultModuleSession.install(modelioPath, mdaPath);
39    }
41    public boolean select() throws ModuleException {
42        return;
43    }
45    public void unselect() throws ModuleException {
46        super.unselect();
47    }
49    public void upgrade(Version oldVersion, Map<String, String> oldParameters) throws ModuleException {
50        super.upgrade(oldVersion, oldParameters);
51    }

<< Previous Index Next >>

module_mdac_and_session.png (26.1 KB) Christophe Malgouyres, 19 August 2014 17:42