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

Chapter 14: Java Code Generation and Reverse

Engineering

Overview

In this chapter, we'll discuss how to generate Java code from your Rational Rose model and reverse engineer a Rose model from your Java code. We'll discuss the code−generation properties that can be set for Java and take a close look at how each Rose model element is implemented in the code. Then, we'll look at how to reverse engineer Java code and how to keep your model and code synchronized.

To generate code, you'll need to follow these steps:

1.

Create the components (see Chapter 10, "Component View").

2.

Assign classes to the components (see Chapter 10).

3.

Set the code−generation properties.

4.

Select a class or component to generate on a Class or Component diagram.

5.

Select Tools → Java → Code Generation.

6.

Select Tools → Java → Browse Java Source to view the generated code.

Rose will take a lot of information from the model to generate code. For example, it will look at the multiplicity, role names, containment, and other details of each relationship. It will look at the attributes, operations, visibility, and other details of each class. From all of the information you entered using the specification windows for the various model elements, Rose will gather what it needs to generate code.

Setting Java code−generation properties

Generating Java code from your Rose model

Mapping Rose elements to Java constructs

Importing the Java Development Kit

Reverse engineering Java into your Rose model

447

Chapter 14: Java Code Generation and Reverse Engineering

Introduction to Rose J

Rose J is the add−in to Rational Rose that supports the generation and reverse engineering of Java constructs. This feature includes:

Integration with VisualAge Java and Visual J++

Support for Java 2 Platform Enterprise Edition (J2EE) constructs

Generation of Java code

Reverse engineering Java constructs into a Rose model

Support for Java frameworks, such as the JavaDevelopment Kit (JDK) and JavaFoundation Classes (JFC).

Let's begin with code generation. Rose J will examine the classes and components that you have created in your Rose model and generate the appropriate source code for these components. There are a number of code−generation properties that will affect the generated source code. Using Rose J, Rose ID numbers will also be created in the source code. These numbers help to keep the code from being overwritten during round−trip engineering.

There is an auto−synchronization feature in Rose J, which automatically starts the code−generation process anytime a Java class has changed in the model. This feature will help ensure that the model and the source code remain consistent.

Once you create your classes, components, attributes, operations, and other model elements, you can begin the code−generation process. Before generating code, check the syntax of the model using the Tools → Java → Syntax Check menu option. If there are any problems, they will appear in the log window.

After you resolve any problems, you can set the code−generation properties and generate code. In this chapter, we will discuss in detail how to set the properties and how each Rose modeling element maps to a Java construct. Table 14.1 lists the Java constructs and their corresponding model elements.

Table 14.1: Java−to−Rose Mapping

Java Construct

Rose Element

Class

Class

Variable

Attribute

Method

Operation

Interface

Interface (class with stereotype of Interface)

.java file

Component

448