visualize with rational application developer · visualize with rational application developer ......

31
Visualize with Rational Application Developer A tour of Rational Application Developer's visual diagramming tools Skill Level: Intermediate Eric Long ([email protected]) Software Engineer IBM 07 Feb 2006 Rational Application Developer provides visual diagramming tools to help you gain insight and knowledge of existing applications or to more easily create and understand new applications. After completing this tutorial, you will know how to create class, sequence, browse, and topic diagrams. Section 1. Before you start Rational Application Developer provides diagrams which enable you to view code from different perspectives using UML 2.0 notation. These diagrams are referred to as UML visualization, not to be confused with UML Modeling. All UML visualizations in Rational Application Developer are synchronized with a source file. Modifications to the source file will dynamically change the diagram and vice versa. To create UML 2.0 models, you need to use Rational Software Modeler or Rational Software Architect. Stay tuned to developerworks for future tutorials covering the visual capabilities of both of those products. About this tutorial This tutorial introduces you to the process of creating UML and non-UML diagrams using Rational Application Developer. This tutorial demonstrates the following Visualize with Rational Application Developer © Copyright IBM Corporation 1994, 2007. All rights reserved. Page 1 of 31

Upload: hakhanh

Post on 24-Apr-2018

225 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Visualize with Rational Application DeveloperA tour of Rational Application Developer's visual diagrammingtools

Skill Level: Intermediate

Eric Long ([email protected])Software EngineerIBM

07 Feb 2006

Rational Application Developer provides visual diagramming tools to help you gaininsight and knowledge of existing applications or to more easily create and understandnew applications. After completing this tutorial, you will know how to create class,sequence, browse, and topic diagrams.

Section 1. Before you start

Rational Application Developer provides diagrams which enable you to view codefrom different perspectives using UML 2.0 notation. These diagrams are referred toas UML visualization, not to be confused with UML Modeling. All UML visualizationsin Rational Application Developer are synchronized with a source file. Modificationsto the source file will dynamically change the diagram and vice versa. To createUML 2.0 models, you need to use Rational Software Modeler or Rational SoftwareArchitect. Stay tuned to developerworks for future tutorials covering the visualcapabilities of both of those products.

About this tutorial

This tutorial introduces you to the process of creating UML and non-UML diagramsusing Rational Application Developer. This tutorial demonstrates the following

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 1 of 31

Page 2: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Rational Application Developer diagrams:

• Class diagrams

• Sequence diagrams

• Browse diagrams

• Topic diagrams

Note:Rational Application Developer can be used to diagram more than just Javaclasses in class diagrams. Database components can also be diagramed. However,this tutorial does not cover that. For more information on diagramming databasecomponents, see the Resources section.

This tutorial is written for developers who are interested in learning about RationalApplication Developer's visualization capabilities.

Objectives

After completing this tutorial, you will know how to use Rational ApplicationDeveloper to create class, sequence, browse, and topic diagrams.

Prerequisites

This tutorials assumes that you have a solid understanding of Java programming.Knowledge of UML 2.0 diagrams is helpful, but not required.

System requirements

To run the examples as demonstrated in this tutorial, you need to have RationalApplication Developer installed on your machine.

If you don't already have a copy of Rational Application Developer, you candownload a free trial version. All of the prerequisites for Rational ApplicationDeveloper are located in the Resources section of this tutorial.

Section 2. Create a Java project and package

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 2 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 3: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

To get started with this tutorial, you need to do some initial set up. First, create aJava project to hold all of the different elements you will be creating (i.e. packages,Java classes, diagrams, etc.).

Create a Java project

Creating a Java project is very easy:

1. Open Rational Application Developer.

2. To open the Java perspective, from the Window menu, select OpenPerspective > Java.

3. Make sure all of your open projects are closed.

4. From the File menu, select New > Project.

5. Make sure the Show All Wizards box is checked.

6. Expand the Java folder.

7. Select Java Project.Figure 1. The New Project window

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 3 of 31

Page 4: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

8. Fill in the Create a Java project wizard as follows:

• Project Name: IBMPayroll

• Location: Create project in workspace.

• Project layout: Use project folder as root for sources and classfiles.

The wizard should look like this:Figure 2. The New Java Project window

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 4 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 5: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

9. Click Finish.

Now, create a package to house your Java classes.

Create a package

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 5 of 31

Page 6: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

1. In the Package Explorer view, right-click the newly created IBMPayrollproject.

2. Select New > Package.Figure 3. New Package

3. In the New Java Package window, name the package com.ibm.common.

4. Click Finish.

5. The Package Explorer should now look like this:Figure 4. Package Explorer view

Now on to the more exciting part of the tutorial. Let's move on to UML classdiagrams.

Section 3. Create and edit a UML class diagram

This section of the tutorial covers the creation and population of a UML classdiagram.

