This post will describes steps to automatically populate process start DataObject from Webdynpro context.

Fist of all I will identify the problem of populating complex DataObjects while starting SAP BPM process via Java api.

I used to write such boiler-plate code to populate  complex DataObjects while starting SAP BPM process via Java (see Fig.1):

And for nice and small DataObjects, in BPM processes this approach works well:

Fig.1 Ordinary approach for DataObject population

But what if we have ugly big DataObject, and we have to repeat this step again and again from one project to another… I suggest to use some custom code for creating

XML from Webdynpro context and JAXB for creating java objects presentation for DataObject XSD defined in process and for populationg this objects with values.

Step 1: Generating POJO classes based on DataObject XSD with JAXB.

This step will require ready-to use DAtaObject XSD and installed JAXB plugin for Eclipse.

You will find XSD under Process development perspective in Data Types/Xsd Files in ProjectExplorer (see fig 2)

Fig.2 XSD file for process context DataObject

Install JAXB lupgin for Exclipse, import XSD file to project where custom code for BPM process starting is (I usually creat enterprise java bean as session facade and process starter helper class for utility purpose).

Than click on XSD file with right mouise button and go >Generate>Jaxb classes.

Step 2: Creating utility class for generating XML from Webdynpro context.

You can find one solution for creating XML from java webdynpro here  Exporting Context Data into XML – Web Dynpro for Java – SAP Library

But I have found some bugs that are related with portal user locale (for differentuser’s  locale there will be different getAttributeAsText presentation, and no escaping characters in this example, so later I place here link for my XML generator class)

Step 3: Populating generated java objects from created XML during runtime (if we need to work with POJO).

While we have String object xml and generated via JAXB classes we can populate last ones with help of such code (Fig. 3):

Fig.3 Populating generated java objects from created XML during runtime.

77 – instantiate JaxbContext object via static factory method

78 – creating Unmarshaller object

79 – creating custom type adapter (in this examle I’ve created Double type adapter)

80 – unmarshalling XML String to POJO with providing it’s class (DataMemos in this case)

81 – getting unmarshalled value

Step 4: Creating DataObject from XML (or from POJO)

We will need commonj.sdo.helper.HelperContext and commonj.sdo.helper.XMLDocument for this purpose, see fig. 4

Fig.4 Creating DataObject from XML during runtime.

So now we can pass this DataObject to SAP BPM API fig. 5

Fig.5 Creating DataObject from XML during runtime.

Later I will describe the reverse automatic process of populating Webdynpro context from taskcontext input DataObject

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply