ModelPro™ Java EE Cartridge User’s Guide
v1.01

Revisions
|
Version |
Description |
Author |
Date |
|
1.0 |
Initial Version |
Model Driven Solutions |
4/27/2009 |
|
1.01 |
Explained Primitive Type
Support |
Model Driven Solutions |
5/1/2009 |
Table of Contents
2 Understanding the Provisioning Model
3 Understanding the Provisioned Project
3.1.4 Data Type Implementation Classes
3.2 Web Service Contract Artifacts
4 Implementing Business Logic for the Provisioned Project
4.1 Implementing Services and Entity Classes
ModePro™ Java EE Cartridge, distributed as part of the ModelPro™ provisioning engine, generates Java EE deployable artifacts from UML Platform Independent Models (PIM) based on SoaML standard.
This following is list of the target technology platforms that the JEE cartridge provisions to:
This document describes how a cartridge user can use the Java EE cartridge to automate the generation of Java EE web services implementations. Knowledge or experience in the following technologies areas is required:
In addition, it is assumed that the user is familiar with the Eclipse development environment. Though SoaML examples are used throughout this document, this document is not intended to be a SoaML tutorial. Please refer to the SoaML/ModelPro Tutorials for how to create models using SoaML. In addition, the ModelPro Technical Reference document explains the basic concepts of ModelPro provisioning engine which first time users may find helpful.
The Java EE cartridge produces deployable artifacts based on
a provisioning model, a Platform Specific Model (PSM), contained in the same
UML model file as the SoaML PIM. In the provisioning model, model elements are
annotated with stereotypes defined in the JEE
Provisioning Profile, a UML profile shipped with ModelPro™. The JEE Provisioning
Profile can be accessed at http://portal.modeldriven.org/content/uml-profiles.

Figure 1
As shown in Figure 1, the following are key stereotypes defined in the JEE Provisioning Profile:
An example of a provisioning model is shown in Figure 2.

Figure 2
Two Java EE web service projects would be provisioned from this model. The first project, with the name “Solicitation Management Service” will target the Glassfish application server, while the second one, named “Solicitation Owner Agency” will have JBoss as its target runtime platform. In addition, the cartridge will provision business logic placeholders for the entity classes: Response and Solicitation in the “Solicitation Management Service” project.
As explained in Section 1, deployable artifacts for each participant in the SoaML model are provisioned to an Eclipse project. The contents of the projects provisioned from the example in Figure 2 are shown in Figure 3.

Figure 3
The provisioned project is an EJB web service in compliance with the JAX-WS specifications. Figure 4 shows how various elements specified in the PIM part of the SoaML model are mapped to platform specific artifacts. These artifacts are explained in details in the following sections.

Figure 4
The generated Java artifacts follow a design pattern that reflects the following principals:
As shown in Figure 3, the provisioned Java code is organized in three source folders:
The provisioned project also has the following folders:
The JEE cartridge provisions a participant class with the same name as the participant class specified in the SoaML model. Super classes of the participant class are also provisioned. Ports of the participant are provisioned as attributes. It is expected that the user will modify the provisioned Java code to implement additional business logic. See Section 4 for more details.

