 | Level: Introductory Anand Ramdeo (anand.ramdeo@in.ibm.com), Software Engineer, IBM Subramanian Neelakantan (subramanian.neelakantan@in.ibm.com), Software Engineer, IBM
10 Jan 2006 This article will describe how to create and use the CORBA Template model, and extend it to create your own CORBA Model.
Introduction
IBM® Rational® Software Architect (RSA) is a Unified Modeling Language (UML) 2.0-compliant modeling tool. This tool can be used to design, develop, and test software. This tool can also transform models from one abstraction level to another. Transforming model elements from one level of abstraction to another level is called Transformation in MDA (Model Driven Architecture) terminology, and is supported by RSA. One good example of transformation can be transforming model elements to source code. These transformations are present for Java™, C++, Common Object Request Broker Architecture (CORBA), and so on. This article will give you an overview of transformation from UML to CORBA.
The UML to CORBA transformation transforms UML 2.0 model elements into CORBA Interface Definition Language (IDL).The transformation provides an optional, lightweight profile that you can use to model and generate most CORBA elements. CORBA Transformation also comes with the CORBA template model. This CORBA template model provides a way to quick-start modeling a CORBA system using RSA or IBM® Rational® Software Modeler (RSM). This template model contains a properly-formatted CORBA Model, including component and interface elements, and shortcuts to the CORBA Types created with the help of UML 2.0 primitive types.
This article will describe how to create and use the CORBA Template model, and extend it to create your own CORBA Model. This will also show you how to validate your model, run transformation on your model to generate CORBA IDL files, and how CORBA Transformation is integrated with IBM® Rational® ClearCase®.
Transformation workflow
Creating a UML project
Before you use the UML 2.0 to CORBA transformation, you should be familiar with creating and editing UML 2.0 models and projects. This section will describe the normal workflow of a CORBA Transformation. The first step for you will be to create a UML Modeling project, and then a CORBA Template model within this project.
- To do this, launch RSA, click File -> New -> Project and select UML Project in the list.
- Click on Next and specify the project name as UMLtoCORBA.
- Click Next.
This will give a list of templates present for the UML model, as shown in Figure 1.
Figure 1. A list of available templates for your project
- Select Corba Template Model from the list, specify the File name as UMLtoCORBA and click Finish.
This will create a Corba Template Model in the UMLtoCORBA project, and will create model structure similar to that in Figure 2.
Figure 2. Model structure of your project
Organizing your model
This CORBA Template model contains various UML elements like package, component, interface and so on. This template model also contains shortcuts to the CORBA primitive types that can be used by your model. Class diagrams and instruction in the template model contains information on how to use this model. Once you have created a new CORBA Template model, you can rename and organize the model structure to create your own UML model with CORBA elements. Follow these steps to create the example model.
- In CORBA transformation, components are mapped to the IDL file, so rename this component to NamingAuthority and drag it to the root of this model (that is, UMLtoCORBA). Transformation will generate an IDL file for this component.
- Rename the interface present in this component to translation_library. This interface provides the interface for the NamingAuthority component. Transformation will generate a corresponding interface definition in the NamingAuthority.idl file.
- Create one package inside the NamingAuthority component called NamingAuthority. This package contains all the classes and interfaces that comprise the naming authority component. Transformation will generate module definition corresponding to this package within the NamingAuthority.idl file.
- Drag the translation_library interface from the component to the NamingAuthority package.
- Create RegistrationAuthority enumeration within the NamingAuthority Package. This enumeration contains the enumeration literals that define the definition language type for the naming authority. Create these enumeration literals in this enumeration: DNS, IDL, ISO, DCE and OTHER.
By this point your model should look similar to Figure 3.
Figure 3. Changes reflected in your model
Designing CORBA-specific types
To model further, you need some way to design CORBA-specific types. CORBA-specific types can be designed with the help of stereotypes. These stereotypes will be available to you if you apply the CORBA Transformation profile to this model. With the help of this profile you can model CORBA-specific types like struct, valuetype, typedef, and so on. This profile also contains information about the constraints applied on these stereotypes.
- To add a CORBA Transformation profile to your model, select the model root (in other words, UMLToCORBA under UMLToCORBA.emx) and observe the Properties view. In the left hand side there will be one tab for Profiles.
- Selecting this tab gives you a list of the profiles already applied to the model, and includes an Add Profile button as shown in Figure 4.
Figure 4. Your model profiles
- Click Add Profile. Once the CORBA Transformation profile is created, you can model CORBA-specific types.
- Create one class AuthorityID inside NamingAuthoritypackage.
- Now select this class and, in the Properties view, click the Stereotypes tab.
- Click the Add Stereotypes button.
- Select CORBAStruct and click OK, as shown in Figure 5. Now Transformation will generate a CORBAStruct definition for the AuthorityID class in the generated IDL file.
Figure 5. Applying a stereotype to your class
- To add properties to this CORBAStruct, add the attribute naming_entry to the AuthorityID class and change its type to CORBAPrimitive type String.
- Now create one more attribute, authority, and set its type to the RegistrationAuthority enumeration. Type of the attribute can be specified in the properties view.
- Create one more class QualifiedName in the NamingAuthority package and apply the CORBAStruct stereotype to this.
- Create one attribute as authority_id and set its type to AuthorityID CORBAStruct.
- Create one more attribute local_name and set its type to String.
- The last part of the model is to implement the translation_library interface.
- Create one operation authority_to_str() in this interface. Set the return type for this operation as String, and the parameter as AuthorityID.
- Add one more operation str_to_authority() in this interface with return type as AuthorityID and parameter as String.
- Similarly create a method for qualified_name_to_str() with return type as String and parameter as QualifiedName.
- For the last method create str_to_qualified_name() with return type as String and parameter as QualifiedName.
Your CORBA model is now complete, and all the required stereotypes have been applied. If you drag all the elements to the diagram surface, the final model should look similar to the Figure 6.
Figure 6. Your finished model
Now you can run CORBA Transformation against this model, or validate this model for any constraints violation for the stereotypes applied. To validate the model you need to select the model, right-click it and select Run Validation, as shown in Figure 7. Alternatively you can also select Modeling -> Run Validation after selecting the model.
Figure 7. Validating your model
If any errors or warnings are reported during the validation process, it is suggested that you correct your model before proceeding to the transformation. If the model is not corrected, transformation may not be complete, or the generated IDLs might be incomplete.
The Transformation
Once you have a correct model which returns zero errors and warning messages, you can run the Transformation.
- To run the Transformation, right-click the model root and select Transform -> Run Transformation -> UML to CORBA, as shown in Figure 8. You can do the same thing by clicking Modeling -> Transform -> Run Transformation -> UML to CORBA.
Figure 8. Running the transformation
- This operation will launch a dialog for Run Transformation, as shown in Figure 9 Using this dialog, you can specify name, source, the target for transformation, a mapping model, and common operations like logging and so on. All these options are discussed in detail in the following sections.
Figure 9. Run Transformation wizard
- The Name of the transformation can be any unique name. Different configurations for transformations can be stored under different transformation names. These transformation names can be displayed in the Run Transformation menu (though you need to select the Show in transformation menu checkbox on the Common Page), and from there be executed directly.
- Source: You can specify a UML model, component, package, or a combination of these elements as the source for transformation. The transformation generates a single IDL file for each UML component. Each IDL file contains code only for the elements that the corresponding UML component owns. The transformation ignores elements that are not owned by a UML component. If you specify any other element as the source for the transformation, the transformation fails during validation.
- Target will store the IDL files generated from the CORBA Transformation. Any Eclipse project can be treated as a valid target for CORBA Transformation. A new Eclipse project to hold the IDLs can also be created by clicking Create new target container.
- After you’ve specified the name, source, and target for the transformation, you can define mapping. Using mapping is optional. By default, the generated IDL will use the names of UML elements for CORBA element names. Using a mapping model, you can rename modeled elements in the generated code. Except for components, you can only rename UML elements with simple identifiers.
By default, mapping is disabled, and you need to select the Enable Mapping checkbox in order to enable it. As shown in Figure 10, you can either use an existing model for the mapping or create a new mapping model by clicking New.
Figure 10. Mapping in the transformation
- If you click Edit Mapping, a dialog (Figure 11) will prompt you to map the UML 2.0 element to the elements in the generated IDL file.
Figure 11. Mapping UML elements to new names
- You can select the UML element and specify the Mapped Name for it. You can rename UML components with either a simple identifier or with a valid partial path that is relative to the target container in which the IDL file is generated. The path should end with the name of the IDL file. For example, if you rename ComponentA as dirA\A, the transformation generates A.idl in the directory named dirA, instead of in the top level of the target container.
- Under the common tab of the Run Transformation wizard (Figure 12), you can specify whether you want to log the transformation execution or not and whether this configuration should come in the Transform menu or not. Selecting Log transformation execution will print a log of all the rules that execute during the transformation. This log is printed out to the Console window. This helps in debugging the transformation and logging error reports (if any) with IBM Tech Support.
Selecting Show in Transform menu will display this transformation configuration as a sub-menu in the Run Transformation menu. This helps in running this configuration directly without bringing up this dialog for each application of the transformation.
Figure 12. The Common tab of the Run Transformation wizard
- Now if you click Apply and then Run, Transformation will be executed and IDL files corresponding to the CORBA Model will be generated according to the mapping specified (if specified) in the mapping model. After the transformation executes, you can view the generated IDL files in the package explorer.
- To open the Package Explorer view, you should have Java developer capabilities enabled. You can enable this at Window -> Preferences and select Java Developer in Workbench -> Capabilities. Once the Java developer capability is enabled, select Window -> Show View -> Package Explorer to see the Package Explorer view.
- Double-click on the IDL file generated. This should open the IDL file in the text editor. If transformation executed successfully, the generated IDL should look similar to the file shown in Figure 13.
Figure 13. The generated IDL file
Observe that NamingAuthority.IDL contains the definition of the RegistraionAuthority enumeration as well as the definition of two CORBAStruct classes and the translation_library interface. A complete and correct IDL file was created from the CORBA model using CORBA Transformation.
The next section will have information about how CORBA Transformation is integrated with ClearCase.
ClearCase integration
CORBA Transformation is integrated with ClearCase for source control of generated IDL files. CORBA Transformation also supports parallel development of CORBA IDL files. CORBA Transformation generates IDL files in a simple Eclipse project. To get the IDL files under ClearCase control, you must add the output Eclipse project under ClearCase control. You can follow these steps to achieve this task.
- Create an Eclipse project, say CCIntegrated.
- Run a CORBA Transformation with the target container specified as CCIntegrated.
- Copy this folder and paste it in a ClearCase VOB folder using Windows® Explorer.
- Now, delete this project from the current workspace, along with its content from the file system.
- Click File > Import Existing Project into Workspace.
- Browse and select the project that you copied under the ClearCase VOB folder, and click Finish to import the project into the workspace. This leaves the sources under the VOB folder and only holds a reference from the workspace.
- Connect to ClearCase (if not already connected) from the current workbench, as shown in Figure 14.
Figure 14. Connecting to ClearCase
- A dialog confirms adding the files under ClearCase control. Click OK (Figure 15) and the project is under ClearCase control.
Figure 15. Putting your project under ClearCase control
- If this dialog does not appear in Step 8, you could still right-click on the project in Navigator view, and click Team > Add to Source Control.
- Now when you run the CORBA transformation again, you will be asked to check out the IDL file(s) to regenerate them as shown in Figure 16.
Figure 16. Prompt to check out the appropriate file(s)
- Click OK, and notice that the IDL file has been checked out and regenerated, as shown in Figure 17.
Figure 17. Regenerated IDL file
UML-to-CORBA mapping
Figure 18 lists how the transformation maps UML 2.0 model elements to CORBA IDL.
Figure 18. UML-to-CORBA mapping
The intent of this article was to give you an overview of the CORBA Transformation, and the created model was therefore very simple. You can design very complex CORBA models if you use all the features of CORBA Transformation.
Resources Learn
Get products and technologies
-
IBM Rational Software Architect: Download a trial version from developerWorks. Provides the tools needed to view the Business Contract Model and develop service realization models that can be used to generate implementation code for different architectural styles.
Discuss
About the authors  | |  | Anand Ramdeo is an IBM software engineer. |
 | |  | Subramanian Neelakantan is an IBM software engineer. |
Rate this page
|  |