Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Hello World: Rational Software Architect V7

Design and implement a simple phone book application (updated)

Tinny Ng (tng@ca.ibm.com), Advisory Software Developer, IBM Toronto
Tinny Ng
Tinny Ng is a scenario architect at the IBM SWG Scenario Analysis Lab, whose mission is to improve the cross-brand integration capability of IBM SWG products. She has more than 10 years of experience in software development, from design to implementation, including application building, packaging, testing, and support.
(An IBM developerWorks Contributing Author)

Summary:  This first tutorial in the Hello World series has been updated for Rational Software Architect V7. Hands-on exercises walk you through every step of designing and implementing a service-oriented application using Rational® Software Architect V7, including using UML diagrams to design and model an application, publishing the model information to a Web page, and transforming the design to Java™ code. It concludes with an introduction to Rational Software Architect V7's new true round-trip engineering (RTE), which makes it possible to forward- and reverse-engineer Java code, giving you a head-start on implementing your designs.

View more content in this series

Date:  20 Feb 2007
Level:  Intermediate PDF:  A4 and Letter (2079 KB | 38 pages)Get Adobe® Reader®

Activity:  43259 views
Comments:  

Transformation and true round-trip engineering

Transformation is a key feature of Rational Software Architect, allowing you to easily transform your designs from UML to EJB components, WSDL, Java code, and so on. In Rational Software Architect V7, the transformation function has been extended to include support for true round-trip engineering (RTE), giving you even more of a head-start in implementing your designs.

Before you can run a transformation, you must create a transformation configuration. A transformation configuration is an instance of a transformation that includes information that all transformations use, such as a unique name, the source, and the target of the transformation. A transformation configuration can also include properties that are specific to a given transformation. When you run a transformation, it uses the information provided in the transformation configuration.

The Rational Software Architect V7 tutorial gallery includes a tutorial called "Concurrently develop UML models and Java code using transformations," which shows you how to create a UML-to-Java transformation configuration that applies the Replace UML elements option. When you run a UML-to-Java transformation, the elements in the UML model are replaced with visual representations of the corresponding generated Java classes. This replacement enables you to make changes to the source code from the model and vice versa. The changes that you make to the model are reflected automatically in the corresponding Java file and the changes that you make to the Java classes are reflected automatically in the corresponding model element.


Figure 17. A screen shot from the UML-to-Java transformation tutorial
A screen shot from the UML-to-Java transformation tutorial

In this tutorial, you will learn how to transform your UML design into Java without using the Replace UML elements option. Instead, you'll first transform the model into Java code, make a small change in the generated Java file, and then transform the Java class into another UML model. You'll then compare the original UML model with the reverse-engineered UML model to see the difference.

Transform UML to Java

First, create a transformation configuration for the UML-to-Java transformation.

Would you like to see these steps demonstrated for you?

Show meShow me

  1. Select Phone Book UML Model in Rational Software Architect's Model Explorer view.
  2. Select Modeling > Transform > New Configuration.
  3. Enter the name PhoneBookUML2Java and select IBM Rational > UML to Java V5.0, as shown in Figure 18. Click Next.

    Figure 18. Creating a transformation configuration
    Creating a transformation configuration

  4. Select MyPhoneBookUML > Models > Phone Book UML Model as the source.
  5. Click Create new Target Container... to create a Java project for storing the generated files.
  6. In the New Java Project panel, enter PhoneBookJavaProject as the Java project name. Click Finish.
  7. In the Source and Target panel, select the newly created Java project PhoneBookJavaProject as your target, as shown in Figure 19.

    Figure 19. Selecting a source and target for transformation
    Selecting a source and target for transformation

  8. Click Next.
  9. Unselect Generate getter and setter so that no getters and setters will be generated, as shown in Figure 20.

    Figure 20. Unselecting getter and setter generation
    Unselecting getter and setter generation

  10. Continue clicking Next to see what other options are available. Take all the default options, then click Finish.

