This chapter describes the OM Access feature.
OM Access is a module that provides the end user with access to the information in a diagram created by the OM Editor through a C++-interface, based on the UML Meta-model.
OM Access is a C++ application programmer's interface to the OM Editor. It can be used in applications that uses the information contained in OM diagrams, such as:
Note: This chapter is an OM Access primer and is not intended to provide knowledge about C++ programming. |
These files can be found under the
directory of your installation.
<Tau installation dir>/orca/omaccess/>
An OM Access application is an application that uses the data in an OM Diagram. This OM Diagram is represented in the program by a data structure similar to UML's metamodel.
The first section introduces the basic methods.
First of all there are some definitions needed; these can be found in the include file omaccess.h
:
#include "omaccess.h"
This file also includes uml.h
and stlmini.h
. The file uml.h
contains declarations for the UML metamodel, and stlmini.h
1 contains a minimal implementation of string
and list
classes in the standard C++ library used for handling the data.
An instance of the OMModule
is needed to hold the information:
OMModule module;
To load the contents of a diagram into the module either GetFile
or GetBufID
can be used:
bool result = GetFile(module, filename); bool result = GetBufID(module, bufid);
Returns true
on success, false if failed to load the module.
The OMModule
class keeps the information fetched from the OM Editor in lists. The lists are:
list<Class> classList list<Generalization> generalizationList list<AssociationClass> associationlist
Aggregations and associations are stored into the associationList
, to simplify handling. To pick out the associations and aggregations separately, use the functions:
GetAggregations(OMModule&, list<AssociationClass>*) GetAssociations(OMModule&, list<AssociationClass>*)
These functions fill the list in the second parameter with the associations and aggregations in the module.
The lists can be traversed using iterators. The following example shows how to print all the names of the classes in a module:
for (list<Class>::iterator ci=omModule.classList.begin(); ci != omModule.classList.end(); ++ci) { const Class &omClass = *ci; cout << omClass.name << endl; }
The links between associations/aggregations/generalizations and classes are represented as the names of classes, stored as strings
.
The Generalization
class contains the data members subtype
and supertype
. The names of the super- and subclass are stored as string
.
The data member discriminator
contains the discriminator, stored as string
.
To list the superclasses and subclasses of a class, the following functions can be used:
GetSuperClassList(OMModule&, string&, list<string>*) GetSubClassList(OMModule&, string&, list<string>*)
They put the names of the superclasses or subclasses belonging to the name of the class in string
, into the list
.
The AssociationClass
class can contain both aggregations and associations as well as associations with association classes connected to them. The boolean
member isAggregation
can be used to determine if it is an aggregation or association.
To get a list of the names of the classes connected to the association/aggregation, the function
GetEndPoints(AssociationClass&, list<string>*)
can be used.
Here follows a small example that shows how to access the class information. For each class in the diagram it prints the name of the class and the name of its subclasses.
printclasses.cc
#include <iostream.h> #include "omaccess.h" #include "stlmini.h" int main(int argc, char *argv[]) { if (argc !=2) { cout << "Usage : printclasses <filename>" << endl; return EXIT_FAILURE; } OMModule omModule; // Retrieve the file from the OM Editor if(! GetFile(argv[1], &omModule) ) return EXIT_FAILURE; // Iterate over the classes for (list<Class>::iterator ci=omModule.classList.begin(); ci != omModule.classList.end(); ++ci) { const Class &omClass = *ci; cout << omClass.name << endl; // Extract the subclassess list<string> classlist; GetSubClassList(omModule,omClass.name,&classlist); // And iterate through them for (list<string>::iterator ni=classlist.begin(); ni != classlist.end(); ++ni) { const string &name = *ni; cout << " Subclass: " << name << endl; } } return EXIT_SUCCESS; }
To use OM Access a C++ compiler that can handle templates is needed, such as g++ 2.7.2, Borland C++ 5.02, or MSVC 5.
There are some Makefiles together with the examples ($telelogic/orca/omaccess/examples
) that might be usable as templates.
OM Access is based on the public interface to Telelogic Tau; see PostMaster Reference.
The following files should be included into the compilation/linking phase for UNIX is:
$telelogic/orca/omaccess/src/omaccess.cc $telelogic/orca/omaccess/src/pmtool.cc $telelogic/lib/<platform>lib/post.o
where $telelogic
refers to the installation path, and <platform>
can be one of hppa
or sunos5
.
Two paths to the include files is also necessary:
-I$telelogic/orca/omaccess/include -I$telelogic/include/post
printclasses.cc
with g++ on HP g++ -o printclasses -I$telelogic/orca/omaccess/include \ -I$telelogic/include/post \ printclasses.cc \ $telelogic/orca/omaccess/src/omaccess.cc \ $telelogic/orca/omaccess/src/pmtool.cc \ $telelogic/lib/hppalib/post.o
If Solaris is used, the switches -lgen -lsocket -lnsl
have to be added.
printclasses.cc
with g++ on Solaris g++ -o printclasses -I$telelogic/orca/omaccess/includes \ -I$telelogic/include/post \ printclasses.cc \ $telelogic/orca/omaccess/src/omaccess.cc \ $telelogic/orca/omaccess/src/pmtool.cc \ $telelogic/lib/sunos5lib/post.o -lgen -lsocket -lnsl
The OM Access files could also be copied to a local directory to ease up compilation.
Add the files omaccess.cc, pmtool.cc
(can be found in <Tau installation directory>\orca\src
) and post.lib
(can be found in <Tau installation directory>\sdt\sdtdir\wini386\include\borland502
) to the project.
Add <Tau installation directory>\orca\includes
and <Tau installation directory>\include\post
to the include path.
Add the files omaccess.cc, pmtool.cc
(can be found in <Tau installation directory>\orca\src
) and post.lib
(can be found in <Tau installation directory>\sdt\sdtdir\wini386\include\msvc50)
to the project.
Add <Tau installation directory>\orca\includes
and <Tau installation directory>\include\post
to the include path.
Applications written with OM Access can easily be called from within the OM Editor, for example from a menu (for more info about defining your own menus see Defining Menus in ORCA and SDT.
The following example adds a choice to generate C++ code skeleton of an OM Diagram from the OM Editor and pops up a text editor with the generated file in it.
ome-menus.ini
SDT-DYNAMICMENUS-3.5 [MENU] Name=&OM Access [MENUITEM] ItemName=Generate C++ Separator=off StatusbarText=Generate C++ code skeleton ProprietaryKey=1 AttributeKey=0 Scope=Always ConfirmText=You might want to change the name of the output file ActionInterpretation=OS_COMMAND BlockCommand=off FormattedCommand=om2cpp %b `basename %b .som`.h [MENUEND]
The reference contains two parts:
The data model in OM Access is based on the UML Metamodel. For more information about the UML Metamodel, see the "UML Semantics" chapter of the "Unified Modeling Language, version 1.1" documentation. This document can be found at
http://www.rational.com/uml/documentation.html.
If not mentioned otherwise, the members are of type string
.
An instance of the OMModule
class contains information about an OM Diagram.
An instance of the Class
class contains information about a class.
An instance of the Operation
class contains information about an operation.
Member | Description |
---|---|
name |
Name of operation. |
returnType |
Return type of operation. |
parameterList |
List of |
An instance of the Parameter
class contains information about a parameter.
Member | Description |
---|---|
name |
Name of the parameter. |
type |
Type of the parameter. |
An instance of the Attribute
class contains information about an attribute.
Member | Description |
---|---|
name |
Name of attribute. |
type |
Type of the attribute. |
value |
Default value. |
An instance of the Generalization
class contains information about a generalization.
An instance of the AssociationClass
class contains information about an association/aggregation. The connection between the different classes is maintained by fromEnd
and toEnd
.
If the association also has an associationclass, the class-information is contained in the instance, inherited from Class
.
An instance of the AssociationEnd
class contains information about a connection to a class, for example in an association.
bool GetFile(filename, omModule, status)
Loads the contents of filename
into omModule.
Returns true
on success, false
if failed to load the module.
bool GetBufID(bufID,omModule,status)
Loads the contents of the buffer bufID
into omModule
. Returns true
on success, false
if failed to load the module.
GetSuperClassList(omModule,className,superClasses)
Fills the list superClasses
with the names of the superclasses to className
in omModule
.
GetSubClassList(omModule,className,superClasses)
Fills the list subClasses
with the names of the subclasses to className
in omModule
.
string SourceAggregationEnd(association)
Returns the name of the class which starts the aggregation (the end with the square in it), the owner-part. (The source
contains the end
.)
Parameter | Type | Description |
---|---|---|
association |
AssociationClass |
The association to check. |
string TargetAggregationEnd(association)
Returns the name of the class that ends the aggregation (the end without the square in it), the owned-part. (The source
contains the end
.)
Parameter | Type | Description |
---|---|---|
association |
AssociationClass |
The association to check. |
void GetEndPoints(association, classes)
Fills the classes list with the names of the classes that this association/aggregation is connected to.
Parameter | Type | Description |
---|---|---|
association |
AssociationClass |
The association to check. |
classes |
list<string> * |
The list to insert the names into. |
bool hasEndPoint(association, name)
Returns true if association
has an endpoint at name
.
Parameter | Type | Description |
---|---|---|
association |
AssociationClass |
The association to check. |
name |
string |
The class to check. |
void GetAggregations(omModule,aggregations)
Fills aggregations
with all the aggregations in omModule
.
Parameter | Type | Description |
---|---|---|
omModule |
OMModule |
The OMModule containing the diagram information. |
aggregations |
list<AssociationClass> |
The list to fill with aggregations. |
void GetAggregations(comModule,aggregations,owner)
Fills aggregations
with all the aggregations in omModule
, that has owner
as source.
void GetAssociations(omModule, associations)
Fills associations
with all the associations in omModule
.
Parameter | Type | Description |
---|---|---|
omModule |
OMModule |
The OMModule containing the diagram information. |
associations |
list<AssociationClass> |
The list to fill with associations. |
void GetAssociations(omModule, associations, firstEnd)
Fills associations
with all the associations in omModule
, that is connected to firstEnd
, in some end.
void GetAssociations(omModule,associations, firstEnd,secondEnd)
Fills associations
with all the associations in omModule
, that is connected to firstEnd
, and secondEnd.
void TraceModule(omModule,os)
Outputs a textual dump of omModule
to os
, with as much information as possible, useful for debugging purposes.
Parameter | Type | Description |
---|---|---|
omModule |
OMModule |
The OMModule containing the diagram information. |
os |
ostream |
The stream to output the dump to. |
1. stlmini.h
can be replaced by the appropriate standard C++ headers <list.h>
and <string.h>
if you have access to an implementation of the standard C++ library.