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

Namespace tutorial



The first tutorial presented the coding and configuration of a very simple system with two modules. In this namespace tutorial, we reuse the implementation of the first tutorial, but we define services and types in a namespace.

Overview

In the first tutorial, we had two modules:
  • The PublishModule module increments or decrements a value cyclically
  • The EventModule module allows to click on a toggle to set if the first module should increment or decrement the value, and shows the value


We will change very little in the services code. The onyl modification will be to use the services keys rather than their names.

XML configuration

Services definition

We will use a namespace with the following URI: http://proto.tutorial.com. We will modify the services.xml XML file to define the two services in this namespace:
      <services>
         <namespace uri="http://proto.tutorial.com" >
           <event name="event" id="1" >
              <data name="event" type="bool" />
           </event>
           <publish name="published" id="2" >
              <data name="value" type="int" />
           </publish>
         </namespace>
      </services>

Types definition

As for the services, we will use a namespace with the following URI: http://proto.tutorial.com. We will modify the services.xml XML file to define our types in this namespace:
      <types>
         <namespace uri="http://proto.tutorial.com" >
           <simpleType name="bool" baseType="boolean" />
           <simpleType name="int" baseType="int" />
         </namespace>
      </types>

Applications definition

We onyl have to refer to the services using the namespaces URI. The applications.xml is modified as follows:
         <applications>
            <application name="eventAppli" id="1">
               <modules>
                  <module name="EventModule" id="1" >
                     <interfaces>
                        <eventSend service="event" uri="http://proto.tutorial.com" attach="attach"/>
                        <subscribe service="published" uri="http://proto.tutorial.com"/>
                     </interfaces>
                  </module>
               </modules>
            </application>
            <application name="publishAppli" id="2">
               <modules>
                  <module name="PublishModule" id="1" >
                     <interfaces>
                        <eventReceived service="event" uri="http://proto.tutorial.com"/>
                        <cyclic service="published" frequency="200ms" uri="http://proto.tutorial.com" attach="attach"/>
                     </interfaces>
                  </module>
               </modules>
            </application>
         </applications>

Code the applications

Code the PublishModule

We will use the namespace URI to get the services:
      public class PublishModule {
      ...
        public void init(Module module) {
          eventService = module.getService("http://proto.tutorial.com", "event");
          publishService = module.getService("http://proto.tutorial.com", "published");
        }
      ...
      }

Code the EventModule

We will use the namespace URI to get the services:
      public class PublishModule {
      ...

        public void init(Module module) {
          eventService = module.getService("http://proto.tutorial.com", "event");
          publishService = module.getService("http://proto.tutorial.com", "published");
        }
      ...
      }

Starting the framework

The framework work just as for the first tutorial.
      public class EventModule {
      ...

        public void init(Module module) {
          eventService = module.getService("http://proto.tutorial.com", "event");
          publishService = module.getService("http://proto.tutorial.com", "published");
          gui = new EventGUI(this);
          gui.setup();
          gui.pack();
          gui.setVisible(true);
        }
      }

Starting the framework

The framework work just as for the first tuturial.

See also


Categories: tutorials

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