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
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.
First, create a transformation configuration for the UML-to-Java transformation.
- Select Phone Book UML Model in Rational Software Architect's Model Explorer view.
- Select Modeling > Transform > New Configuration.
- Enter the name
PhoneBookUML2Javaand select IBM Rational > UML to Java V5.0, as shown in Figure 18. Click Next.
Figure 18. Creating a transformation configuration
- Select MyPhoneBookUML > Models > Phone Book UML Model as the source.
- Click Create new Target Container... to create a Java project for storing the generated files.
- In the New Java Project panel, enter
PhoneBookJavaProjectas the Java project name. Click Finish. - 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
- Click Next.
- 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
- 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.
- Right-click the transformation configuration file PhoneBookUML2Java.tc.
- 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
- 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,
phonebookmodelandphonebookview, which are generated, respectively, as a result of the directed association and association relationships you created earlier. The two operations (userHasInputandstart) that you added when drawing the class diagram are also generated.
Figure 22. PhoneBookController.java
- 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()
- Press Ctrl S to save all the changes.
Now create another transformation configuration to transform the Java files back to a UML model.
- Select PhoneBookJavaProject in Rational Software Architect's Model Explorer view.
- Select Modeling > Transform > New Configuration.
- Enter the name
PhoneBookJava2UMLand select IBM Rational > Java to UML, as shown in Figure 24. Click Next.
Figure 24. Creating a transformation configuration for Java-to-UML transformation
- Select PhoneBookJavaProject as the source.
- Click Create new Target Container... to create a new UML model for storing the generated files.
- In the Create UML Model panel, click Next to create a new UML model from the standard template.
- Enter
Phone Book UML Reverse Modelas the file name. - 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
- Click Finish.
- 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
- Click Next.
- Unselect Generate getter and setter so that no getters and setters will be generated.
- 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.
- Right-click the file PhoneBookJava2UML.tc.
- 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
- Click OK to accept any pending changes.
- 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
- 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 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.
- 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.
- 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
- Press Ctrl S to save all the changes.





