 | Level: Intermediate Niranjan Vasudevamurthy (niravasu@in.ibm.com), Technology Evangelist, IBM India
02 Oct 2007 UML (Unified Modeling Language) to EGL (Enterprise Generation Language) transformations (using a combination of IBM® Rational® Business Developer Extension and IBM® Rational® Software Architect) allow you to model complex applications graphically. In addition, they enable you to implement EGL services or fully CRUD (create, read, update, and delete) - capable applications with no manual coding. This increases productivity and reduces errors.
Introduction to UML to EGL application transformations
UML (Unified Modeling Language) to EGL (Enterprise Generation Language) transformations (using a combination of Rational Business Developer Extension and Rational Software Architect) allow you to model complex applications graphically. In addition, they enable you to implement EGL services or fully CRUD (create, read, update, and delete)- capable applications with no manual coding. This increases productivity and reduces errors.
You can also perform automated transformations starting from relational database schemas.
The resulting output includes:
- EGL SqlRecords and DataItems
- Data access layer
- Common CRUD operations
- Services or Libraries
- Support functions
- JSF (Java™Server Faces)-based JSPs (JavaServer Pages) and corresponding EGL Handlers
- DDL (Data Definition Language) script for defining the database tables (if the starting point of the transformation is a class diagram)
 |
Editor's Note
The examples in this article use IBM® Rational® Software Architect Version 7.0.0.2, IBM® Rational® Business Developer Extension Version 7.0, and Microsoft® Windows® XP Professional SP2. |
|
Model-driven development: Generating source code from UML models
You can use a transformation to generate source code from a UML model. Before you can run the transformation, you will need to create a transformation parameters model file, and then apply those parameters to the UML model.
In general, model-driven development (MDD) follows these steps:
- Model your application with a UML model that describes the functionality at the highest level.
- Choose the UML to EGL transformation.
- Create a transformation parameters model (TPM) file, which is a file tied to the UML model that describes how to translate the UML elements into elements in the source language. The TPM file contains information such as how to convert types and names into the source language, and how the output code should be structured.
- Run the transformations and create code in the output language.
- Edit and implement the output code.
Creating a new UML project and class diagram
Before you run the transformation, you will model your application with a UML model. From the high-level perspective, the steps that are necessary to create a UML model include:
- Launch Rational Software Architect.
- Create a UML modeling project and a default class diagram.
- Add classes to the class diagram, which will be the input for UML to EGL transformation.
Launch Rational Software Architect
- Select IBM Rational Software Architect from the Windows Program menu, or select IBM Software Development Platform>IBM Rational Software Architect > IBM Rational Software Architect from the Start menu, as shown in Figure 1.
Figure 1. Launching Rational Software Architect
- This will launch the IBM® Rational® Software Delivery Platform, which will initially prompt you for a workspace. Enter
C:\RBDWrkSpace and click OK.
Create a UML modeling project
- Create a new UML project by selecting File>New>Other>UML Project.
- Name it
EGLUMLProject, as shown in Figure 2.
Figure 2. Creating and naming the project
- Click Next and select Blank Model from the templates.
- Name the model
EGLUMLModel.
- Leave the default diagram as Class Diagram and click Finish, as shown in Figure 3.
Figure 3. Creating a new UML model from a standard template
Adding classes to the class diagram
- Create two classes (Student and Seminar) in the class diagram. The attributes for both the classes should be created as shown in Table 1.
Table 1. Create two classes with these attributes
| Class name | Attributes |
|---|
|
Student Class
|
- Student_ID:Integer
- Name:String
- Address:String
- PhoneNumber:Integer
| |
Seminar Class
|
- Seminar_ID:Integer
- Name:String
- Seminar_Fees:Integer
|
- Add a One-to-One Association relationship between these two classes, as shown in Figure 4.
Figure 4. One-to-one association
Mapping UML objects to EGL objects
The UML to EGL transformation recognizes a set of UML model elements to perform the transformation. The following list describes the recognized elements, as well as the output generated during the transformation for the element.
-
Package: All UML packages result in the creation of an EGL package.
-
Class: A class in the UML model represents a database table. For each class in the model, the following are created:
- EGL SqlRecord
- A table definition in the DDL (this definition is located in the <project> /scripts/data/createTables.sql directory, where <project> is the location of the project)
- A library or service containing functions for performing create, read, update, and delete operations on the class
- A search/list JSP and corresponding
Pagehandler functions that provide search operations on the database table and present view lists of results
- A detail JSP and corresponding
Pagehandler functions for displaying the details of a specific database row (add, update, and delete operations can also be performed through the detail pages)
-
Operation: From each operation element a function stub in the data access library is generated, and each operation parameter becomes an EGL parameter.
-
Attribute : Each attribute element in the UML model represents a database column. For each Attribute, the following is generated:
- An EGL SqlRecord Field
- A column definition in the DDL
-
Association: An association element represents the relationship between two end classes. Associations with more than two end classes are ignored during the transformation. The following is generated for an association:
- Foreign key definitions in the DDL
- Columns inserted into the database tables (representing the association ends)
 |
