Add the bridge code

The project uses a Java class, BookOperation.java, that needs to be imported into your project.

This code converts the instance data types from the Web service to types for the COBOL application and do the appropriate initialization for the COBOL application.

  1. Right click on the Java Resources\src folder in Project Explorer and select Import > Import > General > File System.
  2. Click Next.
  3. Click Browse and navigate to <tutorial_source_folder>\DynWebTest1\src.
  4. Click OK.
  5. Select BookOperation.java in the right-hand pane.
  6. Click Finish to import the file into the project.
  7. Open BookOperation.java in the editor.
  8. Near the top of the file, update the following line to hold the location of bookfile.dat on the server machine.
     public static final String BOOK_FILE = "<tutorial_source_folder>\\DataFiles\\bookfile.dat"; 
  9. Save the file. The project builds automatically, but in this case the code will have compiled with errors. This is because some of the types used are in the COBOL projects.

Comments

In the outline view are the methods readBook(), nextBook(), deleteBook(), and addBook(), which receive the instance data from the Web service. Each in turn calls a doOperation() method which then converts the data into type of a similar structure for the COBOL application.

The conversion to COBOL is made easier by the types created by SMARTLINKAGE (Details and StatusGroup) allowing a transfer of fields between the Web service types and the ones for the COBOL application. These transfers are done in the methods getDetails() and getBookReturnE().

The final method of note is this overload of doOperation().

static private BookReturnE doOperation(String action, Details details, IRunUnit runUnit)
	{		
		     StatusGroup statusGroup = getObject(StatusGroup.class, runUnit);
		
	     	BookWrapper bookWrapper = getObject(BookWrapper.class, runUnit);		
	     	bookWrapper.setfilename(BOOK_FILE);				
	     	bookWrapper.BookWrapper(action, details, statusGroup);
		
	     	return getBookReturnE(details, statusGroup);
	}

The method invoke bookWrapper.BookWrapper(action, details, statusGroup); calls into the COBOL application and was added to the class by the SMARTLINKAGE feature.

The methods of this class can be static as they don't have any instance data and it reduces the number of objects that are created and garbage collected.

Note the use of run units. These are used to isolate one Web service request from another. Each COBOL program, the subprograms it calls, and any resources such as data files are all self-contained within the run unit and separate from other run units using the same programs.

The next step is to update the four methods in BookLegacySkeleton class to call the appropriate methods in BookOperation class.