You have now created a transformation configuration called PhoneBookUML2Java.tc. You have also created a PhoneBookJavaProject, but no Java files are yet being generated. Your next step is to transform the UML model to Java code.

  1. Right-click the transformation configuration file PhoneBookUML2Java.tc.
  2. Select Transform > UML to Java V5.0 to transform the UML model to Java code, as shown in Figure 21.

    Figure 21. Transforming UML to Java code
    Transforming UML to Java code

  3. Navigate the newly generated Java files to see how the UML model elements are being transformed. For example, take a look at PhoneBookController.java, shown in Figure 22. The generated class has two attributes, phonebookmodel and phonebookview, which are generated, respectively, as a result of the directed association and association relationships you created earlier. The two operations (userHasInput and start) that you added when drawing the class diagram are also generated.

    Figure 22. PhoneBookController.java
    PhoneBookController.java

  4. Make a change to PhoneBookController.java, as shown in Figure 23. You will see later how this change is reflected in the reverse-engineered UML model.

    Figure 23. Adding a parameter to userHasInput()
    Add a parameter to userHasInput()

  5. Press Ctrl S to save all the changes.

Transform Java to UML

Now create another transformation configuration to transform the Java files back to a UML model.

  1. Select PhoneBookJavaProject in Rational Software Architect's Model Explorer view.
  2. Select Modeling > Transform > New Configuration.
  3. Enter the name PhoneBookJava2UML and select IBM Rational > Java to UML, as shown in Figure 24. Click Next.

    Figure 24. Creating a transformation configuration for Java-to-UML transformation
    Creating a transformation configuration for Java-to-UML transformation

  4. Select PhoneBookJavaProject as the source.
  5. Click Create new Target Container... to create a new UML model for storing the generated files.
  6. In the Create UML Model panel, click Next to create a new UML model from the standard template.
  7. Enter Phone Book UML Reverse Model as the file name.
  8. Click Browse to select the existing MyPhoneBookUMLProject as the location for the new model file. The Create UML Model panel should look as shown in Figure 25.

    Figure 25. The Create UML Model panel
    Create new UML model

  9. Click Finish.
  10. In the Source and Target panel, select the newly created model file Phone Book UML Reverse Model as the target, as shown in Figure 26.

    Figure 26. Selecting the source and target for transformation
    Selecting the source and target for transformation

  11. Click Next.
  12. Unselect Generate getter and setter so that no getters and setters will be generated.
  13. Continue clicking Next to see what other options are available. Take all default options, then click Finish.

You have now created a transformation configuration called PhoneBookJava2UML.tc. The last step in this exercise is to transform the Java files to a UML model.

  1. Right-click the file PhoneBookJava2UML.tc.
  2. Select Transform > Java to UML to transform the Java code to a UML model, as shown in Figure 27.

    Figure 27. Transforming Java code to UML
    Transforming Java code to a UML model

  3. Click OK to accept any pending changes.
  4. The three Java classes are now transformed to three model elements under the Phone Book UML Reverse Model, as shown in Figure 28.

    Figure 28. The generated UML model
    The generated UML model

  5. Create a Class Diagram in the Phone Book UML Reverse Model to visualize the generated model elements. Drag and drop the three model classes into the diagram, as shown in Figure 29.

    Figure 29. The three model classes in the class diagram
    The three model classes in the class diagram

  6. The association relationships are shown as attributes in this diagram. Select those attributes, then right-click and select Filters > Show As Association to turn those attributes into association relationships.
  7. The new parameter that you've added in userHasInput is not obvious in the diagram. Right-click the class PhoneBookController and select Filters > Show Signature to display the full signature of the operations.
  8. The class diagram for your transformed UML model should look as shown in Figure 30. Compare this diagram with the class diagram you created earlier (see Figure 9) and notice the similarity. Notice also that the Association Relationship is shown as two lines in this diagram to indicate the bidirectional behavior.

    Figure 30. The generated UML model
    The generated UML model

  9. Press Ctrl S to save all the changes.

10 of 15 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=196561
TutorialTitle=Hello World: Rational Software Architect V7
publish-date=02202007
author1-email=tng@ca.ibm.com
author1-email-cc=