Chapter 10. Using XML Facade for DOM

In this chapter, we will cover the following recipes:

  • Setting up an XML facade project
  • Generating XML facade using ANT
  • Creating XML facade from XSD
  • Creating XML facade from WSDL
  • Packaging XML facade into JAR
  • Generating Java documents for XML facade
  • Invoking XML facade from BPEL processes
  • Accessing complex types through XML facade
  • Accessing simple types through XML facade

Introduction

The Business Process Execution Language (BPEL) is based on XML, which means that all the internal variables and data are presented in XML. In this book, we cover both BPEL and Java. As both the technologies are complementary, we seek ways to ease the integration of the technologies. In order to handle the XML content from BPEL variables in Java resources (classes), we have a couple of possibilities:

  • Use DOM (Document Object Model) API for Java, where we handle the XML content directly through API calls. An example of such a call would be reading from the input variable:
    oracle.xml.parser.v2.XMLElement input_cf= (oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/client:Cashflows"); 

    We receive the XMLElement class, which we need to handle further, either be assignment, reading of content, iteration, or something else.

  • As an alternative, we can use XML facade though Java Architecture for XML Binding (JAXB). JAXB provides a convenient way of transforming XML to Java or vice-versa. The creation of XML facade is supported through the xjc utility and of course via the JDeveloper IDE. The example code for accessing XML through XML facade is:
    java.util.List<org.packt.cashflow.facade.PrincipalExchange> princEx= cf.getPrincipalExchange(); 

We can see that there is neither XML content nor DOM API anymore. Furthermore, we have to access the whole XML structure represented by Java classes.

Tip

The latest specification of JAXB at the time of writing is 2.2.7, and its specification can be found at the following location: https://jaxb.java.net/.

The purpose of an XML facade operation is the marshalling and un-marshalling of Java classes. When the originated content is presented in XML, we use un-marshalling methods in order to generate the correspondent Java classes. In cases where we have content stored in Java classes and we want to present the content in XML, we use the marshalling methods.

JAXB provides the ability to create XML facade from an XML schema definition or from the WSDL (Web Service Definition/Description Language). The latter method provides a useful approach as we, in most cases, orchestrate web services whose operations are defined in WSDL documents.

Throughout this chapter, we will work on a sample from the banking world. On top of this sample, we will show how to build the XML facade. The sample contains the simple XML types, complex types, elements, and cardinality, so we cover all the essential elements of functionality in XML facade.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset