Wednesday, October 2, 2013

Java to UML transformation extensios - Part I

Hi folk, 

In this post, I will show you how to make a Java to UML transformation extension using IBM Rational Software Architect (RSA).

But first, in terms of modeling, what is a transformation?

A transformation is:
  • A mechanism that takes a set of source elements and changes them into a new set of target elements.
  • A set of transforms that you can configure, specify as public in the plug-in manifest file, and run using a transformation configuration.

So, with the transformation extensions you can extend and enhance custom transformations or the transformations that are available in the IBM Rational modeling products.
The transformation framework extensibility is based on the Eclipse plug-in architecture. Transformation extensions are plug-ins that contain the following items:
  • An extension to this extension point: com.ibm.xtools.transform.core.transformationExtensions
  • One or more TransformationExtension elements, which defines the rules, extractors, or transforms that enhance the functionality of the extended transformation
  • One or more ExtendTransform elements, which define the transform to extend  

For example, I'll use two rules and an extractor as show the following image:


- RuleA: select interfaces contains in Java Project
- ExtractorB: extract information from the interface methods
- RuleB: select methods that take input parameters

Concepts:
  • Transformation context: contains the values for all of the parameters of the transformation
  • Source: the initial object, or set of objects, passed into the transformation operation
  • Target container: A reference to the locations where any generated artifacts are located

First thing to check is the packages installations. Run the IBM Installation Manager and be sure that Transformation authoring is selected.

 


Ok, let's get to work.

Procedure to create a Plug-in Project transformation extension:

  1. Open RSA and create a new project. File -> New -> Project...
  2. Select Other -> Plug-in Development -> Plug-in Project and click Next
  3. Write in Project name: org.jif.transform.java2uml and click Next
  4. Write Versión 1.0.0 and in Rich Client Application select No
  5. Click Next
  6. Select Custom plug-in wizard from templates and click Next
  7. Select Transformation Extensions and click Next
  8. In Target transformation ID, select com.ibm.xtools.transform.java.uml.Java-to-UML. Click Next
  9. Insert the 3 transformation elements for the example as shows following image
    • RuleA
    • ExtractorB
    • RuleC
  10. Click Finish
  11. In the Plug-in Manifest Editor (Plug-in Development perspective), click on tab Extensions
  12. Select true in the enabled property in Extension Element Details

Now, we can launch an Eclipse application to set up the test environment for the example.

Procedure to transform Java to UML:
  1. In the Plug-in Manifest Editor (Plug-in Development perspective), click on icon Launch an Eclipse application 
  2. Create a new Java Project. File -> New -> Project...
  3. Select Java -> Java Project and click Next
  4. Write in Project name: Java Program and click Finish
  5. Create 3 classes and 2 Interfaces: 
    • org.jif.test.fix1
      • ClassA
      • InterfaceA
    • org.jif.test.fix2
      • ClassB
      • InterfaceB
    • org.jif.test.fix3
      • ClassC
  6. Define classes and interfaces as:
    • InterfaceA has method getName() and return value as String
    • InterfaceB has method calculate(int val) and return value as int
    • ClassA implements InterfaceA and add a private string attribute name and the override method from interface
    • ClassB implements InterfaceB and add the override method from interface
    • ClassC has method print(String text) and not return value
  7. Open the Modeling perspective
  8. Create a new project. File -> New -> Project...
  9. Select General -> Project and click Next
  10. Write in Project name: UML Project and click Finish
  11. Create a model UML, File -> New -> Model
  12. Select Standard template and click Next
  13. Select General -> Blank Package and in File name: org
    •  The model org, you can delete later. What we need is a model container.
  14. Browse Destination folder and select UML Project
  15. Click Finish
  16. Create a new Transform, File -> New -> Transformation Configuration 
    • Write in Name: java2uml 
    • Select Configuration file destination: Java Program
    • Select the Java to UML transformation
    • Select Protocol: Conceptual
  17. Click Next
  18. We have to set the source and target:
    • Specify the elements that the transformation transforms, inside of Java Project, select src folder
    • Specify the model destination project for the transformation output, select UML Project
  19. Click Finish 
  20. Open the transformation overview with the Transformation Configuration Editor
  21. Click on Extension tab to check if the Java to UML transformation extension is checked
  22. Now, in the Main tab, we can run the extension with the following options checked:
    • Generate UML operations for each Java getter/setter method
    • Generate UML a flat UML package for each Java package
    • Generate a debug log
  23. To see the transformation, create a class diagram and add all UML elements transformed 



Now we have created the skeleton of the transformation, I will now extend the rules and extraction.

Easy right? Now the fun begins

See Java to UML transformation extensios - Part II 

(coming soon, you have to be patient)