This section explains the procedure for creating a client application that calls the binary program of the tutorial on CORBA server applications.
1. Starting the Interstage basis service
1. Starting the Interstage basis service
Before creating CORBA applications, it is necessary that the J2EE execution environment service is started. Because the J2EE execution environment service is not started by default, use the Interstage basis service operation tool to start the service. Refer to "Checking the environment settings of Interstage Application Server".
When the Interstage basis service has already been started by "11.2.2 Developing CORBA Server Applications", this operation is unnecessary.
2. Creating a Project
This section explains how to call a CORBA application using object-oriented COBOL. For details on programming using object-oriented COBOL, refer to the "Interstage Application Server Distributed Application Development Guide (CORBA Service Edition)".
If the COBOL perspective is not displayed, then follow the procedure below to display it:
Select "Window" > "Open Perspective" > "Other" from the menu bar. The "Open Perspective" dialog box is displayed.
Select "COBOL", then click the "OK" button.
Select "File" > "New" > "COBOL Project" from the workbench - a new COBOL project is displayed.
Enter the project name and the save folder. Click the "Next" button.
Setting item | Setting value |
---|---|
Project name | CALCCL |
Contents | Select "Create new project in workspace" |
You can specify target information on this screen. In this tutorial, proceed without specifying anything.
Click the "Next" button.
You can specify the build environment on this screen. Select "Set build environment for CORBA client". Leave the other settings at their default values. Click the "Next" button.
You can select the option "Generate code". Make sure that "COBOL Source" is selected as the code generation wizard, and click the "Finish" button.
3. Creating a Template with COBOL Source Wizard
Create a program template by using the New COBOL Source wizard.
In this tutorial, specify the following COBOL source information.
Setting item | Setting value |
---|---|
Project name | CALCCL |
File name | CALCCL |
PROGRAM-ID | CALCCL |
File comment | (Write any comment.) |
Click the "Finish" button. The "CALCCL.cob" and "CDCORBA.cob(*1)" file is created.
*1: When "Use CDCORBA class" is checked on the "Build Environment" page, this file is created.
4. Editing the Program
Edit the COBOL source generated by the wizard.
Displaying the Template view
1) Select "Window" > "Show View" > "Other" from the workbench menu. The "Show View" is displayed.
2) Select "General" > "Template", and click the "OK" button.
Adding CORBA initialization processing
In the editor, move the cursor to the location at which this processing is to be added. Select "COBOL" > "CORBA" > "Initialize CORBA" from the Template view, then select "Insert" from the context menu to add the processing.
In this tutorial, insert "Initialize CORBA" processing onto line 9 (line number 90) of CALCCL.cob.
Adding CORBA server object search processing
1) In the editor, move the cursor to the location at which this processing is to be added. Select "COBOL" > "CORBA" > "Find CORBA Server Object" from the Template view, then select "Insert with Parameter Value" from the context menu to add the processing.
In this tutorial, create a line immediately under line 19 (line number 100) of CALCCL.cob, and insert "Find CORBA Server Object" there.
2) In the "Input Assistance" dialog that is displayed, specify values for the Replace key as shown below, and click the "OK" button to add the processing.
Adding method invocation processing
1) In the editor, move the cursor to the location at which this processing is to be added. Select "Module Name" > "Interface Name" > "Method" from "CORBA Server Objects" in the Template view, then select "Insert with Parameter Value" from the context menu.
In this tutorial, create a line immediately under line 37 (line number 118) of CALCCL.cob, and insert "addop" method invocation processing there.
Note
To obtain a list of CORBA server objects from the template, Interstage service and the services for management of Interstage(platform services) must be started. If they are not started, restart the workbench.
To start the platform service, use the Interstage Management Service Operation Tool. To start the tool, select "Interstage" > "Studio" > "Interstage Management Service Operation Tool" from the start menu.
2) Specify a value for the Replace key, and click the "OK" button to add the processing.
Add and/or modify necessary data items and processing codes in order to make the source program as shown below.
Note
In this source program, the method invocation processing that has been added last must be modified before the program can be used. If you copy the source program, delete the added method invocation processing before program execution.
000010* 000020 IDENTIFICATION DIVISION. 000030 PROGRAM-ID. CALCCL. 000040 ENVIRONMENT DIVISION. 000050 CONFIGURATION SECTION.
000060 REPOSITORY.
000070* Standard library of ObjectDirector (for repository declaration)
000080 COPY CORBA--REP.
000090* Standard library of naming service (for repository declaration)
000100 COPY CosNaming--REP.
000110* Library output by IDL compiler (for repository declaration)
000120 COPY USCALCSV--REP.
000130* CORBA client development class provided by Interstage Studio
000140 CLASS CDCORBA.
000150
000160 SPECIAL-NAMES.
000170 ARGUMENT-NUMBER IS ARG-NO
000180 ARGUMENT-VALUE IS ARG-VAL
000190 SYMBOLIC CONSTANT
000200* Standard library of ObjectDirector (for constant declaration)
000210 COPY CORBA--CONST.
000220* Standard library of naming service (for constant declaration)
000230 COPY COSNAMING--CONST.
000240* Library output by IDL compiler (for constant declaration)
000250 COPY USCALCSV--CONST.
000260 .
000270 DATA DIVISION. 000280 WORKING-STORAGE SECTION. 000290 COPY CORBA--COPY.
000300 COPY USCALCSV--COPY.
000310 01 L-APL-NAME PIC X(50) VALUE "CALCCL".
000320 01 W-OBJECT OBJECT REFERENCE CORBA-OBJECT.
000330 01 W-TARGET OBJECT REFERENCE SAMPLE-CALCSV.
000340 01 STRUCT1 TYPE SAMPLE-S1.
000350 01 L-RETURN PIC S9(9) COMP-5.
000360 01 L-NAME PIC X(128) VALUE "SAMPLE::CALCSV".
000370 01 ERR-MSG PIC X(128).
000380 01 CDEXCEPTIONMSG OBJECT REFERENCE CORBA-STRING.
000390 01 CDEXCEPTIONCODE TYPE CORBA-LONG.
000400 000410 PROCEDURE DIVISION. 000420 DECLARATIVES.
000430 ERR SECTION.
000440 USE AFTER EXCEPTION SAMPLE-CDEXCEPTION.
000450 MOVE CDEXCEPTIONCODE OF EXCEPTION-OBJECT AS SAMPLE-CDEXCEPTION TO
000451 CDEXCEPTIONCODE.
000460 SET CDEXCEPTIONMSG TO CDEXCEPTIONMSG OF EXCEPTION-OBJECT AS SAMPLE-CDEXCEPTION.
000470 INVOKE CDEXCEPTIONMSG "GET-VALUE" RETURNING ERR-MSG.
000480 DISPLAY ERR-MSG.
000490 END DECLARATIVES.
000500 INVOKE CDCORBA "GET-ORB" USING L-APL-NAME RETURNING L-RETURN. 000510 IF L-RETURN NOT = 0 000520 THEN 000530 DISPLAY "ERROR OCCURRED AT GET-ORB" 000540 END-IF 000550 INVOKE CDCORBA "GET-COSNAMING" RETURNING L-RETURN. 000560 IF L-RETURN NOT = 0 000570 THEN 000580 DISPLAY "ERROR OCCURRED AT GET-COSNAMING" 000590 END-IF 000600 000610 MOVE "SAMPLE::CALCSV" TO L-NAME. 000620 INVOKE CDCORBA "GET-NAMEOBJ" USING L-NAME RETURNING L-RETURN. 000630 IF L-RETURN NOT = 0 000640 THEN 000650 DISPLAY "ERROR OCCURRED AT GET-NAMEOBJ" 000660 END-IF 000670 INVOKE CDCORBA "GET-NAMEOBJR" RETURNING W-OBJECT. 000680 IF W-OBJECT = NULL 000690 THEN 000700 DISPLAY "ERROR OCCURRED AT GET-NAMEOBJR" 000710 END-IF 000720 000730 SET W-TARGET TO NULL. 000740 INVOKE SAMPLE-CALCSV "NARROW" USING W-OBJECT RETURNING W-TARGET. 000750 IF W-TARGET = NULL 000760 THEN 000770 DISPLAY "ERROR OCCURRED AT NARROW" 000780 END-IF 000790 000800* Invocation of server application methods
000810 DISPLAY "Enter the first argument: " WITH NO ADVANCING.
000820 ACCEPT item1 OF STRUCT1.
000830 DISPLAY "Enter the second argument: " WITH NO ADVANCING.
000840 ACCEPT item2 OF STRUCT1.
000850
000860 INVOKE W-TARGET "addop" USING STRUCT1
000870 DISPLAY "Addition result: " result OF STRUCT1.
000880
000890 INVOKE W-TARGET "subop" USING STRUCT1
000900 DISPLAY "Subtraction result: " result OF STRUCT1.
000910
000920 MOVE 0 TO CDEXCEPTIONCODE.
000930 DISPLAY "Multiplication result: " WITH NO ADVANCING.
000940 INVOKE W-TARGET "mltop" USING STRUCT1
000950 IF CDEXCEPTIONCODE NOT = -1 THEN
000960 DISPLAY result OF STRUCT1
000970 END-IF.
000980
000990 MOVE 0 TO CDEXCEPTIONCODE.
001000 DISPLAY "Division result: " WITH NO ADVANCING.
001010 INVOKE W-TARGET "divop" USING STRUCT1
001020 IF CDEXCEPTIONCODE NOT = -1 THEN
001030 DISPLAY result OF STRUCT1
001040 END-IF.
001050
001060 END PROGRAM CALCCL.
5. Adding a Stub
To call the CORBA server application, a stub file and other files required for the CORBA client must be created from the IDL file and added to the project. Use the New CORBA Stub File wizard to create a stub file and the other files, and add them to the project.
Select "File" > "New" > "Other" from the workbench menu. New wizard starts.
Select "COBOL" > "Source" > "CORBA Stub File".
The CORBA stub file wizard starts.
Specify the IDL file, the registration target project, and the language used to create the files.
Setting item | Setting value |
---|---|
IDL File | Specify USCALCSV.idl of the CALCSV project. |
Project | CALCCL |
Language | Object-oriented COBOL |
Click the "Finish" button. The following files are created in the project.
File type | File name |
---|---|
Repository paragraph declaration library | USCALCSV--REP.cbl |
Constant declaration library | USCALCSV--CONST.cbl |
TYPEDEF type declaration library | USCALCSV--COPY.cbl |
Interface file | SAMPLE-CALCSV.cob |
Helper class file | SAMPLE-CALCSV--HELPER.cob |
Stub file | SAMPLE-CALCSV--STUB.cob |
Narrow stub file | SAMPLE-CALCSV_NARROW.cob |
Data-type class file | SAMPLE-CDEXCEPTION.cob |
Data-type Helper file | SAMPLE-S1--HELPER.cob |
Among the files created, COBOL sources other than libraries are registered as the source files in the "Dependency" view.
6. Dependency Analysis
Before a project including an object-oriented COBOL source file is built, the dependencies between COBOL source files must be defined. When the dependencies are correctly defined, COBOL sources are built in the correct order. If the dependencies are not correctly defined, a compile error may occur during building.
When a project is newly created or a COBOL source file is added to "Source Folder", dependencies for the added source file are automatically analyzed and defined. However, when the REPOSITORY paragraph of the COBOL source file has been edited as is shown in this tutorial, a dependency analysis must be executed manually before build.
Select the target project from the workbench Dependency view, then select "Edit" > "Analyze Dependency" > "All" from the menu to execute a dependency analysis.
Note
During a dependency analysis, the message "xxx.rep: does not exist" is displayed on the log console. Normally, an object-oriented COBOL source file in a project is compiled before a repository file (*.rep) for the source file is created. For this reason, the message is displayed if a dependency analysis is executed before build. In such cases, the dependency analysis is executed normally, so you can continue to build the project.
7. Building the Project
By following the procedure to this point, you have completed the work to build the CORBA client application.
However, if "Project" > "Build Automatically" was not previously selected (the "Build Automatically" menu item will have a check if it was selected), the application has not been built.
Select the CORBA server project in the Dependency View or Structure View, and select "Project" > "Project Build" from the menu bar. The CORBA server project is built.
8. Verifying Operation
Start the WorkUnit to which the CORBA server application has been deployed, select the project from the workbench view, and then select "Run" > "Run As" > "COBOL Application" from the menu to run the client application.