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 src/main/conf/res/module.xml file.

1 <Module
2    id="${project.name}"
3    version="${project.version}"
4    binaryversion="3.7.00"
5    class="org.modelio.junit.impl.JUnitModule"
6    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.
  • 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 src/main/java/org.modelio.junit.impl/JUnitLifeCycleHandler.java 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.module.context.log.ILogService;
 6import org.modelio.api.module.lifecycle.DefaultModuleLifeCycleHandler;
 7import org.modelio.api.module.lifecycle.ModuleException;
 8import org.modelio.vbasic.version.Version;
 9
10/**
11 * Implementation of the IModuleLifeCycleHandler interface.
12 * <br>This default implementation may be inherited by the module developers in order to simplify the code writing of the module life cycle handler .
13 */
14public class JUnitLifeCycleHandler extends DefaultModuleLifeCycleHandler {
15
16    /**
17     * Constructor.
18     * @param module the Module this life cycle handler is instanciated for.
19     */
20    public JUnitLifeCycleHandler(JUnitModule module) {
21        super(module);
22    }
23
24    /**
25     * @see org.modelio.api.module.DefaultModuleLifeCycleHandler#start()
26     */
27    @Override
28    public boolean start() throws ModuleException {
29        // get the version of the module
30        Version moduleVersion = this.module.getVersion();
31
32        // get the Modelio log service
33        ILogService logService = this.module.getModuleContext().getLogService();
34
35        String message = "Start of " + this.module.getName() + " " + moduleVersion;
36        logService.info(message);
37        return super.start();
38    }
39
40    /**
41     * @see org.modelio.api.module.DefaultModuleLifeCycleHandler#stop()
42     */
43    @Override
44    public void stop() throws ModuleException {
45        super.stop();
46    }
47
48    public static boolean install(String modelioPath, String mdaPath) throws ModuleException {
49        return DefaultModuleLifeCycleHandler.install(modelioPath, mdaPath);
50    }
51
52    /**
53     * @see org.modelio.api.module.DefaultModuleLifeCycleHandler#select()
54     */
55    @Override
56    public boolean select() throws ModuleException {
57        return super.select();
58    }
59
60    /**
61     * @see org.modelio.api.module.DefaultModuleLifeCycleHandler#unselect()
62     */
63    @Override
64    public void unselect() throws ModuleException {
65        super.unselect();
66    }
67
68    /**
69     * @see org.modelio.api.module.DefaultModuleLifeCycleHandler#upgrade(org.modelio.api.modelio.Version, java.util.Map)
70     */
71    @Override
72    public void upgrade(Version oldVersion, Map<String, String> oldParameters) throws ModuleException {
73        super.upgrade(oldVersion, oldParameters);
74    }
75}
76

<< Previous Index Next >>

ModuleLifeCycle.png (26.7 KB) admin admin, 13 July 2017 16:47