UML: Reverse Engineering Java Applications

Contributed by Cindy Castillo and maintained by Bob May
November 2007
[Revision number: V1-3]
This publication is applicable to NetBeans IDE 6.0 release

In this tutorial, you learn how to reverse engineer the source code of an existing Java application into a UML project. In the UML project all the classes and other application elements are represented in the Projects window under the UML project node, while the original Java code remains in its original state. This document walks you through several basic tasks as indicated by the topic links listed under Contents. .

Expected duration:25 minutes

Contents

  Content on this page applies to NetBeans IDE 6.0

Tutorial Requirements

Prerequisites

To use this tutorial, the IDE must be installed on your system and you should be familiar with the basic parts of the IDE. You should also have a basic familiarity with the Java programming language and UML. For a basic understanding of the IDE, see the IDE Basics topics in the online help. A good resource for UML techniques and theory is the official UML resource page at http://www.uml.org/

System Requirements

This tutorial assumes that your system meets the requirements specified in the Systems Requirements section of the NetBeans 6.0 Release Notes.

Software Needed for This Tutorial

Before you begin, download and install the following software:

Opening the Java Project

In this section, you use the New Project wizard to create the sample Java project and UML project provided with the IDE.

  1. From the main menu of the IDE, choose File > New Project.
    The New Project wizard appears.
  2. In the Choose Project page, expand the Samples node in the Categories pane and select the UML node.
    The Projects pane is updated with the available UML sample project.
  3. In the Projects pane, select the UML Bank App Sample and click Next.
  4. In the Name and Location page, leave the default value of UMLBankAppSample for the Java project name.
  5. For the Projects Location field, click Browse to navigate to the folder in which you want to save the files for the sample projects.
    Notice that when you change the value in the Projects Location field, the IDE automatically updates the values in the Java Project Folder and UML Project Folder fields.
  6. Leave the default value of UMLBankAppSample-Model for the UML project name.
  7. Click Finish.
    The Opening Projects progress dialog box appears.
    The UMLBankAppSample and UMLBankAppSample-Model projects appears in the Projects window.

 View Demo

top

Creating a UML Project by Reverse Engineering

This section steps you through the different parts of the UMLBankAppSample application by exploring the different features of the Projects window that represent the elements of the application.

  1. From the main menu, select Windows > Properties to open the Properties window.
  2. In the Projects window, expand the UMLBankAppSample-Model> Model > bankpack node.
  3. Expand the BankAccount node and its Attributes node.
    All attributes of the BankAccount class are contained in this folder. If there are less than three attributes, the attributes appear under the class node without an Attributes folder.
  4. Select the Attribute node image of Attributes node icon labeled private double balance.
    The Properties window shows the name of the attribute and its properties.
  5. In the Projects window, under the node for the BankAccount class, expand the Operations node image of the Operations node icon is displayed. .
    All the operations on the BankAccount class appear under this node.
  6. Under the BankAccount class, expand the Relationships node image of the Relationships node icon is displayed..
    Nodes for three types of relationships are displayed: Specializations, Aggregation, and Implementation.
  7. Expand the Specializations node image of the Generalization icon is displayed., then expand the three Generalization nodes.
    The Generalization links show the relationship between BankAccount class to other elements (the Checking, Platinum, and Saving classes).
  8. (Optional) Before continuing to the next section, close the expanded nodes under the BankAccount class.

 View Demo

top

Generating a Class Diagram

In this section, you generate the class diagrams for the BankApp application you imported in the previous section.

  1. In the Projects window, under the UMLProject node, expand the Model node and expand the bankpack node under it.
  2. Select the bankpack folder and all the elements under the bankpack folder by holding down the Shift-key or Ctrl-key when making the selection.
  3. Right-click the selected elements and choose Create Diagram From Selected Elements from the pop-up menu.
    The Create New Diagram wizard appears.
  4. In the Diagram Type list, select Class Diagram.
  5. Type BankClassDiagram in the Diagram Name field, leave UMLProject in the Namespace field and click Finish.
    The IDE does the following:
    • Creates a BankClassDiagram node under the Model node
    • Displays the new diagram in the Diagram editor
    • Opens the Modeling Palette
    Note: The new BankClassDiagram diagram consists of all the elements you selected in Step 2 .

 View Demo

top

Exploring the UML Project in the Projects Window

This section steps you through the different parts of the BankApp application by exploring the different features of the Projects window that represent the elements of the application.

  1. In the Projects window, expand the UMLProject > Model > bankpack node.
  2. Expand the BankAccount node and its Attributes node.
    All attributes of the BankAccount class are contained in this folder. If there are less than three attributes, the attributes appear under the class node without an Attributes folder.
  3. Select the Attribute node image of Attributes node icon labeled private double balance.
    The Properties window shows the name of the attribute and its properties.
  4. In the Projects window, under the node for the BankAccount class, expand the Operations node image of the Operations node icon is displayed. .
    All the operations on the BankAccount class appear under this node.
  5. Under the BankAccount class, expand the Relationships node image of the Relationships node icon is displayed..
    Nodes for three types of relationships are displayed: Specializations, Aggregation, and Implementation.
  6. Expand the Specializations node image of the Generalization icon is displayed., then expand the three Generalization nodes.
    The Generalization links show the relationship between BankAccount class to other elements (the Checking, Platinum, and Saving classes).
  7. (Optional) Before continuing to the next section, close the expanded nodes under the BankAccount class.

 View Demo

top

Exploring the Diagram Editor

