       *>
       *> Micro Focus Server Express XA switch module for Oracle.
       *>
       *> (C) Copyright 2005-2007 Micro Focus (IP) Limited
       *> All Rights Reserved.
       *>

       IDENTIFICATION DIVISION.
       PROGRAM-ID. ESORAXA.
       ENVIRONMENT DIVISION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 OraPtr        USAGE PROCEDURE-POINTER VALUE NULL.
       01 OraXaPtr      USAGE PROCEDURE-POINTER VALUE NULL.
       01 XASwitchPtr   REDEFINES OraXaPtr USAGE POINTER.
       01 MFocusCasPtr  USAGE PROCEDURE-POINTER VALUE NULL.
       01 BadPtr        USAGE PROCEDURE-POINTER VALUE NULL.
       01 SubpPtr        USAGE PROCEDURE-POINTER VALUE NULL.

       *> Database Access structure used by Enterprise Server.

       78 78-XA-ONEPHASE-SUPPORT              VALUE H'80000000'.

       01 esoraxa-dbaccess-struct.
          03 esoraxa-xa-structure.
             05 esoraxa-RM-name               PIC X(32).
             05 esoraxa-flags                 PIC S9(9) COMP-5.
             05 esoraxa-version               PIC S9(9) COMP-5.
             05 esoraxa-open-entry            PROCEDURE-POINTER.
             05 esoraxa-close-entry           PROCEDURE-POINTER.
             05 esoraxa-start-entry           PROCEDURE-POINTER.
             05 esoraxa-end-entry             PROCEDURE-POINTER.
             05 esoraxa-rollback-entry        PROCEDURE-POINTER.
             05 esoraxa-prepare-entry         PROCEDURE-POINTER.
             05 esoraxa-commit-entry          PROCEDURE-POINTER.
             05 esoraxa-recover-entry         PROCEDURE-POINTER.
             05 esoraxa-forget-entry          PROCEDURE-POINTER.
             05 esoraxa-complete-entry        PROCEDURE-POINTER.
       78 78-XA-STRUCTURE-LEN                 VALUE
                               NEXT - START OF esoraxa-xa-structure.
             05 esoraxa-1phase.
                07 esoraxa-1phase-flags            PIC X(8).
                07 esoraxa-1phase-connect-entry    PROCEDURE-POINTER.
                07 esoraxa-1phase-disconnect-entry PROCEDURE-POINTER.
                07 esoraxa-1phase-commit-entry     PROCEDURE-POINTER.
                07 esoraxa-1phase-rollback-entry   PROCEDURE-POINTER.
       78 78-XA-DBACCESS-STRUCT-LEN           VALUE
                               NEXT - START OF esoraxa-xa-structure.

       LINKAGE SECTION.
       01  lk-switch-area              PIC X.

       PROCEDURE DIVISION.

          *> Load Enterprise Server module
          SET MFocusCasPtr TO ENTRY "casaxlib.so"

          *> Attempt to load a pointer to the Oracle XA switch structure
          SET OraXaPtr TO ENTRY "xaosw"

           IF XASwitchPtr NOT = NULL
               SET ADDRESS OF lk-switch-area TO XASwitchPtr
               move LK-SWITCH-AREA(1:78-XA-STRUCTURE-LEN)
                                       TO esoraxa-xa-structure

               SET SubpPtr TO ENTRY "ESORAOPC.so"
               IF SubpPtr NOT = NULL
                  SET esoraxa-1phase-commit-entry
                                  TO ENTRY 'esoraopc_1pc_commit'    
                  SET esoraxa-1phase-rollback-entry  
                                  TO ENTRY 'esoraopc_1pc_rollback'
                  SET esoraxa-1phase-connect-entry
                                  TO ENTRY 'esoraopc_1pc_connect'
                  SET esoraxa-1phase-disconnect-entry
                                  TO ENTRY 'esoraopc_1pc_disconnect'
                  COMPUTE esoraxa-flags = 
                       esoraxa-flags B-OR 78-XA-ONEPHASE-SUPPORT
               END-IF
               SET XASwitchPtr TO ADDRESS OF esoraxa-dbaccess-struct
           END-IF


          GOBACK RETURNING OraXaPtr
          .
