About the JavaCompute node JAXB transformation sample

This sample demonstrates the use of Java Architecture for XML Binding (JAXB) with a JavaCompute node to transform message data.

You can use JAXB with Java applications to work with Java object classes by using getter and setter methods. This scenario transforms a simplified sales envelope message that contains invoice records into a processed sales message that contains statement records.

The input and output messages are defined by XML Schema in a IBM Integration library:

  1. JavaComputeNodeJAXBSampleLibrary/SaleEnvelope.xsd
  2. JavaComputeNodeJAXBSampleLibrary/ProcessedSales.xsd
These XML Schema files have been bound into Java object classes by using the JAXB 2.0 schema compiler that is supplied with IBM Integration Bus, and are contained in the Java project "JavaComputeNodeJAXBSampleLibraryJava".

The JAXB Java object classes are used in the JavaCompute node Java class JavaComputeJAXBSampleApplicationJava\com\ibm\sample\JavaComputeNodeJAXBTransform_JAXBSalesTransform.java. This Java class was created by using the "New Java Compute Node Class" wizard, and is called by the JavaCompute node "JAXB Sales Transform". The following code completes the transformation by stepping through the Java object classes, unmarshalling the input message, building Java objects to build the output message, and marshalling the Java objects to build the output from the node:

SaleEnvelope saleEnvelope = (SaleEnvelope)inMsgJavaObj;
StatementList statementList = new StatementList();

List<SaleListType> inSaleLists = saleEnvelope.getSaleList();
for(SaleListType inSaleLst : inSaleLists) {
	List<Invoice> inInvoices = inSaleLst.getInvoice();
	for (Invoice inInv : inInvoices) {
		StatementType outStat = new StatementType();
		outStat.setStyle("Full");
		outStat.setType("Monthly");
		CustomerType outCust = new CustomerType();
		outCust.setInitials(inInv.getInitial().get(0) + inInv.getInitial().get(1));
		outCust.setName(inInv.getSurname());
		outStat.setCustomer(outCust);
		PurchasesType outPurch = new PurchasesType();
		List<ItemType> inItems = inInv.getItem();
		BigDecimal  sumCost = new BigDecimal("0");
		for (ItemType inItem : inItems) {
			BigDecimal outCost = inItem.getPrice().multiply(costMultipler);
			sumCost = sumCost.add(outCost.multiply(new BigDecimal(inItem.getQuantity())));
			ArticleType outArtic = new ArticleType();
			outArtic.setCost(outCost.toPlainString());
			outArtic.setDesc(inItem.getDescription());
			outArtic.setQty(inItem.getQuantity().toString());
			outPurch.getArticle().add(outArtic);
		}
		outStat.setPurchases(outPurch);
		outStat.setAmount(sumCost.toPlainString());

		statementList.getStatement().add(outStat);
	}
}
Object outMsgJavaObj = statementList;

For more information see, Using JAXB with a JavaCompute node.

Back to sample home