This section describes how to use the FXU to efficiently develop applications according to MDE methodology. The whole process can be described in few steps:
Preferred tool to create UML model is Rational Software Architect 7.5, but it can be any other tool which is able to export model into UML2.1 format (.uml extension). In this section it will be described process of creating UML model using Rational Software Architect 7.5. Firstly, create UML model containing class diagram
and state machine diagrams.
Next export model to UML2.1 format.
File->Export opens Export Window. Choose Other->UML 2.1 Model and click "next" button.
Specify UML model to export and destination path:
Now the UML2.1 model file is created in specified path. It will be used in next steps to generate C# code.
Firstly, start FXU by double-clicking Fxu.jar file.
Next click File->Open and select UML2.1 model file. It may take few seconds to load UML model. Model is displayed as tree containing all nodes specified in uml2.1 model file.
Now, the model has been read and is ready for validation and code generation.
This is an optional step, because model is being validated always before code generation. To validate click Model->Validate Model. FXU will display appropriate information about validation result.
To generate code click Model->Generate C# Code. Generation window will be displayed.
It has two tabs. First contains general information:
Second tab contains information about default data types used in generated code:
Note, that this data types are used only if they are not specified in UML model created at first step.
There will be created two subdirectories in output directory:
Click Generate to start process of code generation. After it is done question about starting application wizard will be displayed.
It is possible to specify order of initialization and starting state machines.
Note, that starting state machine must be placed after initialization this state machine.
Click Generate. Now project is created and ready to open and run in Microsoft Visual Studio 2008.
Application Wizard will create:
In the first step, an UML model has to be created. In the example IBM Rational Software Architect 9.0.5 has been used, but it is possible to use any CASE tool which supports exporting the UML model into the UML format of Eclipse (uml 2.2 format). At the beginning, a class diagram has to be created (Figure 1). In the example there are two classes: MarteTimedEventTest, which has neither operations nor attributes, and SimpleClock class in a package clocks. The second class has a ClockType stereotype from the MARTE::Time profile, which tag values are shown in the frame in the picture below. Moreover the package clocks has a TimedDomain stereotype.
The SimpleClock class defines a new type of clock. The stereotype ClockType and its tag values specify properties of this kind of clock. But in order to use this type of clock it is necessary to create an instance of the class. Therefore, in the next step, an object diagram for the clocks package is created (Figure 2). Only one object is created and it will be used by the exemplary state machine.
The third part of the UML model is a state machine diagram for the MarteTimedEventTest class (Figure 3). It consists of four simple states. The transition between those states are triggered by a time event which has a TimedEvent stereotype from the MARTE::Time profile. The first event is generated after 2000 units of time on a clock specified by “on” tag value of the stereotype TimedEvent. Next events will be generated after every 5000 units of time, as it is specified by “every” tag value.
The created model has to be exported to the UML format of Eclipse. It can be done by clicking “File-Export”, selecting “UML 2.2 Model” on the “Other” section and following wizard’s steps. It is important to select an “Export applied profiles” option in the second frame. Thanks to this, the FXU Generator will be able to read all applied profiles in the model and generate appropriate C# code.
The generator can be launched by double clicking the “FXUGenerator5.0.jar” file. Before launching the generator, ensure yourself that the MARTE::Time plug-in is provided by checking the “FXUGenerator3.0_lib” folder. It should contain the “MarteTime.jar” file.
In order to load the model click “File-Open” and select a file with the exported model in your file system.
Now, the model is loaded and visualized in a tree-like form which represents the real hierarchy in the original UML model (Figure 5). It is important to check logs in the result frame at the bottom of the main window. There are a few warnings. They indicate that the FXU loader has not been able to find files with UML profiles (Standard.profile.uml, Default.profile.uml, Deployment.profile.uml), which are applied in the model. In this case, stereotypes from these profiles were not used, so warnings can be ignored.
In order to perform model validation click “Model-Validate Model”. The dialog window with a message “Model is valid” should appear. In the result frame, at the bottom of the main window, additional messages should appear. Apart from messages from the FXU model loader, described earlier, there is one warning:
WARNING::Parameter MarteFunctionalTests::clocks::SimpleClock::indexToValue::value - Name of the element is a C# contextual keyword.
It indicates that there is a parameter named “value”, which is a C# keyword. But in this case, this parameter is a return parameter of an operation SimpleClock::indexToValue and it will not appear in the generated code. Therefore these warnings can be ignored.
In order to generate C# code from the loaded model click “Model-Generate C# Code”. In the generation window there is a possibility to configure some features of the generated code such as algorithms for the FXU Runtime Environment, a destination path, default data types or an application logger configuration. Next four pictures show every tab in the generation window.
Default values can be used and by clicking the “Generate” button C# code can be generated. However, sometimes it would be helpful to choose other possibilities. They are listed and described shortly below.
The last step is a Microsoft Visual Studio 2008/2010 project generation. It is an optional step and can be omitted. Figure 10 shows first three windows of the FXU Application Wizard. There is a possibility to specify a project name, to generate the Main function and specify its containing class namespace and name. In the third window of the wizard, selected state machines can be initialized and started.
In the last window of the wizard there is a possibility to specify which operations have to be invoked in the Main function. There is also a possibility to configure attributes for invoked operations. The window is shown in the figure 11.