wiki:AMF/UML/Profiles

User Defined UML Profiles

AMF allows to define UML Profiles and to process UML models which utilize this profiles. Profile's stereotypes and its attributes can be accessed like any other elements of UML model.

Developing own AMF module for UML Profile

Key feature of developing of AMF module to support user defined UML Profiles is code generator. It loads profile's description and generates most of Ada code to handle profiles. Generated code includes application's API as well as internal support packages and stubs for subprograms which need to be implemented by user.

Converting UML Profile into CMOF metamodel

First step in preparation to develop module to support user's UML Profile is transformation of UML Profile into equivalent CMOF metamodel. There is a special utility to do this, it is stored in directory trunk/matreshka/design/amf2/tools/umlprofile2cmof. It accepts only one command line parameter and output generated XMI document to standard output, so here is example of its use:

$ umlprofile2cmof UMLProfile.xmi > UMLProfile.cmof

Generation of Ada code from CMOF metamodel

Generation of Ada code consists from several separate steps:

  • add mapping of UML Profile's URI to mapping file;
  • generation of Ada API to access to elements of UML Profile;
  • generation of implementation stubs for elements of UML Profile;
  • generation of internal implementation packages.

Add mapping of UML Profile's URI

Before starting of generation of Ada code you need to add rule to map URI of UML Profile into local file, generated on previous step. Mapping file is located in <prefix>/share/matreshka/amf/models/mapping.xml. This file has XML Catalogs format, you can use any of its features.

Generation of Ada API to access elements of UML Profile

Packages of interface of every UML::Stereotype from UMP Profile, collections of corresponding elements and supplementary hash function (compatible with Ada.Containers) are generated by gen_api utility, stored in trunk/matreshka/design/amf2/gen-stage2. It accepts first and last years to fill copyright statement in files' header and URI of CMOF metamodel of profile. Generator outputs generated code to standard output. (Note, gnatchop utility can be used to split output into set of files with GNAT conventions naming). For example:

$ gen_api 2012 2012 'http://mydomain.com/myprofile/1.0' > source.ada
$ gnatchop -gnat12 source.ada

Generation of implementation stubs for elements of UML Profile

Now it is time to generate implementation stubs for all UML::Stereotype of UML::Profile. Generated code allows to set and get attributes of UML::Stereotype, and contains compilable stubs for its operations. Implementation of these operations should be provided by developer when necessary. This code is generated by the gen_api utility, used at previous step. Only difference in command line parameters is one additional parameter --stubs:

$ gen_api 2012 2012 'http://mydomain.com/myprofile/1.0' --stubs > source.ada
$ gnatchop -gnat12 source.ada

Generation of internal implementation packages

Packages of internal implementation of data structures and reflection capabilities are generated by gen2 utility, located at trunk/matreshka/design/amf2/gen-stage2. Its usage is the same with gen_api utility, so here is example:

$ gen2 2012 2012 'http://mydomain.com/myprofile/1.0' > source.ada
$ gnatchop -gnat12 source.ada

Building of module

To build AMF module for UML Profile we need to write GNAT Project file, like this one:

with "matreshka_amf_uml.gpr";

project UML_Profile is

   --  Add any attributes and packages, as well as package Compiler

   package Compiler is
      for Default_Switches ("Ada") use ("-g", "-gnat05");
   end Compiler;

end UML_Profile;

Now, module can be build with gnatmake utility:

$ gnatmake -P uml_profile.gpr
Last modified 10 years ago Last modified on Apr 2, 2012, 6:07:26 PM
Note: See TracWiki for help on using the wiki.