Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/Web Service API/Structured Data Types as JAXB Objects

Introduction

Currently, IPP WS expects out data in the form of ParametersXto which in turn takes list of ParameterXto. This ParameterXto is easy to use for primitive data types, but for SDTs we (WS Client) further need to create new XmlValueXto with some implementation of org.w3c.dom.Element with childs and/or attributes to form required xml structure.

Here one creates the implementation of the Element, and populate the required xml structure [as per your process SDT] and pass it to XmlValueXto and finally, pass the ParametersXto to the completeActivity method as out data. All this is not suitable/easy for WS consumer to deal with.

This article provides the work around and utility code for IPP WS consumers to enable them to use SDTs as JAXB objects.

Example Process

text goes here;


How normally you can use structured data with the Stardust WS API

 

How to use Structured Data Types as JAXB objects?

 text goes in here;

<source lang="Java">
private static void startProcessAndComleteFistActivityWithJaxbClass()
throws BpmFault, IOException, JAXBException {

ProcessInstanceXto startProcess = workflowService.startProcess(
"TakeInSTDAndShow", null, true, null);

ActivityInstanceXto activateNextActivityForProcess = workflowService
.activateNextActivityForProcess(startProcess.getOid());

Institute institute = new Institute();
institute.setName("Pune university of applied sciences");
institute.setCity("Pune");

StudentData studentData = new StudentData();
studentData.setFname("Tanaji");
studentData.setLname("BB");

ParameterXto para1 = new ParameterXto();
para1.setName("InstituteData");
para1.setType(QNameConstants.QN_BASE64BINARY);
XmlValueXto xmlVal1 = new XmlValueXto();
xmlVal1.getAny().add(JaxbParserUtility.getAsElement(institute));
para1.setXml(xmlVal1);

ParameterXto para2 = new ParameterXto();
para2.setName("StudData");
para2.setType(QNameConstants.QN_BASE64BINARY);
XmlValueXto xmlVal2 = new XmlValueXto();
xmlVal2.getAny().add(JaxbParserUtility.getAsElement(studentData));
para2.setXml(xmlVal2);

ParametersXto outData = new ParametersXto();
outData.getParameter().add(para1);
outData.getParameter().add(para2);

workflowService.completeActivity(activateNextActivityForProcess.getOid(), null, outData, true);
}

</source>

Now lets analyze the code line by line;
• Code at line no 103 to 108, starts the process synchronouly and activates the first activity of the current process instance.
• The code at line no 109 to 116 will be of most interest to you as an Infinity WS consumer or developer. Here Institute and StudentData classes are JAXB objects generated from our Process Model structured types explained above. This means, you are using SDT as POJO and set the required values in an intuitive way.
Note that to make these classes available in your project; you will have to export your structured types as XSD and generate the classes from them. And copy those classes into your client project.
For exporting structured types as XSD and generating the classes from it, refer the respective sections given below.
• Line no 117 to 133, creates the two instances of ParameterXto for InstituteData and StudData each, set the names (as per structure data ids in process model) and types. On line number 121, we know org.w3c.dom.Element type is expected; hence we need to convert our JAXB POJO to XML Element. This is done with the help of getAsElement utility method.
• The getAsElement utility method converts JAXB object to required org.w3c.dom.Element. This method is generic enough to take in any JAXB object and convert it into XML Element. The method source code is given below.

Utility To Convert JAXB objects to XML

source code goes here;

<source lang="Java">
package com.sungard.ipp.bootcamp.ws.client;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.w3c.dom.Element;

import ag.carnot.utils.xml.XmlUtils;

public final class JaxbParserUtility {

public static Element getAsElement(Object dataObj) throws JAXBException,
IOException {

JAXBContext jc = JAXBContext.newInstance(dataObj.getClass()
.getPackage().getName());
Marshaller m = jc.createMarshaller();

ByteArrayOutputStream out = new ByteArrayOutputStream();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(dataObj, out);
out.close();
String tempStr = new String(out.toByteArray());
Element elementSDT = XmlUtils.parseString(tempStr).getDocumentElement();

return elementSDT;

}
}
</source>


 

Back to the top