Figure 5
For example, the Solicitation Management Service class shown in Figure 5 is provisioned to the following Java code:
abstract public class
SolicitationManager {
… …
private SolicitationResponseInterface response =
createSolicitationResponseInterface();
… …
private SolicitationManagement solicitation =
ceateSolicitationManagement();
… …
public class SolicitationManagementService extends SolicitationManager {
private static
SolicitationManagementService instance;
public static
SolicitationManagementService getInstance() {
if (instance == null)
instance = new SolicitationManagementService();
return instance;
}
/**
* @modifiable
*/
protected SolicitationManagementService() {
}
private SolicitationNotificationInterface getOwnerAgency()
{
return this.getSolicitation().
getSolicitationNotificationInterface();
}
protected SolicitationManagement
createSolicitationManagement() {
…
…
Service interfaces are the port types of the service points defined on a participant. A POJO class is provisioned for each service interface.
If a service interface implements a UML interface, a Java interface is provisioned for that implemented interface.
If a service interface uses a UML interface, a Java interface is provisioned for that used interface. An attribute of the type presenting the used interface is provisioned as an attribute in the service interface class. At runtime, the infrastructure automatically injects a generated proxy implementing the used interface for the developer to use.

Figure 6
For example, the following source code is provisioned for the Solicitation Management service interface shown in Figure 6:
public class SolicitationManagement implements SolicitationManagementInterface {
// used interfaces for this port
private SolicitationNotificationInterface
solicitationNotificationInterface;
public SolicitationNotificationInterface
getSolicitationNotificationInterface() {
return solicitationNotificationInterface;
}
public void
setSolicitationNotificationInterface(
SolicitationNotificationInterface
_usedInterface) {
this.solicitationNotificationInterface = _usedInterface;
}
// Implemented interface Solicitation
Management Interface operations
public
org.modeldriven.examples.informationmodel.Solicitation
getSolicitation(
org.modeldriven.examples.messagingmodel.GetSolicitation
request)
throws
org.modeldriven.examples.informationmodel.RecordNotFoundException
{
… …
A Java interface is provisioned for each application data type referenced directly or indirectly from the service interfaces, as well as any additional UML class with the Entity stereotype. For example, a structure shown in Figure 7 will produce the following Java classes:

Figure 7
As shown in the SolicitationManagement example above, only these interfaces, instead of concrete implementation classes, are referenced in the generated code for service interfaces. Using interfaces as the contract between the business logic implementation code and the code handling web service interface, i.e. the participant and service interface classes, allows a clean separation of concerns. At the same time, they help work around the Java language limitation that only single inheritances are allowed for concrete classes.
There are a few additional features provided for classes with Entity stereotypes:
The following is an example of the provisioned entity interface:
public interface Solicitation extends Identifiable
{
public static class ID implements java.io.Serializable {
private String solicitationId;
… …
public static class Reference implements
org.modeldriven.modelpro.soapro.util.Reference<Solicitation>
{
private ID id;
public Reference() {
}
public Reference(Solicitation entity) {
this((ID) entity.id());
}
public Reference(ID id) {
this.id = id;
}
… …
The
cartridge also supports a number of primitive data types, as explained in Section
5.1.
In addition to the interfaces, the cartridge also provides a concrete implementation class for all the data types. If a data type has multiple superclasses, such as the Woman and Minority Owned Small Business class shown in Figure 8, only the first super class in the model is provisioned using the standard Java class extension mechanism, as shown in the following example:
public class WomanAndMinorityOwnedBusiness_Impl extends
SmallAndDisadvantagedBusiness_Impl
implements Serializable, WomanAndMinorityOwnedBusiness
{
… …

Figure 8
The implementation class defines a convenient operation to convert of any object implementing the message type interface to a concrete implementation class, for example, the following operation
static
SmallAndDisadvantagedBusiness_Impl.from(
SmallAndDisadvantagedBusiness o)
Will take any object implementing the SmallAndDisadvantagedBusiness interface and returns an instance of a concrete implementation class, which may be a subclass of the SmallAndDisadvantagedBusiness_Impl class.
Exceptions
can be specified in the UML model through the “raisedException” property of an operation. For the provisioned Java
code, the following get provisioned for a raisedException:
The
provisioned POJO operations for service interfaces now declare exceptions in
their “throws” clause, and the provisioned web service implementation and web
service proxies for used interfaces translate the exception to faults defined
in the WSDL.
There are a few limitation imposed by web service technologies. For example, multiple class inheritances are not supported by the Java language and XML schemas. In addition, POJO service implementations in JAX-WS do not handle polymorphism well.
To get around these technology limitations, the data types used in JAX-WS and XML schemas flatten all inheritances through aggregation, and additional utility classes are provisioned to handle transformation between the flat object structure used in the web service implementations and the POJO interfaces, as illustrated in Figure 9. These utility classes are located under the cartridge.src folder.

Figure 9
XML Schemas and WSDLs are provisioned. Because multiple inheritances are not supported by XML schemas, XML schemas have flat structures. The following is a segment of the XML schema provisioned for the classes shown in Figure 8:
<xsd:complexType name="SmallBusiness__Part">
<xsd:sequence>
<xsd:element name="revenue" type="xsd:double"
minOccurs="1"
maxOccurs="1" />
<xsd:element name="size" type="xsd:int"
minOccurs="1"
maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="SmallBusiness">
<xsd:sequence>
<xsd:element name="WomanAndMinorityOwnedSmallBusinessPart"
type="InformationModel1:WomanAndMinorityOwnedSmallBusiness__Part"
minOccurs="0" maxOccurs="1"
/>
<xsd:element name="SmallBusinessPart"
type="InformationModel1:SmallBusiness__Part"
minOccurs="1" maxOccurs="1"
/>
<xsd:element name="SmallAndDisadvantagedBusinessPart"
type="InformationModel1:SmallAndDisadvantagedBusiness__Part"
minOccurs="1" maxOccurs="1"
/>
<xsd:element name="VendorPart"
type="InformationModel1:Vendor__Part"
minOccurs="1" maxOccurs="1"
/>
<xsd:element name="WomanAndMinorityOwnedBusinessPart"
type="InformationModel1:WomanAndMinorityOwnedBusiness__Part"
minOccurs="0" maxOccurs="1"
/>
</xsd:sequence>
</xsd:complexType>
The Java EE developer implements the service by modifying the generated code for the participant. For example,
protected SolicitationManagement
createSolicitationManagement() {
// TODO: Override Default Behavior here
return
new SolicitationManagement() {
… …
Similarly, the cartridge provisions an implementation class, under the user.src folder, for each entity class with the Entity Override stereotype. The developer overrides superclass operations in these classes to provide additional capabilities.
If a service interfaces has dependency on a used interface, proxies are provisioned and injected into the service interface POJO code, transparent to the business logic developer.
By default, the cartridge assumes that the used interface is realized by a web service at the endpoint specified by the value of the usedInterfaceAddress tag in the provisioning model. However, this address is overridden at runtime through one of two ways:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://_jaxws.calculator.example.soapro.modelpro.modeldriven.org/Calculator/calculateRequest</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>http://handlerprovider/service</wsa:Address>
<wsa:ReferenceParameters>
<propertiesRequiredByThePartner/>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
</soapenv:Header>
<soapenv:Body>
……
</soapenv:Body>
</soapenv:Envelope>
The reply-to address will be used for all subsequent messages.
((BindingProvider)
getCalculationResultHandlerInterface())
.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://someurl/");
ModelPro™ provisioning engine is built on a set of open source technologies, including the Eclipse Modeling Framework (EMF). In particular, ModelPro uses EMF UML2 as its metamodel. However, EMF only supports a very limited number of primitive data types, comparing to the rich set of native data types supported by both the Java programming language and XML schemas. Therefore, ModelPro includes an optional Model Library that defines a set of primitive types that can be used by the model developer. The Model Library can be accessed at http://portal.modeldriven.org/content/uml-profiles.

Figure 10
The primitive types defined in the Model Library are shown in the Figure 10. The table below explains how these types are mapped to the data types defined in the Java language and XML schemas.
|
Model Type |
Java Type |
Schema Type |
|
Value |
-- |
-- |
|
Number |
-- |
-- |
|
Boolean |
boolean |
boolean |
|
Integer |
int |
int |
|
Byte |
byte |
byte |
|
Short |
short |
short |
|
Long |
long |
long |
|
Natural |
java.math.BigInteger |
nonNegativeInteger |
|
Real |
java.math.BigDecimal |
decimal |
|
Float |
float |
float |
|
Double |
double |
double |
|
Decimal |
java.math.BigDecimal |
decimal |
|
String |
java.lang.String |
string |
|
Simple String |
java.lang.String |
string |
|
Text |
java.lang.String |
string |
|
Date |
java.util.Calendar |
dateTime |
|
URI |
java.net.URI |
anyURI |
The data type mapping used by ModelPro is the same as the default mapping defined in the Java Architecture for XML Binding (JAXB) specification, with the following exceptions: