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

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Whether an indefinite number of parameters may be passed for the operation (ParamArray field)

Each of these settings will affect the generated code.

Module Specification Properties

The module specification properties are related to the project files you will generate from Rose. There are three places to set these properties. To set them for all components, select Tools → Options, then click the Visual Basic tab and select Module Specification from the drop−down list box. To set them for only one component, select the Visual Basic tab on the component specification window and edit the properties there, or use the Visual Basic Component Properties window.

Table 15.4 lists the code−generation properties for components, their purposes, and their default values.

Table 15.4: Module Specification Code−Generation Properties

Property

Purpose

Default

ProjectFile

Sets the name of the project file

<Set using the Code

 

 

Generation Wizard>

UpdateCode

Specifies if code can be generated for this component

True

UpdateModel

Specifies if the model can be updated for this

True

 

component

 

ImportReferences

Specifies whether to import ActiveX components

True

QuickImport

Specifies whether to import only ActiveX interface

True

 

classes or all classes including methods and

 

 

operations

 

ImportBinary

Determines whether Rose should import the type

False

 

library for the component on the next reverse engineer

 

502

Chapter 15: Visual Basic Code Generation and Reverse Engineering

To open the Visual Basic Component Properties window, as shown in Figure 15.6, right−click the component and select Properties.

Figure 15.6: VB Component Properties Window

The Should Be Generated and Should Be Updated from Code fields correspond to the UpdateCode and UpdateModel properties, respectively. The Project File field corresponds to the ProjectFile property. Using the References tab, you can set the QuickImport, ImportBinary, and ImportReferences properties.

Role Properties

Role properties are the Visual Basic code−generation properties that affect the code generated for relationships. The role properties let you set the name of the attribute that is created; control the generation of Get, Set, and Let operations; and change other specific pieces of the generated code.

503

Chapter 15: Visual Basic Code Generation and Reverse Engineering

There are two places to set these properties. To set them for all associations, select Tools → Options, then click the Visual Basic tab and select Role from the drop−down list box. To set them for only one operation, select the Visual Basic tab on the association specification window and edit the properties there. Table 15.5 lists the code−generation property for roles.

Table 15.5: Role Code−Generation Properties

Property

Purpose

Default

UpdateCode

Specifies if code can be generated for this role

True

New

Controls if the association is generated with a new

False

 

modifier

 

WithEvents

Controls if the association is generated with the With

False

 

Events modifier

 

Fullname

Specifies whether to use the full name of the

False

 

referenced class in the property declaration

 

PropertyName

The name of the property to which the attribute

<blank>

 

created to support the relationship belongs

 

Subscript

Specifies the array subscript for an attribute

<blank>

ProcedureID

Sets the Visual Basic procedure ID

<blank>

Generalization Properties

Generalization properties are the Visual Basic code−generation properties that affect the code generated for generalization relationships. As Visual Basic does not support inheritance, there are only two properties for generalization relationships. The ImplementsDelegation property controls whether the generalization is realized by an implements delegation. The FullName property controls whether the full name of the class, including the component name, should be used in the implements statement.

504

Chapter 15: Visual Basic Code Generation and Reverse Engineering

There are two places to set these properties. To set them for all generalizations, select Tools → Options, then click the Visual Basic tab and select Generalize from the drop−down list box. To set them for only one generalization, select the Visual Basic tab on the generalization specification window and edit the properties there.

Using the Code−Generation Wizard

After you create classes and associations in the Rose model, you can use a Code−Generation Wizard to generate the Visual Basic code. To begin this process, select the objects to generate, then select Tools → Visual Basic → Update Code from the menu. You will see the screen shown in Figure 15.7.

Figure 15.7: Code−Generation Wizard

505

Chapter 15: Visual Basic Code Generation and Reverse Engineering

If you have not yet assigned the objects to components, you will see a window like the one in Figure 15.8. You have the option of assigning the classes to an existing component (in this example, there is a single component called Airline Reservation with a stereotype of Standard EXE). Alternatively, you can create a new component and assign classes to it.

Figure 15.8: Assigning components and classes

To assign classes to an existing component, right−click the component in the Code−Generation Wizard shown in Figure 15.8 and select Assign Classes. You will see a list of unassigned classes:

Drag and drop each class from the right side of the screen to the appropriate component on the left side. Once all classes are assigned, click OK.

To create a new component, select the Create a Visual Basic Component and Assign Classes to It option, as shown in Figure 15.8, or press Ctrl+R. You will be asked what type of component to create:

506

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Select the appropriate type (in this example, we use a Standard EXE) and press OK. The component will be added, and all unassigned classes will be assigned to it:

Check the box next to the components or classes you wish to update. Notice that if you click on a class, you can preview the code that will be generated for the attributes and operations of that class:

Right−click and select Open to view the properties for an object in the treeview. Rose will display the appropriate Model Assistant screen, and allow you to modify any code−generation properties before the final code is generated. For example, right−clicking the Flight class will display the screen shown in Figure 15.9.

507

Chapter 15: Visual Basic Code Generation and Reverse Engineering

Figure 15.9: Setting code−generation properties for the Flight class

Once all classes have been assigned and all code−generation properties are set, click Next to complete the process. You will see a summary screen, as shown in Figure 15.10. Press Finish to generate the code. If Visual Basic is not already running, Rose will launch it and create the appropriate project, classes, and other elements.

Figure 15.10: Code−generation summary screen

An example of the code generated for the Flight class follows below. In the remainder of this chapter, we will discuss the mapping between a Rose model and Visual Basic code.

Option Explicit

'##ModelId=3A818E9F01D0 Private DepartureCity As String

'##ModelId=3A818EAC02C9 Private DepartureDate As String

'##ModelId=3A818EB300CA

Private DestinationCity As String

'##ModelId=3A818EB70134 Private FlightNumber As String

'##ModelId=3A818ECE01A6

508