In this article, part 8 in the "Architecting on demand solutions" series, you use IBM Rational Software Architect Enterprise Patterns to rapidly build J2EE applications. Rational Software Architect (RSA) is an Eclipse-based integrated design and development tool that leverages model-driven development (MDD) to incorporate best practices in creating applications and services. Rational Software Architect helps you:
- Develop applications more productively than ever.
- Exploit the latest in modeling language technology.
- Review and control the structure of your Java applications.
- Leverage an open and extensible modeling platform.
- Simplify your design and development tool solution.
- Integrate with other facets of the life cycle.
Rational Software Architect includes extensible frameworks for patterns and transformations that allow best practices to be codified, cataloged, and reused. Patterns assist in building models at a given level of abstraction; using Enterprise Patterns let you construct and maintain applications at a high level of abstraction. Transformations act upon a model to produce other model artifacts or appropriate source artifacts. Enterprise Patterns extend the transformations delivered with Rational Software Architect to generate source code for the design concepts it represents.
Enterprise Patterns leverage Service Data Objects (SDO) for data transfer. SDO is a specification for a programming model that unifies data programming across data source types and provides robust support for disconnected data access with optimistic concurrency control on updates. SDOs enable applications, tools, and frameworks to more easily query, view, bind, update, and introspect data.
Overview of RSA Enterprise Patterns
Enterprise Patterns are packaged as a reusable asset that can be imported and installed into Rational Software Architect. The patterns include:
- Session Facade
- A Session Facade encapsulates access to a set of remote business services and business objects, such as entity beans. The Session Facade pattern provides a default create, retrieve, update, delete (CRUD) and retrieve all implementation to coordinate interactions between the entity beans and invoking clients. Additional business methods can be added to the Session Facade. Similarly, any business methods on the entity beans other than attribute get/set operations are also represented on the Session Facade.
- Business Delegate
- The Business Delegate pattern decouples a client from a business service. Business service characteristics related to remoteness and technology choices are hidden from the client. The client view to the business service is a plain old Java object (POJO). This view allows the client to focus on the semantics of the business service and much less on the syntax.
- Message Facade
- The Message Facade pattern is used when a client wants to invoke an otherwise synchronous remote service asynchronously. It is implemented as a message-driven bean (MDB). By creating a Java Message Service (JMS) message, a client is free to continue processing rather than wait for the response and can leverage guaranteed delivery capabilities of the messaging service provider.
- Data Access Object
- The Data Access Object pattern provides an API for maintaining enterprise data held in a persistence store. This pattern is frequently used when an application chooses not to use Enterprise JavaBeans (EJB) components, or the persistent store can't be supported by container-managed persistence (CMP) entity beans. This implementation provides a default CRUD API leveraging mutable data transfer objects implemented as dynamic SDOs. The user can modify the API if they want. Dynamic SDOs lose compile-time type safety for the transfer data, but allow more flexibility in the format and traversal of the data returned from persistent storage.
Installing Enterprise Patterns
Enterprise Patterns require Rational Software Architect Version 6.0.0.1. If you've already installed Rational Software Architect 6.0, you can use the Rational Product Updater to update it.
Installing Enterprise Patterns requires three simple steps:
First, use the XDE Repository Connection wizard to connect to the reusable asset (RAS) repository, as shown below. (Enter http://www-128.ibm.com/developerworks/product/rational/rsa/ras in the RAS Asset Explorer window).
Note: This URL is accessible only through the RAS Asset Explorer, not from a Web browser. For more information on importing reusable assets, please see the help topic titled "Importing RAS Assets" in Rational Software Architect Help.
Connect to the reusable asset repository using the Rational XDE Repository Connection wizard
Next, open the Asset Explorer in Rational Software Architect, shown below. Navigate to the Enterprise Patterns folder and select Import.
Opening Asset Explorer
Now, use the Import RAS Asset wizard to import the Enterprise Patterns asset from the repository, shown below, and you are done.
Import the Enteprise Patterns asset
After you restart Rational Software Architect, the Enterprise Patterns appear in the Pattern Explorer, shown here.
The Enterprise Patterns appear in Pattern Explorer

Revisiting the ODFinance scenario
This article builds on the ODFinance theme introduced in earlier articles in the series. A common need in any business is the ability to create, retrieve, update, and delete records from persistent storage. The records represent business domain objects. In this article, you learn how to use the Enterprise Patterns to model and implement such applications. We'll use the ODFinance customer and account business objects as the nucleus of this application, as shown in Figure 1.
Figure 1. ODFinance business objects
For this scenario, entity beans represent the business objects with a Session Facade service providing access to them. The Session Facade provides an interface with strongly typed static SDOs. This approach leverages other features of Rational Software Architect for J2EE development. The scenario also demonstrates how you can use the Business Delegate and Message Facade patterns, as shown in Figure 2.
Figure 2. Overview of the solution architecture for the completed scenario
Applying the Session Facade pattern
The Enterprise Patterns, after imported and installed into Rational Software Architect, are found in the Pattern Explorer under the Enterprise Patterns category.
To begin, open the modeling perspective. Select Window > Open Perspective > Other, as shown in Figure 3.
Figure 3. Open perspective
Choose the Modeling perspective from the resulting dialog, as shown in Figure 4.
Figure 4. Select perspective
Create a new Unified Modeling Language (UML) modeling project with a blank model contained in it. Name the model anything you like; for example, PatternsSample.
Figure 5. UML model creation
Select this newly created model. Be sure to select the model, not the *.emx file, as shown in Figure 6.
Figure 6. Model selection
Go to the Properties view at the bottom of the workbench and select the Profiles tab, as shown in Figure 7.
Figure 7. Model properties
Click Add Profile. The EJB transformation profile must be added to the model, as shown in Figure 8.
Figure 8. Add Profile
Now back in the Model Explorer, right-click on the UML model on the left side and make the selection shown in Figure 9.
Figure 9. Package creation
This creates a UML package to contain the business objects. The business objects shown in Figure 10 are also created within this new UML Package.
Figure 10. ODFinance business objects
After creating the business objects, you're ready to use the Enterprise Patterns. The Pattern Explorer view is not opened by default. To open it, select Window > Show View > Other. Next, select Pattern Explorer, as shown in Figure 11.
Figure 11. Show View
In the Pattern Explorer view, expand the Enterprise Patterns folder to browse the available patterns, as shown in Figure 12.
Figure 12. Pattern Explorer
To use a pattern, you can drag and drop it from the Pattern Explorer onto a class diagram, as shown in Figure 13. This creates a pattern instance showing the parameters that need arguments bound to them. The pattern instance is used to record the binding of model objects to parameters on the pattern.
Figure 13. UML modeling
You interact with the pattern instance to provide values, or arguments, to its parameters. In this example, Customer is dropped on the Entity Bean pattern parameter to bind it. The Session Facade class can be created by interacting with the parameter. You can do this by hovering the mouse pointer over the parameter and selecting one of the icons in the balloon that appears. An existing class in the model could also be used, providing it is stereotyped with EJBTransformProfile::Service (<<Service>>) and is not used in another Session Facade pattern instance. The UML to EJB transformation uses class stereotypes to guide the code generation. The stereotypes used by the UML to EJB transformation for EJBs are:
- <<Service>> for session beans
- <<Entity>> for entity beans
- <<MessageProcessor>> for MDBs
Figure 14 shows a Session Facade pattern instance with bindings to classes that represent the session facade and entity beans. Dotted lines represent dependency relationships between UML elements and solid lines represent associations.
The methods marked <<alias>> on the AccountingSessionFacade class were generated by the pattern and are placeholders that describe the architecturally significant part of the interface. They represent the operations available on the service and can be used in conjunction with other patterns. These classes will produce two entity beans and a Session Facade implementation when transformed.
Figure 14. Session Facade pattern
Applying the Business Delegate pattern
The Business Delegate pattern is applied next to provide POJO access to the Session Facade. The Business Delegate pattern uses the AccountingSessionFacade class from the previous pattern as the argument for its Business Service parameter. The AccountingBusinessDelegate class is created using the pattern parameter default, which is then renamed to AccountingBusinessDelegate, as shown in Figure 15. The result propagates the <<alias>> methods from the service to the AccountingBusinessDelegate class.
Figure 15. Business Delegate pattern
The code generated in the AccountingBusinessDelegate delegates to the AccountingSessionFacade EJB implementation. Because the Use Remote EJB Interfaces is set to true, the session facade is accessed through its remote interface.
As the Business Service's interface changes, the pattern can be reapplied and retransformed to adapt to the changes.
Applying the Message Facade pattern
The Message Facade pattern uses the AccountingBusinessDelegate as the argument for its Delegate parameter. The AccountingMessageFacade class is created by interacting with the pattern instance to produce the default class. The user may accept the default name or rename the class. In this example, the class was renamed to AccountingMessageFacade to provide more context to its purpose.
Figure 16. Message Facade pattern
The generated code for the AccountingMessageFacade MDB is delegated to each of the methods on the AccountingBusinessDelegate class.
Using the Data Access Object pattern
The ODFinance Customer and Account business objects are implemented as entity beans in this scenario. Alternatively, they could be implemented as Data Access Objects (DAO). The Data Access Object pattern is a good choice when:
- Alternate access to persistent data other than entity beans is desired. For example, returned data that is not easily represented as entity beans (such as complex table joins, partial table row results, unsupported databases, and so on).
- Loosely typed dynamic SDO DataObjects are preferred to strongly typed static SDOs, to reduce the coupling between clients and DAO.
- EJB containers are not desired.
The DAO-based application also has the option of providing access to DAOs from a session bean in order to leverage the session bean's transaction management. Conceptually, the DAO occupies the same role as an entity bean in a Session Bean Facade pattern.
Peforming model to source transformation
Now that a number of patterns have been used to mark up the UML model, Rational Software Architect transforms can be used to transform the model into a set of output artifacts, such as Java code supporting the WebSphere Programming Model.
The Rational Software Architect transformation framework allows selection of a source set of elements that are used to create a new set of target elements. Rational Software Architect comes equipped with a number of transforms, such as UML to EJB and UML to Java transforms. By leveraging the extension mechanisms in RSA, existing transforms can be enhanced.
After installation of the Enterprise Patterns, additional rules and transforms were contributed to the UML to EJB transform through extension points defined in the transformation framework. Transformation of models marked up with the Enterprise Patterns occurs through the UML to EJB transformation.
Launch the UML to EJB transformation against the model, as shown in Figure 17.
Figure 17. UML to EJB transformation
You should see the dialog in Figure 18.
Figure 18. UML to EJB transformation dialog
The transformation wizard collects user input to be used during transformation including the target container (restricted to EJB Projects), local or remote interfaces for entity and session beans, and other generic settings such as mapping models and execution logging.
Most of the generated Java source is complete; however, some user edits are required or desired. Such edit areas are identified by TODO items present in the task list, as shown in Figure 19.
Figure 19. Tasks View
Listing 1 is an example from the Message Facade's MDB implementation.
Listing 1. Message Facade implementation TODO examples
private MethodDetails provideMethodDetails(javax.jms.Message msg) {
MethodDetails methodDetails = null;
int methodKey = 0;
//TODO developer must parse javax.jmx.Message to indicate which method
//to be called. The method maps to a key such as _bizOp1_intStringMap_
switch (methodKey) {
case _getAllCustomerObjects_:
//TODO developer must parse javax.jmx.Message to provide an
argument for getAllCustomerObjects
methodDetails = new MethodDetails(methodKey, null);
break;
case _getCustomerByKey_com_odfinance_accounting_ejb_CustomerKey_:
//TODO developer must parase javax.jmx.Message to provide an
argument for getCustomerByKey
methodDetails = new MethodDetails(methodKey, new Object[] { arg00 });
break;
case _deleteCustomer_com_odfinance_accounting_ejb_sdo_Customer:
//TODO developer must parse javax.jmx.Message to provide an
argument for deleteCustomer
methodDetails = new MethodDetails(methodKey, new Object[] { arg10 });
break;
case _createCustomerSDO_:
//TODO developer must parse javax.jmx.Message to provide and
argument for createCustomerSDO
methodDetails = new MethodDetails(methodKey, null);
break;
}
} |
After the TODO entries in the code are examined and completed, the application is ready to be built and deployed as usual with J2EE development.
As the modeled interfaces of the Business Delegate and Business Service change, the pattern can be reapplied and retransformed to adapt to these changes. The code generation in the transform leverages JMerge from the Eclipse Modeling Framework to accommodate preservation of user edits. This capability allows regeneration of source after making model changes.
This article examined several Rational Software Architect Enterprise Patterns you can use to rapidly build J2EE applications. You learned about the development of best-practice-based applications using patterns and transformations in an MDD environment. Applications using these techniques have consistent designs built by leveraging hardened patterns, and the generated code is specific to the user's application needs. In the example, SDOs are used by the Session Facade as the data-transfer technology instead of proprietary developer-created classes. Although not demonstrated in this article, architects can write their own patterns and transforms using the Rational Software Architect framework; the patterns and transforms can extend existing patterns and transforms in the product. In addition to helping simplify your design and development tool life cycle, Rational Software Architect also extends the function of Rational Application Developer.
| Name | Size | Download method |
|---|---|---|
| i-odoebp8code.zip | 100 KB | HTTP |
Information about download methods
- The article "Model with the Eclipse Modeling Framework, Part 2" (developerWorks, April 2004) discusses how to generate code with Eclipse's Java Emitter Templates.
- The article "Model with the Eclipse Modeling Framework, Part 3" (developerWorks, May 2004) explains how to customize generated models and editors with Eclipse's JMerge.
- Visit WebSphere Application Server for an overview of the product.
- To learn more about Rational Software Architect, visit
Rational Software Architect.
- View an index for
Core Enterprise Patterns.
- The white paper
Next Generation Data Programming: Service Data Objects
(Beatty, Brodsky, Nally, Patel) discusses the motivation behind SDO, presents the SDO architecture and discusses opportunities for further enhancements by vendors in the industry.
- Read the
Reusable Asset Specification documentation.
- Innovate your business with IBM products. Try IBM trial downloads to find out how.

Murray Beaton is an Advisory Software Developer for the On Demand Software Development team. Murray's previous role was as a Technical Team Lead with WebSphere Studio Application Developer. Contact Murray at beatonm@ca.ibm.com.

Billy Rowe is a Senior Software Developer for the On Demand Software Development team. Billy has held various positions within IBM as a developer, architect, and consultant, with his primary focus on developing reusable, object-oriented technologies and frameworks. You can contact Billy at browe@us.ibm.com.

James Abbott is an Advisory Software Developer for the On Demand Software Development team. His major focus is on Patterns and Transforms for model-driven development. During his career, he has worked on a series of model-based application development tools for IBM Rational Software and other companies specializing in J2EE technologies. Contact James at jrabbott@us.ibm.com.
Comments (Undergoing maintenance)

