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

Chapter 14: Java Code Generation and Reverse Engineering

UsePrefixes

InstanceVariablePrefix

ClassVariablePrefix

StopOnError

CreateMissingDirectories

NoClassCustomDlg (Always Show Standard Specification Dialog for Classes)

AutoSync (Automatic Synchronization Mode)

ShowCodeGenDlg (Show Codegen Dialog)

Figure 14.6: Detail tab of the Java Project Specification window

Refer to Table 14.2 for a description of each of these properties.

Class Properties

In this section, we discuss the Java code−generation properties that apply to classes. These properties will let you change the class name, decide whether or not constructors should be created for the class, and set other class−specific properties.

456

Chapter 14: Java Code Generation and Reverse Engineering

There are three places to set these properties. To set them for all classes, select Tools → Options, then click the Java tab and select Class from the drop−down list box. To set them for only one class, either select the Java tab on the standard class specification window and edit the properties there or open the custom Java class specification window for the class.

Table 14.3 lists the Java class properties, their purposes, and their default values.

Table 14.3: Java Class Properties

Property

Purpose

Default

Final

Includes the final modifier in the generated code.

False

Static

Declares that a nested Java class is static and that only

False

 

one instance of the class can exist.

 

GenerateDefaultConstructor

Controls whether or not a constructor will

True

 

automatically be generated for the class.

 

ConstructorIs

Sets the visibility (public, private, protected) of the

Public

 

constructor.

 

GenerateFinalizer

Includes a finalizer in the class.

False

GenerateStaticInitializer

Includes a static initializer in the class.

False

GenerateInstanceInitializer

Includes an instance initializer in the class.

False

GenerateCode

Generate code for the class.

True

DisableAutoSync

Disables the automatic generation of code when the

False

 

class changes. (Automatic generation is always

 

 

disabled if the AutoSync project property is set to

 

 

False.)

 

These properties can also be set using the custom Java specification window for the class, as shown in Figure 14.7. As you can see on this window, you can set each of the class properties using the fields with corresponding names. The ConstructorIs property is set through the Constructor Visibility field.

Figure 14.7: Setting class properties through the Java Class Specification window

457

Chapter 14: Java Code Generation and Reverse Engineering

In addition, you can mark the class as abstract using this window. An abstract class will never directly be instantiated. You can mark the class as an interface, in which case the final modifier, finalizer, static initializer, and instance initializer will no longer be available. Using the Extends area, you can list any classes of which this is a subclass. Using the Implements area, you can list any interfaces that this class implements.

Attribute Properties

In this section, we cover the Java code−generation properties that relate to attributes. Using these properties, you can, for example, decide whether or not the attribute will be generated in the code.

There are three places to set these properties. To set them for all attributes, select Tools → Options, then click the Java tab and select Attribute from the drop−down list box. To set them for only one attribute, select the Java tab on the standard attribute specification window (right−click the attribute in the browser and select Open Standard Specification) or open the Java attribute specification window (right−click the attribute in the browser and select Open Specification) and edit the properties there. Figure 14.8 shows the Java tab under Tools → Options, with which you can set properties for all attributes.

Figure 14.8: Setting Java attribute properties

Table 14.4 lists the attribute properties, their purposes, and their default values.

Table 14.4: Java Attribute Properties

Property

Purpose

Default

Final

If True, includes a final modifier in the attribute.

False

Transient

Includes a transient modifier in the attribute.

False

Volatile

Includes a volatile modifier in the attribute.

False

PropertyType

Specifies the property type for a Java Bean.

Not a Property

IndividualChangeMgt

Specifies whether or not the Java Bean gets its own

False

 

registration mechanism.

 

458

Chapter 14: Java Code Generation and Reverse Engineering

Read/Write

Sets whether or not Rose will generate a Get and/or a

Read & Write

 

Set method for the attribute.

 

GenerateFullyQualifiedTypes

Include the complete file path in the generated code

False

 

for reference attributes.

 

You can set the values of these properties using the Java attribute specification window, as shown in Figure 14.9.

Figure 14.9: Setting attribute properties through the Java Field Specification window

Using this window, you can also set the static flag, the attribute visibility, the initial value, and the data type for the attribute. The static flag marks the attribute as a class variable as opposed to an instance variable. The attribute visibility (public, private, protected, or package) controls what other classes will be able to access the attribute. The attribute's initial value is set using this window, and will be generated in the code. The data type can be set by pressing the "…" button next to the Type field and selecting from the list of Java types

presented. The Container Class field is also displayed on this window, but is used only for relationships.

Operation Properties

Next, we discuss the Java code−generation properties that are specific to operations. These properties will let you, for example, control whether the operation is abstract or not.

There are three places to set these properties. To set them for all operations, select Tools → Options, then click the Java tab and select Operation from the drop−down list box. To set them for only one operation, select the Java tab on the standard operation specification window, or open the Java operation specification window and edit the properties there.

Table 14.5 lists the operation code−generation properties, their purposes, and their default values.

Table 14.5: Java Operation Properties

Property

Purpose

Default

Abstract

Includes an abstract modifier in the operation.

False

Static

Includes a static modifier in the operation.

False

Final

Includes a final modifier in the operation.

False

459