Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

};

#endif

Before you can generate code, each of the attributes must have a case specifier. Open the specification window for each of the attributes, and enter a value in the Case Specifier property. The values you enter will control the case statements generated in the code. In the above example, the case specifier for Attribute1 is 1, and the specifier for Attribute2 is 2.

Attributes

As you may have noticed in the previous examples, attributes are generated in the code along with the class. This isn't true for all CORBA types, however. In this section, we'll examine the code generated for attributes for each of the types: interface, typedef, enumeration, constant, exception, structure, and union. For each of these types, we'll take a look at what is generated for the following class:

Attributes Generated for an Interface

In an interface, all of the attributes of the class will appear in the generated code. For each attribute, Rose will include:

Data type

Documentation

This is the interface that is generated for the SampleClass class:

//Source file: C:/corba/SampleClass.idl

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "IncludedClass.idl"

interface SampleClass { attribute string Attribute1; attribute string Attribute2;

};

#endif

588

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

Attributes Generated for a TypeDef

If the class stereotype is set to CORBATypeDef, attributes do not appear in the generated code.

Attributes Generated for an Enumeration

With an enumeration, Rose will place the attributes in the generated code. However, Rose will ignore the data types, default values, and other specifications of the attribute. Here is the enumeration generated for the SampleClass class:

//Source file: C:/corba/SampleClass.idl

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "IncludedClass.idl"

enum SampleClass {

Attribute1,

Attribute2

};

#endif

Attributes Generated for a Constant

If the class stereotype is set to CORBAConstant, attributes do not appear in the generated code.

Attributes Generated for an Exception

If the class stereotype is set to CORBAException, all attributes of the class will be included in the code. For each attribute, the code will include:

Data type

Documentation

Here is the code generated for SampleClass when the stereotype is set to CORBAException:

//Source file: C:/corba/SampleClass.idl

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "IncludedClass.idl"

exception SampleClass {

589

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

string Attribute1; string Attribute2;

};

#endif

Attributes Generated for a Structure

If the class stereotype is set to CORBAStruct, all attributes of the class will be included in the code. For each attribute, the code will include:

Data type

Documentation

Here is the code generated when the SampleClass stereotype is set to CORBAStruct:

//Source file: C:/corba/SampleClass.idl

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "IncludedClass.idl"

struct SampleClass { string Attribute1; string Attribute2; };

#endif

Attributes Generated for a Union

If the class stereotype is set to CORBAUnion, the attributes of the class will appear as case statements in the union. Here is the code generated for SampleClass:

//Source file: C:/corba/SampleClass.idl

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "IncludedClass.idl"

union SampleClass switch(long) { case 1: string Attribute1;

case 2: string Attribute2; };

590

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

#endif

The values used in the case statements are set by the values you enter in the Case Specifier field in each attribute's specification window.

Operations

The operations you define in your Rose model will appear in the generated IDL. Like attributes, though, operations are included only for certain CORBA types. In this section, we'll take a look at the code generated for operations of the following class:

We'll examine how the code is generated as the stereotype of the class changes.

Operations Generated for an Interface

With an interface, all of the operations for the class will appear in the generated code, along with their parameters, parameter data types, and return type. For the SampleClass class, the following interface was generated:

//Source file: C:/corba/SampleClass.idl

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "IncludedClass.idl"

interface SampleClass { /*

@roseuid 39B5C1A0006A */ string Operation1 ();

};

#endif

Operations Generated for Other CORBA/IDL Types

Operations are shown in the generated IDL only for interfaces. If the class stereotype is a typedef, enumeration, const, exception, struct, or union, operations will not be generated in the code.

Bidirectional Associations

To support bidirectional associations, Rose will generate attributes in the code. Each of the classes in the relationship will contain an attribute to support the association. The names of the generated attributes will be controlled by the role names on the association relationship. You must enter role names before you can generate code.

591

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

The code generated for the two classes shown above will resemble the following:

interface Class_A {

attribute Class_B Class_B_Role; };

and

interface Class_B {

attribute Class_A Class_A_Role; };

As you can see, Rose will automatically generate attributes on both sides of the bidirectional association relationship. With the Class_B_Role attribute, Class_A can easily access Class_B. Using the Class_A_Role attribute, Class_B can easily access Class_A.

The full code generated for Class_A is:

//Source file: C:/corba/Class_A.idl

#ifndef CLASS_A_DEFINED #define CLASS_A_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "Class_B.idl"

interface Class_A {

attribute Class_B Class_B_Role;

};

As you can see, Class_A now includes an attribute of type Class_B. Class_B will also include an attribute of type Class_A. These two attributes support the relationship between Class_A and Class_B.

Bidirectional Associations Generated for a TypeDef

If the stereotype for Class_A is set to CORBATypeDef, a Class_B attribute will not be included in the code for Class_A. However, an #include statement will be added to the code in Class_A, as follows:

592

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

#include "Class_B.idl"

Bidirectional Associations Generated for an Enumeration

If the stereotype of Class_A is set to CORBAEnum, an include statement for Class_B.IDL will be included in the code. An attribute will not, however, be generated in Class_A. The code for Class_A looks like this:

//Source file: C:/corba/Class_A.idl

#ifndef CLASS_A_DEFINED #define CLASS_A_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "Class_B.idl"

enum Class_A {

};

#endif

Bidirectional Associations Generated for a Constant

If Class_A is a constant, it will have an include statement for Class_B, but will not have an attribute that supports the relationship. Here is the code generated for Class_A:

//Source file: C:/corba/Class_A.idl

#ifndef CLASS_A_DEFINED #define CLASS_A_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "Class_B.idl"

const long Class_A = 4;

#endif

Bidirectional Associations Generated for an Exception

If Class_A is an exception, an attribute of type Class_B will be generated inside it. Here is the code generated for Class_A:

//Source file: C:/corba/Class_A.idl

#ifndef CLASS_A_DEFINED #define CLASS_A_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "Class_B.idl"

exception Class_A {

593

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

Class_B Class_B_Role; };

#endif

Bidirectional Associations Generated for a Structure

If the stereotype of Class_A is CORBAStruct, an attribute will be created inside Class_A when you generate the IDL.

The code for Class_A is as follows:

//Source file: C:/corba/Class_A.idl

#ifndef CLASS_A_DEFINED #define CLASS_A_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "Class_B.idl"

struct Class_A { Class_B Class_B_Role; };

#endif

Bidirectional Associations Generated for a Union

If the stereotype for Class_A is set to CORBAUnion, the generated code will have an include statement for Class_B, and will include an instance of Class_B within the switch statement. Here is the code generated for Class_A:

//Source file: C:/corba/Class_A.idl

#ifndef CLASS_A_DEFINED #define CLASS_A_DEFINED

/* CmIdentification %X% %Q% %Z% %W% */

#include "Class_B.idl"

union Class_A switch() {

case 1: Class_B Class_B_Role; };

#endif

Note that the attribute generated from the association needs a case specifier, as do the other attributes of Class_A. The case specifier can be set using the Case Specifier Role code−generation property for the relationship.

594