Skip to main content

Reverse engineer UML diagrams by using IBM Rational Software Architect, Version 7.5

Si Yin (Si.Yin@nl.ibm.com), IT Consultant, IBM
Photo of Si Yin
Si Yin is an IT consultant at the IBM Center of Excellence in Water Management in Amsterdam, the Netherlands. He is a technical specialist for Water Management projects. Si graduated cum laude with an M.Sc. in computer science from Vrije Universiteit Amsterdam and was an Extreme Blue student in 2007.
Fenglian Xu (xufengli@uk.ibm.com), Software Developer, WebSphere Enterprise Service Bus Development team, IBM
Photo of Fenglian Xu
Dr. Fenglian Xu is a software developer for IBM WebSphere Service Registry and Repository at the IBM Hursley Software Lab in the UK. Before working in her current role, she was part of the IBM WebSphere Enterprise Service Bus development team, in which she gained expertise in Java Message Service (JMS) and WebSphere MQ JMS bindings, Service Gateway for WebSphere Enterprise Service Bus, and WebSphere Process Server. She also gained knowledge and experience about an integration with WebSphere Application Server and WebSphere MQ. Before Dr. Xu joined IBM, she worked for various IT companies, from middleware to applications, and with the UK eScience pilot project, GEODISE, for which she prototyped a workflow tool in service-oriented architecture. She received a B.Sc. in applied math and software engineering from Xian Jiaotong University in China in 1989 and a Ph.D. in computer science from the University of Southampton in the UK in 1998.

Summary:  In IBM® Rational® Software Architect, Version 7.5, you can reverse engineer code to analyze a Java™ project by creating inheritance trees that contain details of classes and their relationships as Unified Modeling Language (UML) diagrams. This article explains the steps to use reverse engineering on a small Java project.

Date:  13 Aug 2009
Level:  Intermediate PDF:  A4 and Letter (759KB | 15 pages)Get Adobe® Reader®
Activity:  3609 views
Comments:  

Create an inheritance tree of classes by using Software Analyzer

In object-oriented programming languages, inheritance shows the common fields and methods among inherited classes within a family and displays the specific fields and methods for each class. Developers and architects can use inheritance trees of the classes in a Java™ project to understand the relationships among the classes in the project. Suppose that you have created or loaded a Java project in IBM® Rational® Software Architect 7.5. To create an inheritance tree in the project:

  1. Open the Software Analyzer in Rational Software Architect V7.5 by selecting Run > Analysis (see Figure 1). You can use the Software Analyzer to generate reports that are based on rules that you select. Rational Software Architect V7.5 includes rules in the domains of Java Architectural Discovery, Code Review, UML Model Metrics, and UML Model. Creating an inheritance tree is a rule in the Java Architectural Discovery domain.

Figure 1. Open the Software Analyzer
Drop-down menu to open the Software Analyzer.

  1. Create a configuration:
    1. In the Name field, type a name.
    2. In the Analysis Domains and Rules area, expand the Object-oriented Patterns category and select the Inheritance Tree check box (see Figure 2).

Figure 2. Create an inheritance tree
the Software Analyzer window

Click here for a larger view of Figure 2.

    1. Click Analyze. An inheritance tree is displayed (see Figure 3). This inheritance tree shows that a Vehicle class has three children: Bicycle, Car, and PogoStick. The Car class has two children: FamilyCar and SportsCar. There is no information about class fields and methods in the inheritance tree. To explore the fields and methods of the classes, use a browse diagram.

Figure 3. The inheritance tree is generated by Software Analyzer
Screen capture of the inheritance tree, as described.

Click here for a larger view of Figure 3.


Explore the details of the inheritance tree by using a browse diagram

The inheritance tree that you created with the Software Analyzer does not contain details about the fields and methods of the classes. To find out about the details of each class within a certain scope, use a browse diagram. The scope can be a Java package, a project, a work set, or a workspace. For example, use the FamilyCar class as a starting point to explore its details with a browse diagram:

  1. To open a browse diagram, right-click on the FamilyCar.java class name and then select Visualize > Explore in Browse Diagram (Figure 4).

Figure 4. Explore the FamilyCar class in the browse diagram
An image of the steps to open a browse diagram.

  1. In the Browse Diagram window, on the relationship toolbar, click the Extends button (see Figure 5). The relationship toolbar contains five types of relationships:
    • arrow iconExtends: Explores the classes from which FamilyCar is extended
    • arrow iconDependency: Explores the classes that are used in the methods of the FamilyCar class
    • arrow iconRealization: Explores the interface that is implemented by FamilyCar
    • arrow iconAssociation: Explores the classes that are related to FamilyCar
    • magnifying glass iconDeclares: Explores declared packages in the FamilyCar class
    • Degree of separation: Explores the level of extension that the relationship applies

Figure 5. A browse diagram of the FamilyCar class with one degree of separation
An image of the class in a browse diagram

  1. Next to the relationship toolbar is a degree of separation, which indicates the number of relationship levels from the FamilyCar class that are shown in the diagram. In Figure 5, the value of 1 (one) indicates that the diagram shows the FamilyCar class only. When you apply the value of 2, the diagram shows the FamilyCar, Car, and Vehicle classes (see Figure 6).