Create a Java class diagram

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 6 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 7: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

1. In the Package Explorer view, right-click the IBMPayroll project.

2. Select New > Class Diagram.

3. Fill in the Create Class Diagram window as follows:

• Enter or select IBMPayroll/com/ibm/common as the parent folder.

• Name the file IBMPayrollDiagram.The window should look like this:Figure 5. New Class Diagram window

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 7 of 31

Page 8: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 8 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 9: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

4. Click Finish.

5. From the Palette (right side of editor), click the

Class button, then click anywhere in the class diagram editor.

6. Fill in the New Java Class window as follows:

• Source Folder: IBMPayroll.

• Package: com.ibm.common.

• Name: Zipcode.

• Make sure the bottom three check boxes are checked.The New Java Class window should look like this:Figure 6. New Java Class window

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 9 of 31

Page 10: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

7. Click Finish. The diagram editor should now show a UML visualization ofa Java class. Note that this is NOT a UML 2.0 model. It is arepresentation of the Java code using UML 2.0 notation.Figure 7. Zipcode UML representation

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 10 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 11: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

8. Create two additional classes in the com.ibm.common package:PhoneNumber and Employee.

9. From the Palette view, click the Association button .

10. Drag-and-drop from the Employee class to the Zipcode class.

11. Fill in the Create Association window as follows:

• Name the association zipcode.

• Leave the remaining options as default.

• Click Finish.Figure 8. Create Association window

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 11 of 31

Page 12: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

12. Repeat the same steps for an association between Employee andPhoneNumber.

13. Name the association phoneNumber.

14. Arrange the classes in the diagram editor to look like this:Figure 9. Class diagram after adding three classes

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 12 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 13: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

15. Double-click any of the newly created Java classes in the diagram editorto look at its source file.

16. Examine the automatically generated source files.

Edit a Java class diagram

In this section, the Zipcode and PhoneNumber classes are edited using RationalApplication Developer visual tools. Add a field to the PhoneNumber class and a fieldand method to the Zipcode class.

1. In the Package Explorer view, double-click IBMPayrollDiagram.dnx inthe IBMPayroll project.

2. In the editor, right-click the PhoneNumber class.

3. Select Add Java > Field....Figure 10. Add Java Field

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 13 of 31

Page 14: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

4. Fill in the Create Java Field window as follows:

• Name: theNumber

• Type: java.lang.String

• Visibility: privateThe window should look like this:Figure 11. Create Java Field window

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 14 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 15: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

5. Click Finish.

6. Repeat the same steps to add a field to the Zipcode class.

7. Fill in the Create Java Field window as follows:

• Name: theCode

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 15 of 31

Page 16: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

• Type: java.lang.String

• Visibility: private

• Click Finish.

8. In the editor, right-click the Zipcode class.

9. Select Add Java > Method....Figure 12. Add Java method

10. Fill in the Create a Java Method window as follows:

• Name: isZipcode

• Type: boolean

• Visibility: public

• In the Parameters section, click Add.

• Name the Parameter code and the type java.lang.String.Figure 13. Create parameter

11. Click OK.

12. The Create Java Method window should look like this:

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 16 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 17: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Figure 14. Create Java Method window

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 17 of 31

Page 18: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 18 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 19: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

13. Click Finish. In the Package Explorer view you should see an error in theZipcode class now, that's OK.

14. Double-click the Zipcode class in the diagram editor to open the sourcefile.

15. Replace the isZipcode() method with the following code:Listing 1. isZipcode()

public boolean isZipcode(String code) {boolean isValid = true;try {int length = code.length();if ((length != 5) && (length != 10)) {

isValid = false;}

for (int i = 0; i < length; i++) {char c = code.charAt(i);if ((length == 10) && (i == 5) &&) (c != '-')) {

isValid = false;} else if ((c < '0') || (c > '9')) {

isValid = false;}

}} catch (Exception e) {

System.out.println("Error in isZipcode()" + e);} finally {

if (isValid == false)return false;

}return isValid;

}

16. Be sure to save all of your projects now (CTRL + SHIFT + S) or File >Save All. Notice the error is now gone.

17. In the Package Explorer view, right-click the Employee class.

18. Select Source > Generate Getters and Setters...Figure 15. Generate Getters and Setters

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 19 of 31

Page 20: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

19. In the Generate Getters and Setters window, check phoneNumber andzipcode to generate both getters and setters.Figure 16. Generate Getters and Setters window

20. Repeat the same steps for the Zipcode class and the PhoneNumberclass.

21. Again, save all the new changes (CTRL + SHIFT + S) or File > Save All.

22. The diagram editor should now look like this:Figure 17. Final class diagram

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 20 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 21: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Section 4. Visualize a method using a sequence diagram

