- •Table of Contents
- •Mastering UML with Rational Rose 2002
- •Chapter 1: Introduction to UML
- •Encapsulation
- •Inheritance
- •Polymorphism
- •What Is Visual Modeling?
- •Systems of Graphical Notation
- •Booch Notation
- •Object Management Technology (OMT)
- •Unified Modeling Language (UML)
- •Understanding UML Diagrams
- •Business Use Case Diagrams
- •Use Case Diagrams
- •Activity Diagrams
- •Sequence Diagrams
- •Collaboration Diagrams
- •Class Diagrams
- •Statechart Diagrams
- •Component Diagrams
- •Deployment Diagrams
- •Visual Modeling and the Software Development Process
- •Inception
- •Elaboration
- •Construction
- •Transition
- •Summary
- •Chapter 2: A Tour of Rose
- •What Is Rose?
- •Getting Around in Rose
- •Parts of the Screen
- •Exploring Four Views in a Rose Model
- •Use Case View
- •Logical View
- •Component View
- •Deployment View
- •Working with Rose
- •Creating Models
- •Saving Models
- •Exporting and Importing Models
- •Publishing Models to the Web
- •Working with Controlled Units
- •Using the Model Integrator
- •Working with Notes
- •Working with Packages
- •Adding Files and URLs to Rose Model Elements
- •Adding and Deleting Diagrams
- •Setting Global Options
- •Working with Fonts
- •Working with Colors
- •Summary
- •Chapter 3: Business Modeling
- •Introduction to Business Modeling
- •Why Model the Business?
- •Do I Need to Do Business Modeling?
- •Business Modeling in an Iterative Process
- •Business Actors
- •Business Workers
- •Business Use Cases
- •Business Use Case Diagrams
- •Activity Diagrams
- •Business Entities
- •Organization Unit
- •Where Do I Start?
- •Identifying the Business Actors
- •Identifying the Business Workers
- •Identifying the Business Use Cases
- •Showing the Interactions
- •Documenting the Details
- •Creating Business Use Case Diagrams
- •Deleting Business Use Case Diagrams
- •The Use Case Diagram Toolbar
- •Adding Business Use Cases
- •Business Use Case Specifications
- •Assigning a Priority to a Business Use Case
- •Viewing Diagrams for a Business Use Case
- •Viewing Relationships for a Business Use Case
- •Working with Business Actors
- •Adding Business Actors
- •Adding Actor Specifications
- •Assigning an Actor Stereotype
- •Setting Business Actor Multiplicity
- •Viewing Relationships for a Business Actor
- •Working with Relationships
- •Association Relationship
- •Generalization Relationship
- •Working with Organization Units
- •Adding Organization Units
- •Deleting Organization Units
- •Activity Diagrams
- •Adding an Activity Diagram
- •Adding Details to an Activity Diagram
- •Summary
- •Chapter 4: Use Cases and Actors
- •Use Case Modeling Concepts
- •Actors
- •Use Cases
- •Traceability
- •Flow of Events
- •Relationships
- •Use Case Diagrams
- •Activity Diagrams
- •Activity
- •Start and End States
- •Objects and Object Flows
- •Transitions
- •Synchronization
- •Working with Use Cases in Rational Rose
- •The Use Case Diagram Toolbar
- •Creating Use Case Diagrams
- •Deleting Use Case Diagrams
- •Adding Use Cases
- •Deleting Use Cases
- •Use Case Specifications
- •Naming a Use Case
- •Viewing Participants of a Use Case
- •Assigning a Use Case Stereotype
- •Assigning a Priority to a Use Case
- •Creating an Abstract Use Case
- •Viewing Diagrams for a Use Case
- •Viewing Relationships for a Use Case
- •Working with Actors
- •Adding Actors
- •Deleting Actors
- •Actor Specifications
- •Naming Actors
- •Assigning an Actor Stereotype
- •Setting Actor Multiplicity
- •Creating an Abstract Actor
- •Viewing Relationships for an Actor
- •Viewing an Actor's Instances
- •Working with Relationships
- •Association Relationship
- •Includes Relationship
- •Extends Relationship
- •Generalization Relationship
- •Working with Activity Diagrams
- •The Activity Diagram Toolbar
- •Creating Activity Diagrams
- •Deleting Activity Diagrams
- •Exercise
- •Problem Statement
- •Create a Use Case Diagram
- •Summary
- •Chapter 5: Object Interaction
- •Interaction Diagrams
- •What Is an Object?
- •What Is a Class?
- •Where Do I Start?
- •Finding Objects
- •Finding the Actor
- •Using Interaction Diagrams
- •Sequence Diagrams
- •The Sequence Diagram Toolbar
- •Collaboration Diagrams
- •The Collaboration Diagram Toolbar
- •Working with Actors on an Interaction Diagram
- •Working with Objects
- •Adding Objects to an Interaction Diagram
- •Deleting Objects from an Interaction Diagram
- •Setting Object Specifications
- •Naming an Object
- •Mapping an Object to a Class
- •Setting Object Persistence
- •Using Multiple Instances of an Object
- •Working with Messages
- •Adding Messages to an Interaction Diagram
- •Adding Messages to a Sequence Diagram
- •Deleting Messages from a Sequence Diagram
- •Reordering Messages in a Sequence Diagram
- •Message Numbering in a Sequence Diagram
- •Viewing the Focus of Control in a Sequence Diagram
- •Adding Messages to a Collaboration Diagram
- •Deleting Messages from a Collaboration Diagram
- •Message Numbering in a Collaboration Diagram
- •Adding Data Flows to a Collaboration Diagram
- •Setting Message Specifications
- •Naming a Message
- •Mapping a Message to an Operation
- •Setting Message Synchronization Options
- •Setting Message Frequency
- •End of a Lifeline
- •Working with Scripts
- •Switching Between Sequence and Collaboration Diagrams
- •Exercise
- •Problem Statement
- •Create Interaction Diagrams
- •Summary
- •Chapter 6: Classes and Packages
- •Logical View of a Rose Model
- •Class Diagrams
- •What Is a Class?
- •Finding Classes
- •Creating Class Diagrams
- •Deleting Class Diagrams
- •Organizing Items on a Class Diagram
- •Using the Class Diagram Toolbar
- •Working with Classes
- •Adding Classes
- •Class Stereotypes
- •Analysis Stereotypes
- •Class Types
- •Interfaces
- •Web Modeling Stereotypes
- •Other Language Stereotypes
- •Class Specifications
- •Naming a Class
- •Setting Class Visibility
- •Setting Class Multiplicity
- •Setting Storage Requirements for a Class
- •Setting Class Persistence
- •Setting Class Concurrency
- •Creating an Abstract Class
- •Viewing Class Attributes
- •Viewing Class Operations
- •Viewing Class Relationships
- •Using Nested Classes
- •Viewing the Interaction Diagrams That Contain a Class
- •Setting Java Class Specifications
- •Setting CORBA Class Specifications
- •Working with Packages
- •Adding Packages
- •Deleting Packages
- •Exercise
- •Problem Statement
- •Creating a Class Diagram
- •Summary
- •Chapter 7: Attributes and Operations
- •Working with Attributes
- •Finding Attributes
- •Adding Attributes
- •Deleting Attributes
- •Setting Attribute Specifications
- •Setting the Attribute Containment
- •Making an Attribute Static
- •Specifying a Derived Attribute
- •Working with Operations
- •Finding Operations
- •Adding Operations
- •Deleting Operations
- •Setting Operation Specifications
- •Adding Arguments to an Operation
- •Specifying the Operation Protocol
- •Specifying the Operation Qualifications
- •Specifying the Operation Exceptions
- •Specifying the Operation Size
- •Specifying the Operation Time
- •Specifying the Operation Concurrency
- •Specifying the Operation Preconditions
- •Specifying the Operation Postconditions
- •Specifying the Operation Semantics
- •Displaying Attributes and Operations on Class Diagrams
- •Showing Attributes
- •Showing Operations
- •Showing Visibility
- •Showing Stereotypes
- •Mapping Operations to Messages
- •Mapping an Operation to a Message on an Interaction Diagram
- •Exercise
- •Problem Statement
- •Add Attributes and Operations
- •Summary
- •Chapter 8: Relationships
- •Relationships
- •Types of Relationships
- •Finding Relationships
- •Associations
- •Using Web Association Stereotypes
- •Creating Associations
- •Deleting Associations
- •Dependencies
- •Creating Dependencies
- •Deleting Dependencies
- •Package Dependencies
- •Creating Package Dependencies
- •Deleting Package Dependencies
- •Aggregations
- •Creating Aggregations
- •Deleting Aggregations
- •Generalizations
- •Creating Generalizations
- •Deleting Generalizations
- •Working with Relationships
- •Setting Multiplicity
- •Using Relationship Names
- •Using Stereotypes
- •Using Roles
- •Setting Export Control
- •Using Static Relationships
- •Using Friend Relationships
- •Setting Containment
- •Using Qualifiers
- •Using Link Elements
- •Using Constraints
- •Exercise
- •Problem Statement
- •Adding Relationships
- •Summary
- •Chapter 9: Object Behavior
- •Statechart Diagrams
- •Creating a Statechart Diagram
- •Adding States
- •Adding State Details
- •Adding Transitions
- •Adding Transition Details
- •Adding Special States
- •Using Nested States and State History
- •Exercise
- •Problem Statement
- •Create a Statechart Diagram
- •Summary
- •Chapter 10: Component View
- •What Is a Component?
- •Types of Components
- •Component Diagrams
- •Creating Component Diagrams
- •Adding Components
- •Adding Component Details
- •Adding Component Dependencies
- •Exercise
- •Problem Statement
- •Summary
- •Chapter 11: Deployment View
- •Deployment Diagrams
- •Opening the Deployment Diagram
- •Adding Processors
- •Adding Processor Details
- •Adding Devices
- •Adding Device Details
- •Adding Connections
- •Adding Connection Details
- •Adding Processes
- •Exercise
- •Problem Statement
- •Create Deployment Diagram
- •Summary
- •Chapter 12: Introduction to Code Generation and Reverse Engineering Using Rational Rose
- •Preparing for Code Generation
- •Step One: Check the Model
- •Step Two: Create Components
- •Step Three: Map Classes to Components
- •Step Five: Select a Class, Component, or Package
- •Step Six: Generate Code
- •What Gets Generated?
- •Introduction to Reverse Engineering Using Rational Rose
- •Model Elements Created During Reverse Engineering
- •Summary
- •Chapter 13: ANSI C++ and Visual C++ Code Generation and Reverse Engineering
- •Generating Code in ANSI C++ and Visual C++
- •Converting a C++ Model to an ANSI C++ Model
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Package (Class Category) Properties
- •Component (Module Specification) Properties
- •Role Properties
- •Generalization Properties
- •Class Model Assistant
- •Component Properties
- •Project Properties
- •Visual C++ and ATL Objects
- •Generated Code
- •Code Generated for Classes
- •Code Generated for Attributes
- •Code Generated for Operations
- •Visual C++ Code Generation
- •Reverse Engineering ANSI C++
- •Reverse Engineering Visual C++
- •Summary
- •Overview
- •Introduction to Rose J
- •Beginning a Java Project
- •Selecting a Java Framework
- •Linking to IBM VisualAge for Java
- •Linking to Microsoft Visual J++
- •Project Properties
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Module Properties
- •Role Properties
- •Generating Code
- •Generated Code
- •Classes
- •Attributes
- •Operations
- •Bidirectional Associations
- •Unidirectional Associations
- •Associations with a Multiplicity of One to Many
- •Associations with a Multiplicity of Many to Many
- •Reflexive Associations
- •Aggregations
- •Dependency Relationships
- •Generalization Relationships
- •Interfaces
- •Java Beans
- •Support for J2EE
- •EJBs
- •Servlets
- •JAR and WAR Files
- •Automated J2EE Deployment
- •Reverse Engineering
- •Summary
- •Starting a Visual Basic Project
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Module Specification Properties
- •Role Properties
- •Generalization Properties
- •Generated Code
- •Classes
- •Attributes
- •Operations
- •Bidirectional Associations
- •Unidirectional Associations
- •Associations with a Multiplicity of One to Many
- •Associations with a Multiplicity of Many to Many
- •Reflexive Associations
- •Aggregations
- •Dependency Relationships
- •Generalization Relationships
- •Reverse Engineering
- •Summary
- •Overview
- •Introduction to XML DTD
- •Elements
- •Attributes
- •Entities and Notations
- •Project Properties
- •Class Properties
- •Attribute Properties
- •Role Properties
- •Component Properties
- •Generating Code
- •Generated Code
- •Classes
- •Attributes
- •Reverse Engineering DTD
- •Summary
- •Project Properties
- •Class Properties
- •Attribute Properties
- •Operation Properties
- •Module Properties
- •Association (Role) Properties
- •Dependency Properties
- •Generated Code
- •Classes
- •Attributes
- •Operations
- •Bidirectional Associations
- •Unidirectional Associations
- •Associations with a Multiplicity of One to Many
- •Associations with a Multiplicity of Many to Many
- •Associations with Bounded Multiplicity
- •Reflexive Associations
- •Aggregations
- •Dependency Relationships
- •Generalization Relationships
- •Reverse Engineering CORBA Source Code
- •Summary
- •Chapter 18: Rose Data Modeler
- •Object Models and Data Models
- •Creating a Data Model
- •Logic in a Data Model
- •Adding a Database
- •Adding Tablespaces
- •Adding a Schema
- •Creating a Data Model Diagram
- •Creating Domain Packages and Domains
- •Adding Tables
- •Adding Columns
- •Setting a Primary Key
- •Adding Constraints
- •Adding Triggers
- •Adding Indexes
- •Adding Stored Procedures
- •Adding Relationships
- •Adding Referential Integrity Rules
- •Working with Views
- •Generating an Object Model from a Data Model
- •Generating a Data Model from an Object Model
- •Generating a Database from a Data Model
- •Updating an Existing Database
- •Reverse Engineering a Database
- •Summary
- •Chapter 19: Web Modeling
- •Modeling a Web Application
- •Web Class Stereotypes
- •Relationships
- •Reverse Engineering a Web Application
- •Generating Code for a Web Application
- •Summary
- •Appendix: Getting Started with UML
- •Building a Business Use Case Diagram
- •Building a Workflow (Activity) Diagram
- •Building a Use Case Diagram
- •Building an Interaction Diagram
- •Building a Class Diagram
- •Web Modeling
- •Adding Class Relationships
- •Building a Statechart Diagram
- •Building a Component Diagram
- •Building a Deployment Diagram
Chapter 14: Java Code Generation and Reverse Engineering
Java package |
Component package |
Java Bean |
Attribute |
EJB (Enterprise Java Bean) |
Class |
Servlet |
Class |
Inner class |
Nested class |
Implements relationship |
Realization relationship |
Extends relationship |
Generalization relationship |
Import statement |
Association, dependency, or generalization |
Beginning a Java Project
When first creating a Java model, there are four steps you may want to follow. First, when working on a project that will be primarily implemented in Java, you always want to set the default language to Java. This is done through the Tools → Options menu. Click the Notation tab and set the default language to Java.
Next, select the framework you would like to use for your project. This is an optional step, but can provide you with the foundation you need to model your application. We will discuss specific frameworks shortly.
Third, if you are using either Microsoft Visual J++ or IBM VisualAge for Java, you should enable the links between Rose and these tools. Once you enable the links, you can generate code and reverse engineer VisualAge or Visual J++ projects directly from Rose.
Finally, be sure that the ClassPath environment variable is set. The ClassPath is used by Rose J to determine the location of class libraries and other files while generating code and reverse engineering. To view the ClassPath settings, select Tools → Java → Project Specification. The ClassPath entries will be displayed, and you can add or remove entries using this dialog box.
Selecting a Java Framework
When you first create a Rational Rose model, you are given the option to base your model on an existing framework. Create a new Rose model, and you will see the window shown in Figure 14.1.
Figure 14.1: Rose frameworks
Note
449
Chapter 14: Java Code Generation and Reverse Engineering
If you do not see the frameworks window, select Add−Ins → Add−In Manager, and be sure Framework Wizard is checked.
There are several Java frameworks available: J2EE, J2SE 1.2, J2SE 1.3, jdk−116, jdk−12, and jfc−11. (The last three are, respectively, Java Development Kit version 1.1.6, Java Development Kit version 1.2, and the Java Foundation Classes version 1.1.)
Simply select whichever framework you will be using for your project. Rose will automatically load classes, relationships, attributes, operations, and components from the selected framework into your new model. You can then use these elements as a foundation to create your own project.
Figure 14.2 is an example of a new Rose model using the J2EE framework. No new information has yet been added to the model. The figure shows only what is imported with the J2EE framework. Note that, for readability, many of the packages in Figure 14.2 are not expanded; however, classes and other model elements are inside each one.
Figure 14.2: Rose model with J2EE framework
You can also use a framework on an existing Rose model. To do so, you need to load the appropriate controlled units. Each package in the frameworks is stored as controlled units. Select File → Units → Load, and then navigate to the Rose 2000\framework\frameworks\shared components directory. The .cat files in this directory are the controlled units for the frameworks. Each .cat file begins with the name of the framework, such as j2ee or j2se12, so you know which files to import for which framework. Select the .cat files appropriate for your framework, and Rose will import them into your model.
Linking to IBM VisualAge for Java
Establishing a link between Rational Rose and IBM's VisualAge will allow you to update a VisualAge project directly from within Rose or to reverse engineer a VisualAge project into Rose.
To set up the link between the two tools, first start VisualAge. Select File and then Quick Start. On the dialog box, select Basic and then RoseLink Plug−In Toggle. This will establish the link from the VisualAge side.
To complete the process, start Rose. Select Tools → Java → Project Specification. On the Detail tab, set the Virtual Machine setting to IBM, as shown in Figure 14.3.
450
Chapter 14: Java Code Generation and Reverse Engineering
Figure 14.3: Java Virtual Machine setting
Select Tools → Java → IBM VisualAge for Java Project. Select the appropriate VisualAge project. The link between the two tools is now set.
Linking to Microsoft Visual J++
Similar to the link with IBM's VisualAge, the link to Microsoft Visual J++ will allow you to generate code and to reverse engineer using Rose and Visual J++. Once the link has been established, Rose can launch Visual J++ or Visual J++ can launch Rose in order to generate code or reverse engineer.
To set up the link to Visual J++, select Tools → Java → Project Specification. On the Detail tab, set the Virtual Machine setting to Microsoft.
You are now ready to work with Rose and Visual J++. From Rose, select Tools → Java → Generate Java to launch Visual J++ and generate code. From Visual J++, select the elements you wish to reverse engineer and select Tools → Update Rose Model. Rose will be launched, and the elements will be reverse engineered into the Rose model.
Java Code−Generation Properties
The Java code−generation properties can be set in two places. The defaults are set by using the Tools → Options menu item and then selecting the Java tab, as shown in Figure 14.4. You can set properties for the following items:
∙
|
Attributes |
∙ |
|
|
Classes |
∙ |
451 |
|
Chapter 14: Java Code Generation and Reverse Engineering
Module bodies
∙
Module specifications
∙
Operations
∙
Projects
∙
Roles
Figure 14.4: Java code−generation properties window
We'll discuss using these various properties throughout this chapter. We'll begin with a brief description of the available code−generation properties, then cover projects, modules, classes, attributes, operations, and roles.
Project Properties
The project properties affect all aspects of Java code generation in Rose. This section provides a listing of the properties and their common settings.
The project properties are code−generation properties that apply more to the whole project than to any specific model element, such as a class or relationship. The options in this section include things like the default directory to use when generating code, the file extensions to use, and whether or not to stop generation if an error occurs. The project properties are listed in Table 14.2, along with their purposes and default value. (In this and subsequent code−generation property tables, we list the most commonly used properties.)
Table 14.2: Java Project Properties
452
Chapter 14: Java Code Generation and Reverse Engineering
Property |
Purpose |
Default |
RootDir |
Directory to hold the Java project. |
<blank> |
CreateMissingDirectories |
If True, creates any directories that are |
True |
|
required if they do not exist. |
|
StopOnError |
If True, Rose will stop code generation at the |
False |
|
first error. |
|
UsePrefixes |
If True, Rose will add user−defined prefixes to |
False |
|
the variable names. |
|
AutoSync |
Automatically begins the code−generation |
False |
|
process when a Java element changes in the |
|
|
Rose model. |
|
ShowCodeGenDlg |
Shows a progress dialog box while generating |
False |
|
code. |
|
JavadocDefaultAuthor |
Sets the value of the Javadoc @author tag. |
<blank> |
JavadocDefaultVersion |
Sets the value of the Javadoc @version tag. |
<blank> |
JavadocDefaultSince |
Sets the value of the Javadoc @since tag. |
<blank> |
JavadocNumAsterisks |
Number of asterisks to use with the Javadoc |
0 |
|
comments. |
|
MaxNumChars |
Maximum number of characters in a line of |
80 |
|
generated Java code. |
|
Editor |
Select the editor to use while browsing code. |
Rose's built−in editor |
VM |
Select the version of the Java Virtual Machine |
Sun |
|
(Sun, IBM, or Microsoft). |
|
ClassPath |
Specifies the directory where code will be |
<blank> (use current |
|
generated. |
directory) |
InstanceVariablePrefix |
If UsePrefixes is True, then this prefix will be |
m_ |
|
added to all instance variables. |
|
ClassVariablePrefix |
If UsePrefixes is True, then this prefix will be |
s_ |
|
added to all class variables. |
|
DefaultAttributeDataType |
If no type is selected for an attribute, this type |
Integer |
|
will be used. |
|
DefaultOperationReturnType |
If no return type is selected for an operation, |
Void |
|
this type will be used. |
|
NoClassCustomDlg |
Determines whether the custom specification |
False |
|
window will be suppressed for Java classes |
|
|
and other elements. |
|
GlobalImports |
Sets import statements to be generated. Each |
<blank> |
|
class or package listed will generate an import |
|
|
statement. |
|
OpenBraceClassStyle |
Sets whether an opening brace will start on a |
True |
|
new line. |
|
OpenBraceMethodStyle |
Sets whether an opening brace for a method |
True |
|
will start on a new line. |
|
UseTabs |
Determines whether to use tabs (as opposed to |
False |
|
spaces) to indent the generated Java code. |
|
453
Chapter 14: Java Code Generation and Reverse Engineering
UseSpaces |
Determines whether to use spaces (as opposed |
True |
|
to tabs) to indent the generated Java code. |
|
SpacingItems |
Number of tabs or spaces (depending on the |
3 |
|
values of UseTabs and UseSpaces) to use to |
|
|
indent the generated Java code. |
|
RoseDefaultCommentStyle |
Use the default Rose comment style in |
True |
|
generated code. |
|
AsteriskCommentStyle |
Use asterisk comment style in generated code. |
False |
JavaCommentStyle |
Use Javadoc tags for comments in generated |
False |
|
code. |
|
JavadocAuthor |
Controls whether the Javadoc @author tag is |
True |
|
enabled. |
|
JavadocSince |
Controls whether the Javadoc @since tag is |
False |
|
enabled. |
|
JavadocVersion |
Controls whether the Javadoc @version tag is |
False |
|
enabled. |
|
Most of these project properties can also be set in the Project Specification window. To open the Project Specification window, select Tools → Java → Project Specification. On the Class Path tab, you can set the ClassPath project property.
Figure 14.5 shows the Style tab of the Java Project Specification window. On this tab, you can set the values of the following properties:
∙
UseTabs
∙
UseSpaces
∙
SpacingItems (Number to Use)
∙
OpenBraceClassStyle (On New Line for Classes)
∙
OpenBraceMethodStyle (On New Line for Methods)
∙
RoseDefaultCommentStyle (Rose Default)
∙
AsteriskCommentStyle (Asterisk Style)
∙
JavaCommentStyle (Javadoc Style)
∙
MaxNumChars (Maximum Number of Characters in a Line)
∙ |
454 |
|
Chapter 14: Java Code Generation and Reverse Engineering
JavadocAuthor, JavadocDefaultAuthor (@Author)
∙
JavadocVersion, JavadocDefaultVersion (@Version)
∙
JavadocSince, JavadocDefaultSince (@Since)
∙
JavadocNumAsterisks (Number of Asterisks)
Refer to Table 14.2 for a description of each of these properties.
Figure 14.5: Style tab of the Java Project Specification window
On the Detail tab of the Project Specification window, you can set additional project properties. Figure 14.6 shows the Detail tab. It includes the following properties:
∙
Editor
∙
VM (Virtual Machine)
∙
RootDir (Root Directory)
∙
DefaultAttributeDataType (Attribute)
∙
DefaultOperationReturnType (Method Return)
∙
455