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:
For example, I'll use two rules and an extractor as show the following image:
- 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:
- Open RSA and create a new project. File -> New -> Project...
- Select Other -> Plug-in Development -> Plug-in Project and click Next
- Write in Project name: org.jif.transform.java2uml and click Next
- Write Versión 1.0.0 and in Rich Client Application select No
- Click Next
- Select Custom plug-in wizard from templates and click Next
- Select Transformation Extensions and click Next
- In Target transformation ID, select com.ibm.xtools.transform.java.uml.Java-to-UML. Click Next
- Insert the 3 transformation elements for the example as shows following image
- RuleA
- ExtractorB
- RuleC
- Click Finish
- In the Plug-in Manifest Editor (Plug-in Development perspective), click on tab Extensions
- Select true in the enabled property in Extension Element Details
Procedure to transform Java to UML:
- In the Plug-in Manifest Editor (Plug-in Development perspective), click on icon Launch an Eclipse application
- Create a new Java Project. File -> New -> Project...
- Select Java -> Java Project and click Next
- Write in Project name: Java Program and click Finish
- Create 3 classes and 2 Interfaces:
- org.jif.test.fix1
- ClassA
- InterfaceA
- org.jif.test.fix2
- ClassB
- InterfaceB
- org.jif.test.fix3
- ClassC
- 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
- Open the Modeling perspective
- Create a new project. File -> New -> Project...
- Select General -> Project and click Next
- Write in Project name: UML Project and click Finish
- Create a model UML, File -> New -> Model
- Select Standard template and click Next
- Select General -> Blank Package and in File name: org
- The model org, you can delete later. What we need is a model container.
- Browse Destination folder and select UML Project
- Click Finish
- 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
- Click Next
- 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
- Click Finish
- Open the transformation overview with the Transformation Configuration Editor
- Click on Extension tab to check if the Java to UML transformation extension is checked
- 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
- To see the transformation, create a class diagram and add all UML elements transformed
This is a very valuable tutorial. For tutes like these for diagramming its better to ise a Creately UML diagram software
ReplyDelete