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

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

There are two places to set the dependency property. To set the property for all dependencies, select Tools → Options, then click the CORBA tab and select Dependency from the drop−down list box. To set the property for only one dependency, select the CORBA tab on the dependency specification window and edit the properties there. There is only one dependency property, GenerateForwardReference, which controls whether a referenced interface is included with an #include statement or a forward reference. By default, a #include statement is used.

Generated Code

In the following sections, we'll examine the CORBA that is generated from the various types of model elements. Rose will use the information you entered in the specification windows for the various model elements when generating the CORBA/IDL.

Let's begin by looking at the code generated for a typical class.

Classes

A class in your object model will generate a single IDL file. The file that is generated will look something like the following:

Interface TheClass

{

};

A great deal of additional information, such as configuration management statements, copyright notices, and include statements, will also be generated in the code. We'll look at a complete file in the following section, "Standard Code Generation."

581

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

All of the attributes, operations, and relationships of the class will be reflected in the generated code. The major elements generated for each class include:

Class name

Attributes

Operations

Relationships

Documentation

When generating code, Rose will use the package structure you established in the Component view of your model to generate the appropriate directories. A directory will be created for each package in the model. Within each of the directories Rose creates will be the files for the classes in that package.

Much of the information in your Rose model will be used directly when generating code. For example, the attributes, operations, relationships, and class name of each class will directly affect the code generated. Other model properties, such as the documentation entered for the class, will not directly affect the code. These properties are created as comments in the generated code.

Table 17.7 lists the properties available in the class specification window and notes which of these properties will directly affect the IDL that is generated.

Table 17.7: Effect of Class Specifications on IDL

Property

Effect on Code

Name

Name in model will become class name

Type

No effect

Stereotype

No effect

Export Control

No effect

Documentation

Comment

Cardinality

No effect

Space

No effect

Persistence

No effect

Concurrency

No effect

Abstract

No effect

Formal Arguments

No effect

Operations

Generated in code

Attributes

Generated in code

582

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

Relationships

Generated in code

Standard Code Generation

Let's look at the code generated for the following class.

The following IDL file was generated for the SampleClass:

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

#ifndef __SAMPLECLASS__DEFINED #define __SAMPLECLASS__DEFINED

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

#include "IncludedClass.idl"

interface SampleClass { };

#endif

Let's examine each piece of this file, one at a time.

Module Section

The module section contains some basic information about the class being generated. It includes the following line:

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

This section includes comments that describe what class is being generated and where the IDL file is located.

Configuration Management Section

The configuration management section is provided to support integration with your configuration management software. It includes the following lines:

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

This section of the file includes information about your configuration management settings. The properties on the second line (%X% %Q% %Z% %W%) are the default configuration management settings. To change the configuration management settings, select Tools → Options from the menu. In the CORBA tab, select Module Specification from the drop−down list box to display the module specification code−generation properties. You can use the CmIdentification property to change the default values on this second line. Using this property, you can set the Change Management settings to a string that your configuration management software will recognize.

Some sample values you can place in this setting include:

583

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

$date, which inserts the date the code was generated

$time, which inserts the time the code was generated

$module, which inserts the component name

$file, which inserts the component's file

Preprocessor Directives Section

The preprocessor directives include the following lines:

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

These lines are inserted into the code to prevent the file from being included more than once.

Includes Section

The includes section is the area of the generated code that shows any entries you added in the AdditionalIncludes code−generation property for the component and any entries you added in the Includes section of the specification window for the component.

The includes section for the SampleClass is as follows:

#include "IncludedClass.idl"

In this example, only one other class, called IncludedClass, was included.

Class Definition Section

This section contains information about the class itself, including the class name, its attributes, its operations, and its relationships. For the class example above, the definition section includes the following:

interface SampleClass { };

If you entered any documentation for the class using the documentation window or the documentation area of the class specification window, this documentation will be included as a comment in the code.

Code Generated for Different Types of CORBA/IDL

The code that is generated depends directly upon the stereotype (interface, union, const, etc.) of the class. Let's examine the code generated for the following class, with each of the different CORBA/IDL stereotype options.

584

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

TypeDef Generation

If the class stereotype is set to CORBATypeDef, an interface will not be generated for the class. Instead, a typedef will be created. In the Implementation Type property on the Class Specification window, enter the definition that this typedef will be aliasing. The code generated for the SampleClass class looks like this:

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

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

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

#include "IncludedClass.idl"

typedef long SampleClass;

#endif

Enumeration Generation

The second CORBA type you can generate is an enumeration. If you select this option, Rose will use the keyword "enum" in the generated file. The following is the code generated for the class above, but with the stereotype set to CORBAEnum.

//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

Constant Generation

The third CORBA type that you can generate is a constant. In this case, Rose will include the keyword "const" in the generated IDL. To generate a constant, set the class stereotype to CORBAConstant. In the Class Specification window, set the Implementation Type field to the data type you wish to use and the Constant Value field to the value of the constant.

585

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

The following is the file generated for SampleClass.

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

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

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

#include "IncludedClass.idl"

const long SampleClass = 4;

#endif

Exception Generation

The fourth CORBA type you can generate is an exception. If the class stereotype is set to CORBA−Exception, Rose will include the keyword "exception" in the code. Here is the file generated for SampleClass:

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

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

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

#include "IncludedClass.idl"

exception SampleClass { string Attribute1; string Attribute2;

};

#endif

Structure Generation

Another CORBA type you can generate is a structure. Rose will include the "struct" keyword in the generated file if the stereotype of the class is set to CORBAStruct. The attributes of the class will appear as data

586

Chapter 17: CORBA/IDL Code Generation and Reverse Engineering

members in the generated file. The code generated for SampleClass is:

//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

ValueType Generation

By setting the stereotype to CORBAValue, you can generate a valuetype. Here is the code generated for the SampleClass class with a stereotype of CORBAValue:

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

#ifndef __SAMPLECLASS_DEFINED #define __SAMPLECLASS_DEFINED

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

#include "IncludedClass.idl"

valuetype SampleClass {

;

;

};

#endif

Union Generation

Finally, you can generate a union in CORBA by setting the class stereotype to CORBAUnion. The generated code looks like this:

//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;

587