Now that a UML class diagram has been created, you are going to utilize anothervisualization capability that Rational Application Developer offers: sequencediagrams. A sequence diagram shows the sequence (in time) of messages, whichare exchanged among roles that implement the behavior of the system. This sectionof the tutorial guides you through the process of creating a sequence diagram usingRational Application Developer.Create a sequence diagram

1. From the Package Explorer view, expand the Zipcode class.Figure 18. Expanded Zipcode class

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 21 of 31

Page 22: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

2. Right-click the isZipcode(String) method and select Visualize > Add toNew Diagram File > Static Method Sequence Diagram.Figure 19. Select sequence diagram

3. The diagram is automatically created and opened (default name issequencediagram.tpx).

4. Explore the sequence diagram.Figure 20. Sequence diagram

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 22 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 23: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

5. For quick navigation around large diagrams, the Outline view allows youto quickly move the viewable area of the editor (this applies to all

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 23 of 31

Page 24: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

diagrams).Figure 21. Diagram outline view

Section 5. Create a topic diagram from existing code

A topic diagram is a non-editable diagram that provides a quick way to showrelationships between elements. They are useful to define a query and to display

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 24 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 25: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

and persist the results from that query. An example would be creating a hierarchytopic diagram that you can update to always show the hierarchy for a specific class.This section of the tutorial shows you how to use Rational Application Developer tocreate a topic diagram from existing code.Create a topic diagram

1. From the Package Explorer view, right-click the Employee class.Figure 22. Employee class

2. Select Visualize > Add New Diagram File > Topic Diagram...Figure 23. Select new topic diagram

3. Fill in the Topic Wizard window as follows:

• Parent Folder: IBMPayroll/com/ibm/common

• File name: EmployeeTopicDiagram

4. The wizard should now look like this:Figure 24. Topic Wizard

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 25 of 31

Page 26: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

5. Click Next.

6. Select Java Field Types as the topic.

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 26 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 27: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Figure 25. Topic Wizard

7. Use the defaults for the remaining pages, however feel free to explore theoptions.

8. Click Finish.

9. The finished browse diagram looks like this:Figure 26. Browse diagram

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 27 of 31

Page 28: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Section 6. Create a browse diagram

A browse diagram is a temporary, non-editable diagram that shows the results of aquery on a context diagram element in a model. Use browse diagrams to navigatethrough a model to view the details of its elements and relationships. For example,create a browse diagram to show a dynamic view of a class and its related elementsto understand how it fits into the model.Create a browse diagram

1. From the Package Explorer view, right-click the Employee class.Figure 27. Employee class

2. Select Visualize > Explore in Browse Diagram...Figure 28. Select Explore in Browse Diagram

3. The diagram is automatically created.

4. Click all of the buttons in the editor to explore all relationships to theEmployee class.Figure 29. Select all Relationships

5. Click Apply.

6. The final diagram looks like this:Figure 30. Final browse diagram

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 28 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 29: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Section 7. Conclusion

Congratulations! In this tutorial, you covered the creation of a class, sequence,browse, and topic diagram to create and visualize a single Java class. Visualdiagramming is far more useful when trying to understand and edit largerapplications. With the knowledge you've gained from this tutorial, you can easilymove on and apply the same skills to complex applications using RationalApplication Developer.

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 29 of 31

Page 30: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

developerWorks® ibm.com/developerWorks

Visualize with Rational Application DeveloperPage 30 of 31 © Copyright IBM Corporation 1994, 2007. All rights reserved.

Page 31: Visualize with Rational Application Developer · Visualize with Rational Application Developer ... Java project to hold all of the different elements you will be creating (i.e. packages,

Resources

Learn

• Get a guided tour of Rational tools available to help you visually design anddevelop software applications.

• Visit the developerWorks Rational zone to expand your Rational skills.

• Visual Data Modeling in Rational Application Developer 6.0 (developerWorks,June 2005) details the visual tools available to visualize data elements in RationalApplication Developer.

• Stay current with developerWorks technical events and webcasts.

Get products and technologies

• Download a free trial version of Rational Application Developer.

• Build your next development project with IBM trial software, available fordownload directly from developerWorks.

• Order the SEK for Rational, a two-DVD set containing the latest IBM trial softwarefor Linux® from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.

Discuss

• Participate in the discussion forum for this content.

• Participate in developerWorks blogs and get involved in the developerWorkscommunity.

About the author

Eric LongEric Long is a Software Engineer in the IBM Developer Skills Program. Eric graduatedfrom The University of Texas with a degree in Computer Science. He joined IBM inJuly of 2004 and currently works in Austin, Texas. As a Software Engineer, heprovides technical information to developers on open source and industry trends andtechnologies through speaking engagements, Web content, and faculty consultationsat IBM Academic Initiative member universities. His work also includes technicaldemos and content available at www.ibm.com/university.

ibm.com/developerWorks developerWorks®

Visualize with Rational Application Developer© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 31 of 31