Overview of UML-to-JSF or -SDO transformation
In this article, I describe how the transformation works and the current limitations. I then walk through an example that takes a UML model of the database, marks it up, generates, and then tests the resulting Web pages.
Let's start with an overview of what the transformation does: It simply takes a marked-up class in the UML model and generates a page for a list of results, which then links to pages to create and update or delete the specific entry (see Figure 1).
Figure 1. UML table to Web pages
If Class A is modelled as related to Class B, then a list of related B items will be shown on the Details page for A (Figure 2), thereby enabling navigation around the data in the database.
Figure 2. UML relationships to Web pages
This transformation can take a significant data model and generate a working Web site for data update and management. The generated Web pages will require additional manual work, because they need to be cosmetically updated to match the UI guidelines for your organization. Or the transformation could be updated to do as much of this as practical by default.
The transformation currently has several limitations:
- It supports only Java™Server Faces and Service Data Objects (SDO) architecture.
- It supports only IBM® DB2® databases (you will need DB2 installed to follow the steps in this article).
- It does not support joins (although this could be achieved through the use of views)
Now that you know a little more about what the transformation does and doesn't do, it's time to install it and use it in an example.
The installation of the UML to JSF/SDO transformation is straight-forward.
- Download the RAS file (Downloads) to a location on your hard drive.
- Start IBM Rational Software Architect and select File > Import.
- Choose RAS > RAS Asset and click Next.
- Browse to the downloaded RAS file and click OK in response to the information warning about installing a feature or plug-in.
- Click Next.
- Select the feature, accept the license agreement, and then click Finish.
- Click OK in the Import Results dialog that says that the import was successful but not enabled for this session.
- When prompted, restart to enable the plug-in.
Now switch to the Modeling perspective and go to Modeling >Transform >New Configuration to confirm that you have the UML to JSF/SDO transformation under IBM Rational Web Transformation.
- Download the zip file to a location on your project.
- Open up Rational Software Architect, and choose Import > General > Existing projects, and then select archived file, and then point at the downloaded zip file.
This will then import the source projects into your workspace, and you can modify the transformation as desired.
Now you're ready to complete this model example.
The project is contained as an archived file, inside the documentation plug-in.
- Select File > Import, and then General > Existing projects Into workspace.
- Click Next, and then select Archive File > Browse, and browse to the C:\Program Files\IBM\SDP70\plugins directory.
- Open the com.ibm.uk.transformations.umltojsfsdo.doc folder, and select the com.ibm.uk.transformations.umltojsfsdo.example.zip file.
- Select Open, and then click Finish.
In the Project Explorer, you should now have a project called:
com.ibm.uk.transformation.umltojsfsdo.example
- Go to the Modelling perspective.
- Open the model called STORE_SCHEMA.emx (do not open the one with the profile applied, because it has already been marked up).
- Open the Overview diagram (Figure 3).
- Review the model.
Figure 3. Overview diagram
- Select the STORE_SCHEMA model, and go to the Profiles tab on the Properties page.
- Choose Add Profile, and select the CRUD_JSF_pages profile from the deployed profiles list (Figure 4).
Figure 4. Properties tab with applied profile
The model must contain an abstraction of the database.
- Select the model, right-click, and choose to Add UML > Component.
- Call the component
STORE. - Select the STORE component, and in the Properties view, go to the Stereotype tab, choose Apply stereotype, and select DB (Figure 5).
Figure 5. Component stereotype selection
- Now, still in Properties, go to the Advanced tab, and under DB, set the
databaseUser to
db2adminin the Value column.
Figure 6. Component properties
- Select the STORE_SCHEMA model.
- In the Properties view, apply the
Schemastereotype by selecting the Stereotypes tab and then Apply Stereotype > Schema.
The key gen table is the table that is used to generate a primary key on insertion.
- Open the KEYGEN table in Project Explorer, select the SETCOL
attribute, and apply the
PKstereotype.
Figure 7. Project Explorer
To mark up the tables, you need to stereotype them, mark their foreign keys, and align their key gen tables to KEYGEN.
- First, apply the
TableWithCRUDJSFPagesstereotype to these:- ORDER
- PRODUCT
- SALE
- INVENTORY
- STORE
- Then select ORDER,
PRODUCT, SALE, INVENTORY, and STORE, go to the
Advanced tab on the Properties page, and enter
KEYGENin the uniqueKeyTable field under TableWithCRUDJSFPages. - Add the
PKstereotype to the following columns:- INVENTORY.ID
- ORDER.ORDER_ID
- PRODUCT.CODE
- SALE.SALE_ID
- STORE.STORE_ID
- Finally, the product table will be referenced in a drop-down list from
ORDER,INVENTORY and SALE. To display the description, rather than the code, you
need to stereotype the Description column. Apply the
Displaystereotype to PRODUCT.DESCRIPTION.
In the Project Explorer, the completed model should look like Figure 8.
Figure 8. Completed model in Project Explorer
Correctly name the foreign keys
The last step is to make sure that the foreign keys are correctly defined for the relationships.
- Open the Overview diagram tab. Select each composition relationship in turn, and
set the role name at the composition end to
STORE_ID. When you are finished, in the Project Explorer you should now see a STORE_ID column on the INVENTORY, ORDER, and SALE tables. - Select each relationship to the PRODUCT table in turn, and rename the product
role to
PRODUCT_CODE. Again, on completion you should see a PRODUCT_CODE attribute on SALE, INVENTORY, and ORDER. - The model should now look like Figure 9.
Figure 9. Final marked-up model
Transform a marked-up model to create the Web pages
To complete this setup, you need to create the database, configure and run the transformation, and then test the generated artifacts.
- Start the DB2 Control Center, and create a new database called
STORE. - Then select the Schema folder under the database, and choose Create new schema.
- Provide a name of
STORE_SCHEMAand an authorization user name ofdb2admin. - In Rational Software Architect, switch to the Data perspective.
- In the Database Explorer, create a connection to the STORE database, and call
it
STORE. - In the Data Project Explorer, open the ibm.uk.transformations.umltojsfsdo.example project, and select createDatabase.sql from the SQL Scripts folder.
- Right -click, and select Run SQL. Choose to use an existing connection, and choose the store connection created previously.
- Reconnect if necessary, and click Finish.
- In the Data Project Explorer, select insertData.sql, right-click, and select Run SQL. Choose to use an existing connection, and choose the STORE connection already created.
- Reconnect if necessary, and click Finish.
- The database is now set up. You can verify that it is set up OK by going to the Database Explorer and selecting STORE > Schemas > STORE_SCHEMA > Tables.
- Select STORE, right-click, and then select Data > Sample Contents.
You should see three rows returned, as Figure 10 shows.
Figure 10. Results of Store query
Create a transformation configuration
- Return to the Modeling perspective and select Modeling > Transform > New Configuration.
- Enter
UML to JSFas the name. - Within the IBM Rational Web Transformation folder, select UML to JSF/SDO Transformation.
- Then select the example project as the configuration file destination for the transformation configuration (Figure 11).
- When you have finished, click Next.
Figure 11. New Transformation Configuration view
- Choose the model as the source, and select the example project as the target (Figure 12).
Figure 12. Transformation Source and Target view
- Click Next.
- Enter the name of the project that will be created, such as
MyStore, and click Finish.
- Select the transformation configuration from the previous step, right-click, and choose Transform > UML to JSF/SDO Transformation.
- This will generate MyStore Web and MyStoreEAR projects and all of the Web pages required to view, update, create, and delete data in the database.
- From the MyStore project, open the Web site navigation diagram.
The diagram should show the generated Web pages (Figure 13).
Figure 13. Web site navigation diagram
- Change to the Web perspective.
- Start your application server.
- Deploy the EAR file to the application server.
- Select the store_list.jsp file, and choose Run on server.
| Description | Name | Size | Download method |
|---|---|---|---|
| Deployable RAS file | umltojsfsdo_v1.0.8_ras.zip | 5044KB | HTTP |
| Source Code - Archived Eclipse Projects | umltosjfsdo_v1.0.8.zip | 10328KB | HTTP |
Information about download methods
Learn
- In the
Architecture area on developerWorks,
get the resources you need to advance your skills in the architecture arena.
- Visit the
Rational software area on
developerWorks
for technical resources and best practices for Rational Software Delivery Platform
products.
- 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.
Get products and technologies
- Download
trial versions of IBM Rational software.
- Download
IBM product evaluation versions
and get your hands on application development tools and middleware products from
DB2®, Lotus®, Rational®, Tivoli®, and
WebSphere®.
Discuss
- Participate in the discussion forum.
- Check out
developerWorks blogs and
get involved in the
developerWorks community.
-
Rational Software Architect, Data Architect, Software Modeler, Application Developer and Web Developer forum: Ask questions about Rational Software Architect and other architecture management tools.
Comments (Undergoing maintenance)