Figure 6. The FamilyCar class in a browse diagram with 2 degrees of separation
An image of the browse diagram, as described.

The browse diagram of the inheritance tree is a temporary diagram that you cannot save. Typically, you use browse diagrams to explore a given class or to document the design of a project.


Generate an inheritance tree by using a topic diagram

The previous example showed how to use a browse diagram to visualize the inheritance tree of a class. In certain circumstances, you might want to create a diagram which consistently represents all of the inherited classes of the FamilyCar class during the development of the program. In this case, you can use a topic diagram to represent the inheritance tree of a given class. Unlike a browse diagram, you can save a topic diagram in a model file for a reuse.

To create an inheritance tree of a class in a topic diagram:

  1. Open a topic diagram of a given class, such as FamilyCar, by right-clicking the FamilyCar.java class and then selecting Visualize > Add to New Diagram File > Topic Diagram (see Figure 7).

Figure 7. Open the FamilyCar class in a topic diagram
Drop-down menu selections to open a topic diagram

  1. Generate a topic diagram:
    1. Select a topic, such as Inherited Java Classes (N levels)
    2. Specify the related elements to be shown. In this example, the Extend relation is selected with indefinite expansion on both incoming and outgoing directions to represent the whole inheritance tree.
    3. Click Finish. The result is shown on the right of Figure 8.

To respond to changes in Java source code, update the diagram by right-clicking the topic diagram workspace and clicking Refresh.


Figure 8. Create an inheritance tree by using a topic diagram
3 screen captures show creating inheritance tree

Click here for a larger view of Figure 8.

Integrate a generated class diagram into a model file by using Harvest

In Rational Software Architect, you can transform a model file into Java code. You might create a model file by creating a new class with some attributes and methods; you might also want to integrate existing Java classes from a project into the model file. To use the Harvest function in Rational Software Architect to copy a generated class diagram into your model file:

  1. Create a blank model file by clicking File > New item. A new wizard window opens (see Figure 9).

Figure 9. Open the Model wizard
The New window in Rational Software Architect

  1. Click Next and follow the workflow in Figure 10, which shows a freedom diagram.

Figure 10: Create a model file
3 screen caputres: how to create a model file

Click here for a larger view of Figure 10.

  1. Copy the class diagrams into the new model file by using the Harvest function:
    1. Select all of the classes in the diagram (see Figure 11).
    2. Right-click the diagram, and then click Harvest.

Figure 11. Harvest the selected classes in the browse diagram
Harvest feature selected in drop-down menu

    1. Paste the classes into the new model file (Figure 11 shows the result).

In Figure 11, neither the Vehicle nor Car classes show fields and methods information. To make the fields and methods visible, select one or more classes in the diagram, right-click the class or classes, and click Filters > Show/Hide Compartment > All Compartments (see Figure 12). To view the final results of enabling the compartments, see Figure 13.


Figure 12. Show all of the compartments of the Vehicle class
Drop-down menus to select  compartments of a class

Click here for a larger view of Figure 12.


Figure 13. The compartments of the Vehicle class
All of the compartments of the class are visible.


Summary

To analyze and expand Java projects, you can use the tools in Rational Software Architect, Version 7.5 for these actions:

  • To generate an inheritance tree for all of the classes in a project, use the Software Analyzer.
  • To visualize the details of a class that is part of an inheritance tree, use a browse diagram.
  • To use a fixed query to monitor code changes, use a topic diagram.
  • To paste a class from an inheritance tree into a model file, use the Harvest function.

Resources

Learn

Get products and technologies

Discuss

About the authors

Photo of Si Yin

Si Yin is an IT consultant at the IBM Center of Excellence in Water Management in Amsterdam, the Netherlands. He is a technical specialist for Water Management projects. Si graduated cum laude with an M.Sc. in computer science from Vrije Universiteit Amsterdam and was an Extreme Blue student in 2007.

Photo of Fenglian Xu

Dr. Fenglian Xu is a software developer for IBM WebSphere Service Registry and Repository at the IBM Hursley Software Lab in the UK. Before working in her current role, she was part of the IBM WebSphere Enterprise Service Bus development team, in which she gained expertise in Java Message Service (JMS) and WebSphere MQ JMS bindings, Service Gateway for WebSphere Enterprise Service Bus, and WebSphere Process Server. She also gained knowledge and experience about an integration with WebSphere Application Server and WebSphere MQ. Before Dr. Xu joined IBM, she worked for various IT companies, from middleware to applications, and with the UK eScience pilot project, GEODISE, for which she prototyped a workflow tool in service-oriented architecture. She received a B.Sc. in applied math and software engineering from Xian Jiaotong University in China in 1989 and a Ph.D. in computer science from the University of Southampton in the UK in 1998.

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=419386
ArticleTitle=Reverse engineer UML diagrams by using IBM Rational Software Architect, Version 7.5
publish-date=08132009
author1-email=Si.Yin@nl.ibm.com
author1-email-cc=
author2-email=xufengli@uk.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers