Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Type annotation mapping tutorial



This tutorial shows how to map a data type to a class through annotations.

Overview

Suppose the we want to specify two modules which exchange one data which is an array of structure.

The structure which is the type oea each element in the array contains three fields:
  • A boolean
  • An int
  • A String


We will map this structure to a class to be able to set and get the value of the array without having to set indivicually each field foe each structure element:
tutoannot

XML configuration

Services definition

We define only one service in a services.xml XML file:
      <services>
         <event name="service"  >
            <data name="array" type="structArray" />
         </event>
      </services>

Types definition

The data is an array for which each element is a structure.

We define the associated types in a types.xml XML file:
      <simpleType name="bool" baseType="boolean" />
      <simpleType name="int" baseType="int" />
      <simpleType name="string" baseType="string" />
      <arrayType name="structArray" type="struct" />
      <structType name="struct">
         <field name="bool" type="bool" />
         <field name="int" type="int" />
         <field name="string" type="string" />
      </structType>

Applications definition

We define our two applications in an applications.xml XML file:
  • The first application contains one module which sends the Service
  • The first application contains one module which receives the Service
      <applications>
         <application name="appli1">
            <deployment>
      ...
            </deployment>
            <modules>
               <module name="module1">
                  <implementation path="..." >
                     <initEntryPoint method="init" />
                     <startEntryPoint method="start" />
                  </implementation>
                  <interfaces>
                     <push service="service" attach="attach"/>
                  </interfaces>
               </module>
            </modules>
         </application>
         <application name="appli2">
            <deployment>
      ...
            </deployment>
            <modules>
               <module name="module2">
                  <implementation path="..." >
                     <defaultReceiveEntryPoint method="subscribe" />
                  </implementation>
                  <interfaces>
                     <subscribe service="service"/>
                  </interfaces>
               </module>
            </modules>
         </application>
      </applications>

Creating the structure associated class

We will create a class which will hold the fields of our structure:
      @DataTag
      public static class StructObject {
      @FieldTag(field = "bool")
      public boolean bool = false;
      @FieldTag(field = "string")
      public String str = "";
      @FieldTag(field = "int")
      public int val = 0;
      }
The annotations specify that:
  • @DataTag: the class maps a type
  • @FieldTag: the class member maps a structure field

Code the applications

Code the first module

      ServiceInstance service;

      public void init(Module module) {
        service = module.getProviderService("service");
      }

      public void start() {
        Data data = service.getData("array");

        StructObject obj = new StructObject();
        obj.bool = true;
        obj.str = "toto";
        obj.val = 2;
        list.add(obj);
        data.setValue(list);
        service.invoke();
      }

Code the second module

      public void subscribe(ServiceInstance service) {
        Data data = service.getData("array");

        StructObject obj = new StructObject();
        obj.bool = true;
        obj.str = "toto";
        obj.val = 2;
        list.add(obj);
        List<StructObject> array = (List<StructObject>)data.getValue(StructObject.class);
      }

See also


Categories: concepts

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence