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 licenseRequired="false" 
2        uid="794fecf1-cf25-4f3d-8d90-936f1ceda651" 
3        name="${project.name}" 
4        version="${project.version}.9015" 
5        class="org.modelio.junitmodule.impl.JUnitModuleModule" 
6        binaryversion="3.0.00.9015" >
  • 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.
  • name value is the internal name of the module.
  • version value is composed of two parts:
    1. module version in the V.R.C form
    2. the metamodel version (9015) retrieved as described in this section.
  • binaryversion value is the same as the version value.
  • licenceRequired value is self explicit and set to false for this tutorial
  • class value is the name of the Java class that will represent the module.

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 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;
 2
 3import java.util.Map;
 4
 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;
10
11/**
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 {
16
17    public JUnitSession(JUnitModule module) {
18        super(module);
19    }
20
21    public boolean start() throws ModuleException {
22        // get the version of the module
23        Version moduleVersion = this.module.getVersion();
24
25        // get the Modelio log service
26        ILogService logService = Modelio.getInstance().getLogService();
27
28        String message = "Start of " + this.module.getName() + " " + moduleVersion;
29        logService.info(this.module, message);
30        return super.start();
31    }
32
33    public void stop() throws ModuleException {
34        super.stop();
35    }
36
37    public static boolean install(String modelioPath, String mdaPath) throws ModuleException {
38        return DefaultModuleSession.install(modelioPath, mdaPath);
39    }
40
41    public boolean select() throws ModuleException {
42        return super.select();
43    }
44
45    public void unselect() throws ModuleException {
46        super.unselect();
47    }
48
49    public void upgrade(Version oldVersion, Map<String, String> oldParameters) throws ModuleException {
50        super.upgrade(oldVersion, oldParameters);
51    }
52}

<< Previous Index Next >>

module_mdac_and_session.png (26.1 KB) Frédéric Ferran, 09 July 2013 16:20