当前页面: 开发资料首页 → 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
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.
- Create a directory on your file system named UMLTut and unzip the BankApp.zip file into the directory.
- From the main menu, choose File > Open Project.
- Browse to the UMLTut directory that you just created and select the BankApp project.
- 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.
- From the main menu, choose File > New Project and then do the following in the New Project wizard:
- Under Categories, select UML.
- Under Projects, select Java-Platform Model by Reverse-Engineering a Java Project.
- Click Next.
- In the Project Name field, type UMLProject.
- For the Project Location field, click Browse to navigate to, select the UMLTut folder, and click Open.
- In the Java Project field, select BankApp from the drop-down list.
- Leave the checkboxes in the Reverse Engineer column selected.
- 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.
- In the Projects window, under the UMLProject node, expand the Model node and expand the bankpack node under it.
- 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.
- Right-click the selected elements and choose Create Diagram From Selected Elements from the pop-up menu.
The Create New Diagram wizard appears.
- In the Diagram Type list, select Class Diagram.
- 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.
- In the Projects window, expand the UML Project > Model > bankpack node.
- 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.
- Select the Attribute node
labeled private double balance.
The Properties window shows the name of the attribute and its properties.
- In the Projects window, under the node for the BankAccount class, expand the Operations node
.
All the operations on the BankAccount class appear under this node.
- Under the BankAccount class, expand the Relationships node
.
Nodes for three types of relationships are displayed: Specializations, Aggregation, and Implementation.
- Expand the Specializations node
, then expand the three Generalization nodes.
The Generalization links show the relationship between BankAccount class to other elements (the Checking, Platinum, and Saving classes).
- (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.
- 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.
- Stay in the expanded Diagram editor and click the Fit To Window button
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.
- Select the Symmetric Layout
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.
- Select the Hierarchical Layout
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.
- Select the Orthogonal Layout
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.
- Double-click the BankClassDiagram tab at the top of the expanded Diagram editor.
The IDE returns to the multi-window view.
- Select 50% from the zoom drop-down list and then click the Fit to Window button
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.
- Click the Overview Window button
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.
- Drag the blue box over the BankAccount element.
This focuses the BankAccount element in the center of the Diagram editor.
- 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.
- 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.
- Close the Overview window by clicking the X in the upper right corner or by clicking the Overview Window button a second time.
- Click the Fit to Window button
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.
- Double-click the BankClassDiagram tab to switch to the full view of the diagram.
- 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.
- Double-click the BankClassDiagram tab again to switch to the multi-window view of the IDE.
- In the Projects window, expand the BankAccount class node under the UMLProject > Model > bankpack folder.
You see that a BankAccountDependencies node
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
- Click the BankAccountDependencies tab in the Diagram editor.
- Select BankAccount element and adjust the zoom so that you can easily read the operation labels.
- 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.
- In the Diagram Type list, select Sequence Diagram.
- In the Diagram Name field, type withdrawSD.
- Accept the default value in the Namespace field and click Finish.
A sequence diagram appears in the Diagram editor.
- 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.
- 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
.
- 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:
- Generate a class diagram from the imported Java application
- Explore the features of the Projects window for representing the elements of the application
- Use the buttons of the Diagram toolbar to view the application in various UML layouts
- Use the Overview Window as a viewing tool
- Generate a dependency diagram for one of the application's classes
- Generate a sequence diagram for an operation and examine how it was represented as a diagram and as elements in the UML Project in the Projects window
top
↑返回目录
前一篇:
Remove Duplicate and Unused Entries From Your Property Files
后一篇:
Running the Amazon E-Commerce Service Sample Application In NetBeans