Skip to main content

skip to main content

developerWorks  >  Rational  >

Customizing IBM Rational Rose with frameworks and stereotypes

developerWorks
Document options

Document options requiring JavaScript are not displayed


Rate this page

Help us improve this content


Level: Introductory

Shawn Keller, Delivery Leader, Experio Solutions

24 Nov 2003

This article gives you step-by -step instructions for creating customized frameworks and stereotypes in Rose. The benefits of using Rose to visually model a framework's major concepts are also discussed.

Depending on the software engineering effort you're involved in, you may or may not know right up front the implementation platform and language of the system you're developing. If you do know the specifics at the outset -- because the implementation standard is set across the enterprise or across multiple projects -- you can use a Rational Rose framework to model your application. You can either use one of the standard frameworks or customize Rose to use an internally developed software engineering framework. In addition, you can visually model the framework's major concepts with custom stereotypes. This article explains frameworks and stereotypes and shows you how to create them in Rose.

Creating Custom Frameworks

The Framework Wizard Add-In (available on all Windows versions of Rational Rose) provides a library of frameworks that you can use as templates when creating models. If you know the implementation specifics when your development effort enters design, you can use one of these frameworks -- or a custom framework you create -- to model your application. This will enable you to take advantage of common development libraries as you develop implementation-specific class models. Library characteristics such as packages, classes, interfaces, relationships, operations, and attributes are exposed to the designer and can easily be extended to suit your own system.

Rational Rose offers a number of different kinds of frameworks, including ones for the Java and Visual Basic languages, Oracle databases, and the Rational Unified Process. The Java frameworks support both Java 1 and 2, including JDK 1.1.6, Java 2 Standard Edition (J2SE), and Java 2 Enterprise Edition (J2EE). The available frameworks are displayed when you choose File > New in Rose, bringing up the Create New Model dialog (Figure 1).

Create New Model dialog
Figure 1: Create New Model dialog

But what if the development effort needs to employ a framework that's not packaged with Rational Rose, whether a third-party API or a corporate library developed internally and reused throughout the enterprise? You can easily add a new framework with the Framework Wizard. Here are the steps you'll follow:

  1. Obtain the library.
  2. Configure the environment for the library.
  3. Reverse-engineer the library into a Rose model.
  4. Create a description and an icon for the new framework.
  5. Invoke the Framework Wizard and fill in the specification page.

An example will illustrate these steps. Let's say we want to create a framework that incorporates the JavaMail API as developed by Sun. The JavaMail API is a library that takes advantage of SMTP and POP3 capabilities to develop mail and messaging applications.

Obtain the library

In our example, we download the JavaMail API from the JavaSoft site as a ZIP file.

Configure the environment for the library

Since we're using Java, the environment variable CLASSPATH must be set to reflect the presence of our new library. In our example, the JavaMail API is made up of five JAR (Java archive) files and each of these must be set in the environment variable:

CLASSPATH= ...;c:\javamail-1.2\imap.jar;c:\javamail-1.2\mail.jar;c:\ 
javamail-1.2\mailapi.jar;c:\javamail-1.2\pop3.jar;c:\javamail-1.2\smtp.jar;

Reverse-engineer the library into a Rose model

Next we need to create and save a Rose model with the contents of the library. This model will be used as the template when new models are created from this framework. The most direct way to get our third-party library into Rose is through reverse engineering.

Choose Tools > Java > Reverse Engineer Java in Rose. This opens the Java Reverse Engineer dialog (Figure 2).

Java Reverse Engineer dialog
Figure 2: Java Reverse Engineer dialog

Add the five JavaMail JAR files to the model as follows:

  1. In the directory tree on the left, select a JavaMail JAR file.
  2. In the Filter list box, set the filter to *.class to display in the file listing (above this list box) all the class files associated with the chosen JAR file.
  3. Click the Add All button to add all the class files to the reverse-engineer listing in the bottom half of the dialog.
  4. Repeat steps 1 through 3 to add the class files for all the JavaMail JAR files to the reverse-engineer listing.
  5. Click the Select All button to select all the files in the reverse-engineer listing. Then we click the Reverse button to start the reverse engineering process. If any errors occur during this process, we'll be notified in a window.

