Chapter 3. Using the COBOL Transformers Generator

Table of Contents

Using ant scripts
COBOL Transformers Generation for an Adapter
COBOL Transformers Generation for a Proxy
Using Eclipse plugins
COBOL Transformers Generation for an Adapter
COBOL Transformers Generation for a Proxy
Using generated tranformers
Running Host/Java Transformers
Running Host/XML Transformers
Running Host/JSON Transformers

We assume you have an XML Schema with COBOL annotations you are ready to turn into Transformers.

We show 2 use cases in the following sections. The Adapter use case is one where you started from a commarea-driven COBOL CICS program (LSFILEAE). The Proxy use case is one where you started from a WSDL (Microsoft LIVE search).

You have the choice between using ant scripts and Eclipse plugins.

Using ant scripts

COBOL Transformers Generation for an Adapter

You can use the build-coxb.xml ant script from the samples/quickstarts/adapter_lsfileae folder as your starting point. It generates Transformers for the LSFILEAE COBOL program which takes the same input and output structure called Dfhcommarea.

Generally, there are 4 things you will need to change in build-coxb.xml in order to adapt it to your needs:

  • Make sure the classpath setting is correct. The fileset should point to the location where you installed LegStar.

  • The xsdFile parameter of the jaxbgen ant task must point to the location of you XML Schema with COBOL annotations.

  • The jaxbPackageName parameter, for both jaxbgen and coxbgen ant tasks, must be set to the same value conforming to your naming standards.

  • The jaxbRootClass parameter of the coxbgen ant task must designate one, or more, JAXB classes that you want to turn into Transformers.

build-coxb.xml executes 3 steps (or targets in ant parlance):

  • The first target, generateJAXB, runs the jaxbgen ant task and turns an XML Schema with COBOL annotations into JAXB classes with COBOL annotations.

    For a complete list of options for the jaxbgen task, you can refer to CobolJAXBGenerator.

  • The second target, compileJAXB, is a regular java compilation step for the JAXB classes previously generated.

  • The third target, generateCOXB, runs the coxbgen ant task and produces the actual Transformers. The generation process reflects on the JAXB classes compiled at the previous step.

    You will notice that the coxbgen ant task takes one or more jaxbRootClass elements. These are needed to designate which JAXB class (or classes) should become a Transformer. You would generally pickup the higher classes in the hierarchy but you don't have to.

    By default you get Java to Host Transformers only. In addition, you can get Host to XML and Host to JSON Transformers (use the xmlTransformers and jsonTransformers options).

    For a complete list of options for the jaxbgen task, you can refer to CoxbBindingGenerator.

The Using generated tranformers section gives examples of code you could write to run Transformers.

COBOL Transformers Generation for a Proxy

You can use the build-coxb.xml ant script from the samples/quickstarts/proxy_ws_cultureinfo folder as your starting point. It generates Transformers for the cultureinfo Web Service which takes the GetInfo structure as its input and the GetInfoResponse structure as its output.

Refer to COBOL Transformers Generation for an Adapter for a description of what you need to customize in build-coxb.xml and how it works.

Assuming you want to customize build-coxb.xml for the Microsoft LIVE search SOAP service. Follow these steps:

  • Change xsdFile parameter of the jaxbgen ant task to point to the location the XML Schema that was produced with the WSDL/XSD Structures Mapping tool.

  • Change the jaxbPackageName parameter, for both jaxbgen and coxbgen, to something like com.microsoft.schemas.msnsearch.

  • Change the jaxbRootClass parameters to Search and SearchResponse, which are the wrapper elements expected and produced by the target LIVE Web Service.

if you execute the ant script as is, you will get a JAXB error:

  [ERROR] A class/interface with the same name "com.microsoft.schemas.msnsearch.SearchResponse" is already in use.

This is because Microsoft uses the same names for Complex Types and Elements in their XML Schemas which confuses JAXB. To solve this, you can use the typeNameSuffix parameter on the jaxbgen task. The Task should now look like this:


        <jaxbgen 
            xsdFile="LIVESearch.xsd"
            targetDir="src"
            jaxbPackageName="com.microsoft.schemas.msnsearch"
            generateIsSetMethod="true"
            serializableUid="1"
            typeNameSuffix="Type"
        />

You can now execute the ant script.

The Using generated tranformers section gives examples of code you could write to run Transformers.