In this section, you use the buttons of the Diagram toolbar to view the application in various UML layouts in the Diagram editor.

  1. Double-click the BankClassDiagram tab at the top of the Diagram editor.
    This action stretches the class Diagram editor to fill the entire IDE window space.

    Note: This is a toggle: To reverse this action double-click the BankClassDiagram tab again.
  2. Stay in the expanded Diagram editor and click the Fit To Window button image of the FitToWindow icon is displayed. on the Diagram toolbar to display the diagram completely in the expanded editor.

    Note: Notice the zoom level percentage field in the Diagram toolbar. You can manipulate the size by typing different numbers in this field.
  3. Select the Symmetric Layout image of the Tree Style icon is displayed. button on the Diagram toolbar and click Yes in the Layout warning dialog box.
    The IDE arranges the BankClassDiagram diagram into a symmetric layout style.
  4. Select the Hierarchical Layout image of the Hierarchical Style tool icon is displayed. button on the Diagram toolbar and click Yes in the Layout warning dialog box.
    The IDE rearranges the BankClassDiagram diagram into a hierarchical layout style with all elements below the bankpack package.
  5. Select the Orthogonal Layout image of the Orthogonal Style icon is displayed. button on the Diagram toolbar and click Yes in the Layout warning dialog box.
    The IDE rearranges the BankClassDiagram diagram into a rectangular layout style.

 View Demo

top


Using the Overview Window

Here, use the features of the Overview window to get a scalable view of the diagram in the Diagram editor.

  1. Double-click the BankClassDiagram tab at the top of the expanded Diagram editor.
    The IDE returns to the multi-window view.
  2. Select 50% from the zoom drop-down list and then click the Fit to Window button image of the FitToWindow icon is displayed. on the Diagram toolbar.
    Using the Fit to Window button, the diagram scales from the 75% sized version so that you can read the labels better.
  3. Click the Overview Window button image of the Overview Window icon is displayed. on the Diagram toolbar to open the Overview window.
    A small, scalable window displaying the entire diagram appears. A blue box in the window indicates what appears in the Diagram editor.
    Note: You may need to enlarge the Overview window or select a higher scale in the zoom drop-down list to see the blue box.
  4. Drag the blue box over the BankAccount element.
    This focuses the BankAccount element in the center of the Diagram editor.
  5. To zoom in on an element, click one of the handles at the corner of the blue box and decrease the size of the box. Adjust the location of the box to zoom in on a specific part of the diagram.
  6. To zoom out, click one of the handles of the blue box and increase the box's size.
    Notice that the IDE zooms out on the diagram.
  7. Close the Overview window by clicking the X in the upper right corner or by clicking the Overview Window button a second time.
  8. Click the Fit to Window button image of the FitToWindow icon is displayed. again on the Diagram toolbar

 View Demo

top

Generating a Dependency Diagram for a Class

Now, generate a dependency diagram for one of the classes in the BankApp application.

  1. Double-click the BankClassDiagram tab to switch to the full view of the diagram.
  2. Right-click the BankAccount class in the Diagram editor and choose Generate Dependency Diagram from the pop-up menu.
    The IDE creates a dependency diagram and opens a BankAccountDependencies tab in the Diagram editor to display the new diagram. Your focus is now in the Diagram editor tab showing the BankAccountDependencies diagram. The BankAccountDependencies diagram shows the following dependency links:
    • Implementation relationship with the Account interface
    • Navigable Aggregation link to the History class
    Note: Using this option, you can create a diagram showing all the dependencies for any given object.
  3. Double-click the BankClassDiagram tab again to switch to the multi-window view of the IDE.
  4. In the Projects window, expand the BankAccount class node under the UMLProject > Model > bankpack folder.
    You see that a BankAccountDependencies node image of the BankAccountDependencies node icon is displayed. has been added representing the Dependency diagram you just created.

 

 View Demo

top

Generating a Sequence Diagram for an Operation

Now generate a sequence diagram for the application's withdraw operation. Examine how it is represented as a diagram and as elements in the UML Project in the Projects window

  1. Click the BankAccountDependencies tab in the Diagram editor.
  2. Select BankAccount element and adjust the zoom so that you can easily read the operation labels.
  3. In the Diagram editor, right-click the withdraw operation and choose Reverse Engineer Operation from the pop-up menu.
    The Create New Diagram dialog box appears.
  4. In the Diagram Type list, select Sequence Diagram.
  5. In the Diagram Name field, type withdrawSD.
  6. Accept the default value in the Namespace field and click Finish.
    A sequence diagram appears in the Diagram editor.
  7. Expand the Diagram editor and manipulate the zoom level so that you can easily examine the new sequence diagram.
    The sequence diagram shows the control flow, the sequence of behavior, and the concurrent processes and activations.
  8. In the Projects windows, under the BankAccount class node, expand the Operations node, then expand the public void withdraw operation node.
    You see the new withdraw sequence diagram node image of the sequence diagram node..
  9. Expand the withdraw node to see the elements of the sequence diagram represented in the Projects window.

 View Demo

top

A Note on Merge Markers

UML uses merge markers to assist you in keeping your source and model synchronized.  The IDE adds merge markers by default when you invoke the Code Generation action from your UML project.  If the UML project was created by your reverse engineering an existing Java project, there are no merge markers for your existing source elements.

To add merge markers:

  1. Create or open your Java project.
  2. Right click on the Java project node and select Reverse Engineer . Verify that Create New UML Project is selected.  Click OK.
  3. Ensure the reverse engineering to complete.  The output window displays Task Successful.
  4. Right-click on the newly created UML project node -> Generate Code ...
  5. Select the Java project from the Target Project pull down list. Select the Add Merge Markers to Existing Source Elements. Click OK.

Your source and model are now synchronized and all source elements will have merge markers.  You can safely switch back and forth between the source and model.  Before each switch, however, you should invoke Reverse Engineer or Code Generation, as appropriate.

top

Summary

top

Next Steps


Send Us Your Feedback

top