BPEL document transformation (XML-OO mapping)

Rationale and description

A deployed BPEL document needs to be transformed in a tree structure of objects representing a BPEL process type. Bexee will then use such a tree structure for the execution of processes. This transformation is a XML to OO mapping and within bexee this task is accomplished with the Jakarta Digester tool [Digester]

Briefly, Digester is configured with an xml mapping description which describes how xml elements contained in BPEL documents will be mapped to the correspondent BPEL activities and elements. For the creation of activities, Digester is configured to use factories. Each activity type has its own specialized factory. In the following illustrations the usage of Digester and the creation of BPEL process types, this mapping description is called "bpel-rules.xml".

Digester overwiev

It is possible to let Digester create the objects without using specialized factories, but in the case of bexee it is advantageous to use this customized technique. BPEL activities have complex properties and it is easier to create those properties with specialized factories. In addition, BPEL activities and elements reference other elements, e.g. variables from the same BPEL process type. It is therefore necessary to find other elements (variables, partner links, etc.) and associate them with some activities in the BPEL process.

Elements references

In order to be able to find other elements and activities existing in a BPEL process, the factories used by Digester don't create process elements themselves, but delegate this task to a BPELElementFactory. Such a factory exist only once per BPEL process, therefore all specialized activity and element factories used by Digester use the same BPELElementFactory. Every process element is registered at its creation and can thus be found by other activities at a later time of BPEL document parsing.


Code and configuration excerpts

The following is an excerpt from the Digester xml-oo mapping description "bpel-rules.xml"


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE digester-rules SYSTEM "http://bexee.sourceforge.net/dtd/digester-rules.dtd">
  <!--  -->
  <!-- parsing the Process -->
  <!--  -->
  <pattern value="process">
    <factory-create-rule classname="bexee.model.xmltobpel.ProcessImplFactory"/>
    <!--  -->
    <!-- parsing the PartnerLinks -->
    <!--  -->
    <pattern value="partnerLinks">
      <object-create-rule classname="bexee.model.elements.impl.PartnerLinksImpl"/>
      <pattern value="partnerLink">
        <factory-create-rule classname="bexee.model.xmltobpel.PartnerLinkImplFactory"/>
        <set-next-rule methodname="addPartnerLink"/>
      <set-next-rule methodname="setPartnerLinks"/>
    <!--  -->
    <!-- parsing the Variables -->
    <!--  -->
    <pattern value="variables">
      <object-create-rule classname="bexee.model.elements.impl.VariablesImpl"/>
      <pattern value="variable">
        <factory-create-rule classname="bexee.model.xmltobpel.VariableImplFactory"/>
        <set-next-rule methodname="addVariable"/>
      <set-next-rule methodname="setVariables"/>
  <set-next-rule methodname="setProcess"/>
  <!--  -->
  <!-- parsing the sequence -->
  <!--  -->
  <pattern value="*/sequence">
    <object-create-rule classname="bexee.model.activity.impl.SequenceImpl"/>
    <set-properties-rule />
    <set-next-rule methodname="activity"/>
  <!--  -->
  <!-- parsing receive -->
  <!--  -->
  <pattern value="*/receive">
    <factory-create-rule classname="bexee.model.xmltobpel.ReceiveImplFactory"/>
    <set-next-rule methodname="activity"/>
  <!--  -->
  <!-- parsing invoke -->
  <!--  -->
  <pattern value="*/invoke">
    <factory-create-rule classname="bexee.model.xmltobpel.InvokeImplFactory"/>
    <set-next-rule methodname="activity"/>

The Java code for a factory responsible for the creation of a Receive BPEL activity:


public class ReceiveImplFactory extends AbstractObjectCreationFactory {

    public Object createObject(Attributes attributes) throws Exception {

        BPELElementFactory elementFactory = BPELElementFactory
                .getInstance((BPELProcess) getDigester().getRoot());

        String partnerLink = attributes.getValue(PARTNER_LINK);
        String portType = attributes.getValue(PORT_TYPE);
        String operation = attributes.getValue(OPERATION);
        String variable = attributes.getValue(VARIABLE);
        String createInstance = attributes.getValue(CREATE_INSTANCE);

        return elementFactory.createReceive(getStandardAttributes(attributes),
                partnerLink, portType, operation, variable, createInstance);

As already mentioned, the activity factory only delegates the creation of an Activity to the BPELElementFactory, following an excerpt from this element factory:


public class BPELElementFactory {

    private Map variables = new Hashtable();

    public Variable createVariable(String name, String messageType,
            String type, String element) {

        Variable variable = new VariableImpl();


        variables.put(name, variable);

        return variable;
    public Object createReceive(StandardAttributes standardAttributes,
            String partnerLinkName, String portTypeString, String operation,
            String variableName, String createInstance) {

        PartnerLink partnerLink = retrievePartnerLink(partnerLinkName);
        QName portType = expandToQName(portTypeString);
        Variable variable = retrieveVariable(variableName);

        Receive receive = new ReceiveImpl(standardAttributes, partnerLink,
                portType, operation, variable, createInstance);

        return receive;

    public Variable retrieveVariable(String variableName) {
        if (StringUtils.isNullOrEmpty(variableName)) {
            return null;
        return (Variable) variables.get(variableName);