Save the new Rose model as javamail.mdl.

Create a description and an icon for the new framework.

At this point, we'll need to create a description and an icon that will be used in the Create New Model dialog to denote our new framework. In this example, we write a description of the JavaMail framework in Microsoft Word and saved it in RTF format as javamail.rtf, and save a drawing of the popular Java juggler from JavaSoft as juggler.ico.

Start the Framework Wizard and fill in the specification page.

We start the Framework Wizard by clicking the Make New Framework icon in the Create New Model dialog (Figure 1, above). The wizard's specification page (Figure 3) prompts us for necessary information.

Framework Wizard specification page
Figure 3: Framework Wizard specification page
(click here to enlarge)

Enter the name of the new framework (JavaMail) and the name and location of the file that constitutes the framework model (D:\javamail-1.2\javamail.mdl). In the Start Diagram list box, choose Logical View / Main as the initial diagram. Then enter the name and location of the documentation and icon files (D:\javamail-1.2\javamail.rtf, D:\javamail-1.2\juggler.ico) and click Next.

The wizard presents a summary of the new framework to approve. When we click Finish, the wizard creates a folder with the same name as the new framework, containing the specified files, in the \Framework\Frameworks folder. The next time a new model is created, the JavaMail choice is available (Figure 4), and a design can be based on this new framework.

Create New Model dialog with the JavaMail framework available
Figure 4: Create New Model dialog with the JavaMail framework available


Back to top


Creating Custom Stereotypes

In Rose, a stereotype is a modeling element subclassification that gives more specific meaning to the element and helps define it. For example, you can use different stereotypes to distinguish classes that provide data storage (<<Model>>), classes that display data (<<View>>), and classes that handle user interaction (<<Controller>>). Stereotypes can be applied to packages, components, classes, use cases, operations, attributes, and such. A stereotype can be depicted in diagrams, in the Rose model browser, and in the toolbar by either a name enclosed in guillemets (<< >>) or an icon.

Rose comes with a set of predefined stereotypes. You can also define your own stereotypes to further customize your development process, provide mnemonic help and visualization aids, and add greater detail to your presentations. Here's the process you'll want to follow:

  1. Create icons for the stereotype.
  2. Edit the stereotype configuration file to define the new stereotype.
  3. Add the new stereotype to the diagram toolbox.

Again we'll use an example to illustrate this process. In our example, we'll create a JavaScript stereotype for the Web Modeler Add-In, associate it with images, and enable it for use in Rose. This add-in, which comes standard with Rational Rose Enterprise, enables developers to model the presentation side of an application. It already includes stereotypes and model images for Web pages, forms, Java applets, and COM objects. Adding a JavaScript stereotype will make it easy to represent JavaScript code where called for in the design of Web pages.

Create icons for the stereotype.

First we quit Rose and create two different kinds of icon for the stereotype: one to be used in diagrams and a second to be used in the diagram toolbox, specification lists, and the browser. There are size constraints for the latter kind; you should consult the Rose online documentation for specifics (Rational Rose Help > Search For Help On… > Creating Diagram Toolbox and List View Icons).

The diagram icon -- to be placed on a diagram browser, toolbar, or menu -- must be created in Windows Metafile (.wmf) or Enhanced Metafile (.emf) format. Figure 5 is our diagram icon, saved as javascript.wmf.

Diagram icon for our JavaScript stereotype
Figure 5: Diagram icon for our JavaScript stereotype

The diagram toolbox and list view icon -- to serve as a button in the diagram toolbox and represent the stereotype in specification lists and in the browser -- must be in Windows Bitmap (.bmp) format. Figure 6 is our diagram toolbox and list view icon, saved as javascript.bmp.

Diagram toolbox and list view icon for our JavaScript stereotype
Figure 6: Diagram toolbox and list view icon for our JavaScript stereotype

If we want to, we can supply the second kind of icon in both small and large sizes to make a large button optionally available in the diagram toolbox.

Edit the stereotype configuration file to define the new stereotype.

The stereotypes in Rational Rose must be defined in a stereotype configuration file, which includes the location of icon files as well as settings that affect the usage and display of the defined stereotypes. Rational Rose is delivered with a default stereotype configuration file, named DefaultStereotypes.ini, and you should add your stereotypes to that file if possible. In this example, we use the stereotype configuration file for the Web Modeler Add-In.

Because different versions of Rational Rose name this configuration file differently, we need to view the Windows Registry to determine the exact name and location of the file. Using the Windows Registry Editor (regedit.exe), we navigate to the following registry location:

HKEY_LOCAL_MACHINE\SOFTWARE\Rational Software\Rose\AddIns\Web Modeler

Look for the installation location of Rational Rose (InstallDir) and the name of the stereotype configuration file (StereotypeCfgFile), and then open the file -- in our case, at C:\Program Files\Rational\Rose\Web Modeler\rwmstereotypes.ini.

In the configuration file, first add a line for the JavaScript stereotype (Class:JavaScript) in the section called Stereotyped Items, as shown in Figure 7.

Stereotyped Items section with Class:JavaScript added for the stereotype
Figure 7: Stereotyped Items section with Class:JavaScript added for the stereotype

Then add a Class section for the new stereotype, titled with the same line that was added to the Stereotyped Items section. Copying and pasting a preexisting Class section for another stereotype and then editing it is the easiest way to add this section in the file. Figure 8 shows our Class section; note that we specify the names of the icon files as well as some formatting and sizing instructions.

Class section added for our stereotype
Figure 8: Class section added for our stereotype

That's all there is to editing the stereotype configuration file. When we restart Rose, the new stereotype will be available.

Add the new stereotype to the diagram toolbox.

To make the new stereotype available as a button on a diagram toolbox, choose Tools > Options and click the Toolbars tab. Under Customize Toolbars, click on the diagram type for which we want to change the toolbox. The Customize Toolbar dialog (Figure 9) is displayed. Select the new icon in the column on the left and click Add.

Customize Toolbar dialog
Figure 9: Customize Toolbar dialog
(click here to enlarge)

As Figure 10 shows, the new stereotype is now enabled within the Rational Rose browser and diagram toolbox. Any class created with the JavaScript stereotype will be represented with the stereotype icon in all Rational Rose diagrams.

JavaScript stereotype in the browser and diagram toolbox
Figure 10: JavaScript stereotype in the browser and diagram toolbox
(click here to enlarge)


Back to top


The Joy of Customization

Successful development teams use industry-accepted standards like J2EE or Microsoft .NET for the implementation while at the same time creating internal software engineering frameworks that serve as blueprints for most application development efforts. These frameworks are reusable, evolve over time, and make efficiency gains possible. As you've learned in this article, Rational Rose is customizable to incorporate such frameworks. Rose also gives teams the ability to visually model a framework's major concepts through the use of custom stereotypes. Try injecting Rose into the development effort from design through construction and customizing it with frameworks and stereotypes. You'll be glad you did.



About the author

Shawn Keller is the Delivery Leader for Experio Solutions' Western Regional Application Construction Practice. He specializes in architecting and managing the development of large-scale Java/J2EE and Microsoft applications using the Rational Unified Process. He's been designing and developing large-scale applications for more than four years. At the time of the development efforts on which this article is based, Shawn worked for WaveBend Solutions (later acquired by Experio Solutions). He can be reached by e-mail at skeller@experio.com.




Rate this page


Please take a moment to complete this form to help us better serve you.



YesNoDon't know
 


 


12345
Not
useful
Extremely
useful
 


Back to top