X hits on this document

318 views

0 shares

0 downloads

0 comments

101 / 120

for the JNI program Java2CblXmlBridge.cpp, which implements the JNI method

described in the generated header file.

Table 9.7. Example implementation of the Java to COBOL JNI XML bridge.

01: #include "package_JSimpleCalculator.h" 02: #include "cobcall.h"

/* * Class: * Method:

info_reversingproject jsimplecalculator JSimpleCalculator smplCalcXmlInterface

_

_

* Signature: */

(Ljava/lang/String;)Ljava/lang/String;

03: jstring JNICALL J a v a _ i n f o _ r e v e r s i n g p r o j e c t _ j s i m p l e c a l c u l a t o r _ J S i m p l e C a l c u l a t o r _ s m p l C a l XmlInterface (JNIEnv *env, jobject parent_obect, jstring xml_doc) 04: { c

05: 06: 07: 08: 09: 10:

// Get input XML document passed from Java jboolean iscopy; jstring output_xml; char *xml_buffer = NULL; char *xml_buffer_ptr = NULL; const char *xml input = (*env)->GetStringUTFChars(env, xml doc,

_

_

&iscopy);

11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:

int xml_len = strlen(xml_input); // Allocate XML I/O buffer and copy input XML xml_buffer = (char*)malloc(32767); memset(xml_buffer, 0x00, 32767); // initialize memcpy(xml_buffer, xml_input, xml_len); // Free JNI memory used for MBCS to SBCS conversion (*env)->ReleaseStringUTFChars(env, xml_doc, &iscopy); // call COBOL to XML marshalling layer, passing XML I/O buffer cobinit(); // Initialize Micro Focus COBOL runtime XML2CALC(&xml_len, xml_buffer); // Call COBOL // Null terminate XML returned from COBOL xml_buffer_ptr = xml_buffer; xml_buffer_ptr += xml_len; *(xml_buffer_ptr) = 0x00; // Allocate UTF version of XML to return to Java output_xml = (*env)->NewStringUTF(env, xml_buffer); // Free XML I/O buffer free(xml_buffer); // Return XML generated by COBOL as Java String return output xml;

_

31:

}

93

Document info
Document views318
Page views319
Page last viewedSun Dec 04 12:42:21 UTC 2016
Pages120
Paragraphs2913
Words25794

Comments