Tool Mentor: Using Rational Rose® to
Reverse-Engineer Code
Purpose
This tool guide describes how to use Rational Rose to reverse-engineer existing code
into elements in the Artifact: Design Model.
Reverse engineering source code with Rational Rose requires a Rational Rose Language
Support add-in that is compatible with that source code. For example, Rational Rose
Visual C++ is required to reverse engineer an existing Visual C++ project.
For simplicity, this activity generally references a Microsoft®Visual C++
project, but the steps are generic to any language supported by Rational Rose.
Related Rational Unified Process activity: section "Reverse-engineer components
and databases" in Activity:
Architectural Design.
Overview
Reverse engineering (also called archeology) is the process of examining an existing
source - or binary - code project to recover information about its design, then using that
information to generate or update a model representing the project's logical structure.
A code project corresponds to a component in the component view of a model. Reverse
engineering is performed between the project file and the target model.
When reverse engineering source code for an existing modelcode that was generated
by the Code Update toolcode elements that were removed from the project have their
corresponding model elements remove from the model. You can choose to confirm or reject
these deletions in the Model Update tools Synchronize window.
You can use Rational Rose to reverse-engineer existing code into a design model in one
of four ways:
- Create a new model by reverse-engineering code.
- Update an existing model by reverse-engineering
code.
- Add code from other projects into your model.
- Add external components to a model.
- Packaging and diagramming reverse-engineered
components
Note: When Rational Rose reverse-engineers or imports code information, it assigns the
resulting model elements to a package (with the same name as the project) within the
reverse-engineered package. Diagramming these components, or adding them to other
packages, is left up to you. See Packaging and Diagramming Reverse-Engineered Classes.
Note: Before proceeding with these steps, make certain the project you want to reverse
engineer compiles and contains no syntax errors.
To create a new Rose model from existing source code:
- Open a new model in Rational Rose.
- Create or open a component diagram. To create a new diagram, right-click on the
Component View folder, select New, and then select Component Diagram.
- From the Tools menu, select Visual C++, then select Update Model from
Code. If you see the welcome screen, click Next>.
- In the Project Components window, right-click on Visual C++ and select Add
Component.
- Enter the name of the Visual C++ workspace file (.dsw) containing the
project to reverse engineer, or click Browse to find the file. If the workspace
contains more than one project, select a project.
- Click OK. This displays the Visual C++ project in the Model Update
tools Component window.
- Click Next> to reverse engineer the entire project, or click on the + to list
the class names in the project.
- Select the classes to reverse engineer, and then click Next>. The Model Update
tool lists the project and classes it is about to reverse engineer.
- Click Finish. The Model Update tool Summary lists the components that were
reverse engineered.
- Click Close. The newly reverse engineered component is placed in a package with
the project name under the Reverse Engineered folder in both the Component View and the
Logical View.
- Assign and diagram your reverse-engineered classes. See "Packaging and Diagramming
Reverse-Engineered Classes" for more information.
You can now further develop the model.
Note: Before proceeding with these steps, make certain the project you want to
reverse engineer compiles and contains no syntax errors.
To update an existing model by reverse engineering changes to the source code:
- Open the model in Rational Rose.
- From the Tools menu, select Visual C++, then select Update Model from
Code. If you see the welcome screen, click Next>. The Model Update tool
displays and the project associated with the model is checked for reverse engineering.
- Click Next> to reverse engineer the entire project, or click on the + to list
the class names in the project. Select the classes to reverse engineer, and then click Next>.
The Model Update tool lists the project and classes it is about to reverse engineer.
- Click Finish. The Model Update tool Summary lists the components that were
reverse engineered.
- Click Close. The modeled elements are updated. If you had deleted classes in the
code that had been created by the Code Update tool, a synchronization page would display
asking you to confirm the deletion of these classes from the model. See
"Synchronizing Model and Code".
You can now further develop the model.
Note: Before proceeding with these steps, make certain the project you want to
reverse engineer compiles and contains no syntax errors.
- Open the model in Rational Rose.
- From the Tools menu select Visual C++, then, select Update Model from
Code. If you see the welcome screen, click Next>. The Model Update tool
displays and the project associated with the model is checked for reverse engineering.
- In the Project Components window, right-click on Visual C++ and select Add
Component.
- Enter the name of the Visual C++ workspace file (.dsw) containing the
project to reverse engineer, or click Browse to find the file. If the workspace
contains more than one project, select a project.
- Click OK. This adds the new Visual C++ project to the Model Update
tools Component window.
- Deselect the existing model project(s).
- Click Next> to reverse engineer the entire project, or click on the + to
list the class names in the project. Select the classes to reverse engineer, and then
click Next>. The Model Update tool lists the project and classes it is about to
reverse engineer.
- Click Finish. The Model Update tool Summary lists the components that were
reverse engineered.
- Click Close. The newly reverse engineered component is placed in a package with
the project name under the Reverse Engineered folder in both the Component View and the
Logical View.
- Assign and diagram the reverse-engineered classes. See "Packaging and Diagramming
Reverse-Engineered Classes" for more information.
You can now further develop the model.
External components are classes that are not implemented in your application. Instead,
they are referenced or are sub-classed by model classes and by code implemented in your
application. For example, COM objects, or Microsoft®Foundation Classes (MFC).
Because they are not implemented in your applications code, only their interface
and internal documentation are reverse engineered. This limited form of reverse
engineering is called Importing.
Note: This process should be restricted to components that are external to the
model, or that will be sub-classed in the model. External classes should have their
Generate Code flag set to false.
To access COM objects from your model, simply drag and drop the COM object file (.dll,
.exe, .ocx, or .tlb) from the Explorer into an open component
diagram, a component package, or onto a logical package in the browser.
- If the drop target is a component package or one of its diagrams, the new component will
belong to that package. Otherwise, the new component is added to the top-level of the
Component View and to the main component diagram.
- A logical package with the same name as the new component is created in the logical
view. The new logical package contains the interface elements that are provided by the
corresponding software module. The interface of the new component can now be used by the
classes in the model.
- If the drop target is a logical package or one of its diagrams, the logical package for
the new component is added to that package.
Two conditions must be met before you can drag-and-drop a COM object into your model:
- The TypeLibImporter add-in must be loaded and activated
- The selected COM object file must either be a properly registered TypeLib (.tlb) or must
contain a TypeLib.
If both of these conditions are not met, the drop into the model is ignored.
For Visual C++ users, you can access the MFC library from your model by simply
importing it: From the Tools menu, select Visual C++, then select Quick
Import MFC 6.0.
This adds a logical package named MFC to your model, represented by an MFC folder in
the Logical View and an MFC component in the Component View. This package contains the
complete interface set for all public MFC classes and their internal documentation, if
any. Imported MFC classes have their Generate Code flag set to False. You only want
to reference or sub-class these, not generate code for them.
When Rational Rose reverse engineers or imports code information, it assigns the
resulting model data to a package (with the same name as the project) under the Reverse
Engineered package, or to an MFC package, as appropriate. Diagramming these components, or
adding them to other packages, is left up to you.
Diagramming Reverse-Engineered projects
Diagramming a model is a very subjective process. For this reason, the reverse
engineering process generates model data only. It does not generate model diagrams. You
can add classes to a diagram in either of two ways:
- Drag-and-drop classes from the browser to an open diagram.
- Add one or more classes, by name, to the active diagram using the Add Classes dialog box
(from the Query menu, select Add Classes)
Arrange the diagrammed components to illustrate the architecture of the system. Avoid
crossed association lines by moving the classes in the diagram. You can use the Diagram
Object Properties command on the Edit menu to control the level of class
details in a diagram.
Dropping Classes into a Diagram
You can add a class to a diagram simply by opening the diagram, then dragging and
dropping the individual classes from the browser into the diagram.
The Add Classes Dialog Box
You can use the Add Classes dialog box to move classes from a package to the
active diagram:
- Open the Class diagram where you want to add the classes. Make certain it is the active
diagram.
- From the Query menu, select Add Classes.
- From the Package drop-down, select the package that currently holds your classes.
- From the Classes window, select the classes you want to move, and transfer them
to the Selected Classes window.
- Click OK.
The selected classes are added to the active diagram. Arrange the added classes to best
illustrate the architecture of the system.
Adding Reverse-Engineered Classes to Packages
While you may leave your new classes in their reverse-engineered project package, can
also move or copy them to other packages in your system. There are four ways to move a
class from one package to another:
- Drag-and-drop the class from the Reverse Engineered package to the one you want it in.
- Open a class diagram that contains the destination package, then drag-and-drop the class
from the Reverse Engineered package to the one you want it in.
- Create a new class in your package diagram with the same name as the reverse-engineered
one, select this new class, then choose Relocate from the Edit menu to move
the class.
- Cut or Copy, then Paste the class from the Reverse Engineered package to the one you
want it in.
|