站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题Reverse Engineering Java Applications

Reverse Engineering Java Applications

摘要: This tutorial applies to NetBeans? 5.5 integrated development environment (the IDE) and the NetBeans 5.5, UML Modeling Beta module.

In this tutorial, you learn how to reverse engineer the source code of an existing Java application into a UML Modeling 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.

For more information about working with NetBeans IDE, see the Support and Docs page on the NetBeans web site.

Note: Wherever you see the View Demo icon, you can click to view a detailed interactive demonstration of the steps described in the tutorial.

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 modeling. For a basic understanding of the IDE, see the IDE Basics topics in the online help. A good resource for UML modeling 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 NetBeans IDE 5.5 Release Notes.

Software Needed for the Tutorial

Before you begin, you need to install the following software on your computer:

Contents

top


Opening the Java Project

In this section, you open the BankApp Java application provided with this tutorial as a project in the IDE.

  1. Create a directory on your file system named UMLTut and unzip the BankApp.zip file into the directory.
  2. From the main menu, choose File > Open Project.
  3. Browse to the UMLTut directory that you just created and select the BankApp project.
  4. Leave the checkbox Open as Main Project selected and click Open Project Folder.
    A progress dialog box appears and then a node for the BankApp project appears in the Projects window.

 View Demo

top


Creating a UML Project by Reverse Engineering

Now, create a new UML project by reverse engineering the BankApp Java project that you opened in the previous section.

  1. From the main menu, choose File > New Project and then do the following in the New Project wizard:
    1. Under Categories, select UML.
    2. Under Projects, select Java-Platform Model by Reverse-Engineering a Java Project.
    3. Click Next.
  2. In the Project Name field, type UMLProject.
  3. For the Project Location field, click Browse to navigate to, select the UMLTut folder, and click Open.
  4. In the Java Project field, select BankApp from the drop-down list.
  5. Leave the checkboxes in the Reverse Engineer column selected.
  6. Click Finish.
    The Opening Projects progress dialog box appears.
    The UMLProject project appears in the Projects window.

 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 UML Project > 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 50% 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


Summary

In this tutorial, you learned how to reverse engineer a Java application by importing its data into a UML model. You learned how to perform the following tasks:



top


↑返回目录
前一篇: Remove Duplicate and Unused Entries From Your Property Files
后一篇: Running the Amazon E-Commerce Service Sample Application In NetBeans