Creating a new EGL Web project for the transformation
The EGL Web project contains the EGL code, Web pages, and a sample database, all of which make up the logic, data, and interface of the application. The Enterprise Application Resource project (EAR project) contains information about deploying an application in the Java™ 2 Platform, Enterprise Edition (J2EE) framework, because the project will have a Web interface, you need to create an EGL Web project, not an EGL project.
Creating a new EGL Web project for the transformation
- Select File > New > Other.
- Select EGL Web Project and click Next.
- Name the project
EGLWeb7.
- Also create a new EAR Project by clicking New under the EAR Membership. Call it
EGLWeb7EAR, as shown in Figure 5.
- Click Finish and do not switch to Web perspective when asked.
Figure 5. Creating an EGL-enabled Web project
Creating the transformation parameters model (TPM) file
This section explains you how to create a new TPM file. A TPM file contains the metadata that describes how to transform a UML file to EGL code.
Create a TPM file by performing the following steps:
- Right-Click the UML Model (in this example it would be EGLUMLModel) and click Edit Transformation Parameters, as shown in Figure 6.
Figure 6. Opening the edit dialog
- In the Create a New TPM file window, make sure that your UML file is listed in the Target Model field.
- Select the EGL Web project for the new TPM File.
- Click the Browse button in the Folder section and select the EGL Web project that you created previously, as shown in Figure 7.
- Click the Finish button.
Figure 7. Specifying settings for a new TPM file
Configuring the TPM file
The TPM file allows you to customize the transformation of a UML model to source code.
The steps to configure a TPM file include the following:
- Select the UML to EGL transformation
- Specify class transformation parameters
- Specify the Key column for classes
- Configure primitive type parameters
Select the UML to EGL transformation
- Open the TPM file by double-clicking it in the Project Explorer view.
- At the top right corner of the editor, select the Manage applied transformations checkbox. This opens the Manage Your Transformation Parameters window, as shown in Figure 8.
Figure 8. Transformation Parameters Editor
- 3. Move the transformations that you want to use into the Selected Transforms list by clicking a transformation in the Available Transforms list and then clicking Add, as shown in Figure 9.
- 4. Click OK.
Figure 9. Selecting available transformations
Specifying class transformation parameters
Figure 10 shows the parameters that apply to the UML class element. Right-click the class to select EGL Application Transformation.
Figure 10. Specify database, page, and button options
-
Schema name: The name of the database schema to which the table being transformed belongs. If a schema name is not specified, the name of the model will be used.
-
Table name: The name of the database table represented by the class. If a table name is not specified, the class name is used.
-
Record name:The name of the EGL SqlRecord that represents the class. If a record name is not specified, the class name is used. If defaulting to class name, the transformation may alias the class name to ensure that it is a valid EGL name.
-
List/Search Page: The title that is added to the JSP representing the list view of the class. The default value is
class_name List Page, where class_name is the name of the class.
-
Details Page: The title that will be added to the JSP representing the detail view of the class. The default value is
class_name List Page, where class_name is the name of the class.
-
Add Button: Label that will be displayed on the Add button in JSPs. The default value is
Add.
-
Delete Button: Label that will be displayed on the Delete button in JSPs. The default value is
Delete.
-
Update Button: Label that will be displayed on the Update button in JSPs. The default value is
Update.
-
Search Button: Label that will be displayed on the Search button in JSPs. The default value is
Search.
-
Maximum record rows per page: The number of result set rows that will be displayed per page in the list JSP. The default value is
5.
Specify the Key column for the classes
- Expand the Student class.
- Select the
Student_ID attribute, then right-click and select EGL Application Transformation.
- In the Configure property parameters for EGL Application transformation section, select the Is Key Column checkbox, as shown in Figure 11.
Figure 11. Specifying the Key column for Student
- Configure the Key property for the Seminar class. Expand the Seminar class.
- Select the
Seminar_ID attribute, then right-click it and select EGL Application Transformation.
- In the Configure property parameters for EGL Application transformation section, select the Is Key Column checkbox, as shown in Figure 12.
Figure 12. Specifying the Key column for Seminar Transformation
Configuring the primitive type parameters for EGL Application Transformation
The parameters in this category are used to define UML data types, allowing you to expand the data types that can be associated with an UML attribute.
To specify the parameters to be used by the EGL Application Transformation when transforming a UML primitive type element, follow these steps.
- Expand the Primitive types under the list of objects defined in the UML Model.
- Select the defined primitive type, right-click it and select EGL Application Transformation.
- Under the Configure primitive type parameters section, select the appropriate EGL type.
- In this example, for the Date primitive type in the UML model, select the
DATE
EGL Type, as shown in Figure 13. If no appropriate EGL type is selected for a UML primitive type, then a default of String type will be created.
Figure 13. Specify parameters to be used by the EGL Application Transformation
Run the Transformation
To generate the EGL code from the UML model, perform the following steps.
- 1. Click the Run transformation button in the Transformation parameters file, as shown in Figure 14.
- 2. Click Finish.
Figure 14. Select one of the objects defined in the business model
After the transformation runs, there are several new EGL packages in the EGL Source folder of the EGL Web Project (in this case, EGLWeb7) which includes eglumlmodel.data, eglumlmodel.access, and eglumlmodel.primitivetypes.data.
-
eglumlmodel.data holds the records.
-
eglumlmodel.access package holds the libraries.
-
eglumlmodel.primitivetypes.data package holds the dataitems.
Note: In the above packages, "eglumlmodel" is prefixed with the name of the UML model from which EGL code is generated.
Additionally, DDL script for defining the database tables is also generated. The SQL file is stored under the <project>/scripts/data/createTables.sql directory, where <project> is the location of the project.
Finally, JSF-based JSPs and corresponding EGL Handlers are also generated.
Resources Learn
-
Read "IBM Rational Business Developer Extension: An executive overview" Rational Business Developer Extension provides development teams with a language IBM introduced in 2006, Enterprise Generation Language (EGL). This article describes the reasons IBM developed EGL and discusses how IT organizations can use it to become more productive, more quickly in today's Web- and services-based arena.
-
Read "How does EGL fit into the IBM Rational and WebSphere software portfolios?" See how EGL is tightly integrated into the IBM Rational software portfolio.
-
Visit the Enterprise Generation Language area on developerWorks for articles, tutorials, courses, and other technical information.
-
Subscribe to the developerWorks Rational zone newsletter. Keep up with developerWorks Rational content. Every other week, you'll receive updates on the latest technical resources and best practices for the Rational Software Delivery Platform.
-
Browse the technology bookstore for books on these and other technical topics.
- Stay current with developerWorks technical events and Webcasts.
-
IBM® Rational® Business Developer Extension product page: Find technical documentation, how-to articles, education, downloads, and product information about Rational Business Developer Extension.
Get products and technologies
Discuss
About the author  | |  | Niranjan is a Technology Evangelist. He works for IBM at India Software Labs, Bangalore on Rational tools. |
Rate this page
|  |