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 model—code that was generated by the Code Update tool—code 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 tool’s Synchronize window.

You can use Rational Rose to reverse-engineer existing code into a design model in one of four ways:

  1. Create a new model by reverse-engineering code.
  2. Update an existing model by reverse-engineering code.
  3. Add code from other projects into your model.
  4. Add external components to a model.
  5. 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.

1. Create a New Model by Reverse-engineering code To top of page

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:

  1. Open a new model in Rational Rose.
  2. 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.
  3. From the Tools menu, select Visual C++, then select Update Model from Code. If you see the welcome screen, click Next>.
  4. In the Project Components window, right-click on Visual C++ and select Add Component.
  5. 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.
  6. Click OK. This displays the Visual C++ project in the Model Update tool’s Component window.
  7. Click Next> to reverse engineer the entire project, or click on the + to list the class names in the project.
  8. 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.
  9. Click Finish. The Model Update tool Summary lists the components that were reverse engineered.
  10. 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.
  11. Assign and diagram your reverse-engineered classes. See "Packaging and Diagramming Reverse-Engineered Classes" for more information.

You can now further develop the model.

2.   Update an Existing Model by Reverse-engineering code To top of page

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:

  1. Open the model in Rational Rose.
  2. 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.
  3. 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.
  4. Click Finish. The Model Update tool Summary lists the components that were reverse engineered.
  5. 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.

3. Add Code from other Projects into your Model To top of page

Note: Before proceeding with these steps, make certain the project you want to reverse engineer compiles and contains no syntax errors.

  1. Open the model in Rational Rose.
  2. 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.
  3. In the Project Components window, right-click on Visual C++ and select Add Component.
  4. 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.
  5. Click OK. This adds the new Visual C++ project to the Model Update tool’s Component window.
  6. Deselect the existing model project(s).
  7. 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.
  8. Click Finish. The Model Update tool Summary lists the components that were reverse engineered.
  9. 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.
  10. Assign and diagram the reverse-engineered classes. See "Packaging and Diagramming Reverse-Engineered Classes" for more information.

You can now further develop the model.

4.   Add External Components to a Model To top of page

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 application’s 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.

5.   Packaging and Diagramming Reverse-Engineered Classes To top of page

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:

  1. Open the Class diagram where you want to add the classes. Make certain it is the active diagram.
  2. From the Query menu, select Add Classes.
  3. From the Package drop-down, select the package that currently holds your classes.
  4. From the Classes window, select the classes you want to move, and transfer them to the Selected Classes window.
  5. 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:

  1. Drag-and-drop the class from the Reverse Engineered package to the one you want it in.
  2. 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.
  3. 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.
  4. Cut or Copy, then Paste the class from the Reverse Engineered package to the one you want it in.
 

Display Rational Unified Process using frames

 

© Rational Software Corporation 1998 Rational Unified Process 5.1 (build 43)