Project

Profile

Help

Revision 2ebe3898

Added by O'Neil Delpratt almost 6 years ago

Added files to the Saxon/C release

View differences:

.gitattributes
478 478
latest9.6/hec/Saxon.C.API/64-bit-code/PEC/.DS_Store svn_mime_002dtype=application%2Foctet-stream
479 479
latest9.6/hec/Saxon.C.API/64-bit-code/PEC/SaxonCGlue.c svn_eol_002dstyle=native
480 480
latest9.6/hec/Saxon.C.API/64-bit-code/PEC/SaxonCGlue.h svn_eol_002dstyle=native
481
latest9.6/hec/Saxon.C.API/EEC/SaxonCGlue.c svn_eol_002dstyle=native
482
latest9.6/hec/Saxon.C.API/EEC/SaxonCGlue.h svn_eol_002dstyle=native
483
latest9.6/hec/Saxon.C.API/HEC/SaxonCGlue.c svn_eol_002dstyle=native
484
latest9.6/hec/Saxon.C.API/HEC/SaxonCGlue.h svn_eol_002dstyle=native
485
latest9.6/hec/Saxon.C.API/PEC/SaxonCGlue.c svn_eol_002dstyle=native
486
latest9.6/hec/Saxon.C.API/PEC/SaxonCGlue.h svn_eol_002dstyle=native
481 487
latest9.6/hec/Saxon.C.API/SaxonCGlue.c svn_eol_002dstyle=native
482 488
latest9.6/hec/Saxon.C.API/SaxonCGlue.h svn_eol_002dstyle=native
483 489
latest9.6/hec/Saxon.C.API/SaxonCProcessor.c svn_eol_002dstyle=native
latest9.6/hec/Saxon.C.API/EEC/SaxonCGlue.c
1
#include "SaxonCGlue.h"
2

  
3
jobject cpp;
4
/*
5
* Set Dll name. Also set the saxon resources directory. 
6
* If the SAXONC_HOME sxnc_environmental variable is set then use that as base.
7
*/
8
void setDllname(){
9
	if(getenv("SAXONC_HOME")!= NULL) {
10

  
11
		char * env = getenv("SAXONC_HOME");
12
		size_t env_len = strlen(env);
13
		size_t name_len =  15;
14
		size_t rDir_len = 11;
15
		//dllname =malloc(sizeof(char)*name_len);
16
		//resources_dir =malloc(sizeof(char)*rDir_len);
17
		memset(&dllname[0], 0, sizeof(dllname));
18
		memset(&resources_dir[0], 0, sizeof(resources_dir));
19
		strncat(resources_dir, env,  env_len);
20
		strncat(resources_dir, "/saxon-data", rDir_len);
21
		strncat(dllname, env, env_len);
22
		strncat(dllname, "/libsaxoneec.so", name_len); //rename according to product edition (-hec or -pec)
23
#ifdef DEBUG	
24
		printf("resources_dir: %s\n", resources_dir);	
25
		printf("envDir: %s\n", env);
26
		printf("size of env %i\n", strlen(env));
27
		printf("size of dllname %i\n", strlen(dllname));
28
		printf("dllName: %s\n", dllname);
29
		printf("resources_dir: %s\n", resources_dir);
30
#endif
31
	}
32
#ifdef DEBUG	
33
		printf("resources_dir: %s\n", resources_dir);	
34
		printf("size of dllname %i\n", strlen(dllname));
35
		printf("dllName: %s\n", dllname);
36
		printf("resources_dir: %s\n", resources_dir);
37
		printf("size of resources dir %i\n", strlen(resources_dir));
38
#endif 	
39

  
40
}
41

  
42
char * getDllname(){
43
	return dllname;
44
}
45

  
46
/*
47
 * Load dll using the default setting in Saxon/C
48
 * Recommended method to use to load library
49
 */
50
HANDLE loadDefaultDll(){
51
	return loadDll(NULL);
52
}
53

  
54

  
55
/*
56
 * Load dll.
57
 */
58
HANDLE loadDll(char* name)
59
{
60
	if(name == NULL) {
61
		setDllname();
62
		name = getDllname();
63
		//perror("Error1: ");
64
	}
65

  
66
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
67
    HANDLE hDll = LoadLibrary (_T(name)); // Used for windows only
68
#else
69
    HANDLE hDll = LoadLibrary(name);
70
#endif
71

  
72
    if (!hDll) {
73
        printf ("Unable to load %s\n", name);
74
	perror("Error: ");
75
        exit(1);
76
    }
77
#ifdef DEBUG
78
    printf ("%s loaded\n", name);
79
#endif
80

  
81
    return hDll;
82
}
83

  
84

  
85

  
86
jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
87
jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
88

  
89

  
90

  
91
void initDefaultJavaRT(sxnc_environment ** env){
92
	sxnc_environment *environ = *env;
93
	initJavaRT((environ->myDllHandle), &(environ->jvm), &(environ->env));
94
}
95

  
96
/*
97
 * Initialize JET run-time.
98
 */
99
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv)
100
{
101
    //perror ("initJavaRT - load Saxon/C library\n");
102
    int result;
103
    JavaVMInitArgs args;
104
    JNI_GetDefaultJavaVMInitArgs_func =
105
    (jint (JNICALL *) (void *args))
106
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
107
    GetProcAddress ((HMODULE)myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
108
#else
109
    GetProcAddress (myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
110
#endif
111
    
112
    JNI_CreateJavaVM_func =
113
    (jint (JNICALL *) (JavaVM **pvm, void **penv, void *args))
114
    
115
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
116
    GetProcAddress ((HMODULE)myDllHandle, "JNI_CreateJavaVM");
117
#else
118
    GetProcAddress (myDllHandle, "JNI_CreateJavaVM");
119
    
120
#endif
121
    
122
    if(!JNI_GetDefaultJavaVMInitArgs_func) {
123
        printf ("%s doesn't contain public JNI_GetDefaultJavaVMInitArgs\n", getDllname());
124
        exit (1);
125
    }
126
    
127
    if(!JNI_CreateJavaVM_func) {
128
        printf ("%s doesn't contain public JNI_CreateJavaVM\n", getDllname());
129
        exit (1);
130
    }
131
    
132
    memset (&args, 0, sizeof(args));
133
    
134
    args.version = JNI_VERSION_1_2;
135
    result = JNI_GetDefaultJavaVMInitArgs_func(&args);
136
    if (result != JNI_OK) {
137
        printf("JNI_GetDefaultJavaVMInitArgs() failed with result\n");
138
        exit(1);
139
    }  
140
    /*
141
     * NOTE: no JVM is actually created
142
     * this call to JNI_CreateJavaVM is intended for JET RT initialization
143
     */
144
    result = JNI_CreateJavaVM_func (pjvm, (void **)penv, &args);
145
    if (result != JNI_OK) {
146
        printf("JNI_CreateJavaVM() failed with result\n");
147
        exit(1);
148
    }
149

  
150
#ifdef DEBUG
151
    printf ("JET RT initialized\n");
152

  
153
#endif
154
    fflush (stdout);
155
}
156

  
157

  
158
/*
159
 * Look for class.
160
 */
161
jclass lookForClass (JNIEnv* penv, const char* name)
162
{
163
    jclass clazz = (*penv)->FindClass (penv, name);
164

  
165
    if (!clazz) {
166
        printf("Unable to find class %s\n", name);
167
	return NULL;
168
    }
169
#ifdef DEBUG
170
    printf ("Class %s found\n", name);
171
    fflush (stdout);
172
#endif
173

  
174
    return clazz;
175
}
176

  
177

  
178
/*
179
 * Create an object and invoke the instance method
180
 */
181
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments)
182
{
183
    jmethodID MID_init, MID_name;
184
    jobject obj;
185

  
186
    MID_init = (*penv)->GetMethodID (penv, myClassInDll, "<init>", "()V");
187
    if (!MID_init) {
188
        printf("Error: MyClassInDll.<init>() not found\n");
189
        return;
190
    }
191

  
192
    obj = (*penv)->NewObject(penv, myClassInDll, MID_init);
193
    if (!obj) {
194
        printf("Error: failed to allocate an object\n");
195
        return;
196
    }
197

  
198
    MID_name = (*penv)->GetMethodID (penv, myClassInDll, name, arguments);
199

  
200
    if (!MID_name) {
201
        printf("Error: %s not found\n", name);
202
        return;
203
    }
204
    
205
    (*(penv))->CallVoidMethod (penv, obj, MID_name);
206
}
207

  
208

  
209

  
210

  
211
/*
212
 * Invoke the static method
213
 */
214
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments)
215
{
216
    jmethodID MID_name;
217

  
218
    MID_name = (*penv)->GetStaticMethodID(penv, myClassInDll, name, arguments);
219
    if (!MID_name) {
220
        printf("\nError: method %s not found\n", name);
221
        return;
222
    }
223
    
224
    (*penv)->CallStaticVoidMethod(penv, myClassInDll, MID_name);
225
}
226

  
227

  
228
/*
229
 * Find a constructor with a set arguments
230
 */
231
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments)
232
{
233
    jmethodID MID_initj;
234
    jobject obj;
235

  
236
    MID_initj = (jmethodID)(*penv)->GetMethodID (penv, myClassInDll, "<init>", arguments);
237
    if (!MID_initj) {
238
        printf("Error: MyClassInDll.<init>() not found\n");
239
	fflush (stdout);
240
        return 0;
241
    }
242

  
243
  return MID_initj;
244
}
245

  
246
/*
247
 * Create the Java SaxonProcessor
248
 */
249
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean license)
250
{
251
    jmethodID MID_initi;
252

  
253
    jobject obj;
254

  
255
    MID_initi = (jmethodID)(*(penv))->GetMethodID (penv, myClassInDll, "<init>", arguments);
256
	if (!MID_initi) {
257
        	printf("Error: MyClassInDll.<init>() not found\n");
258
       	 return NULL;
259
        }
260
     
261
    if(argument1) {
262

  
263
	     obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, argument1, license);
264
    } else {
265
	
266
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, license);
267
     }
268
      if (!obj) {
269
        printf("Error: failed to allocate an object\n");
270
        return NULL;
271
      }
272
    return obj;
273
}
274

  
275

  
276
/*
277
 * Create the Java SaxonProcessor without boolean license argument
278
 */
279
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1)
280
{
281
    jmethodID MID_initi;
282

  
283
    jobject obj;
284

  
285
    MID_initi = (jmethodID)(*(penv))->GetMethodID (penv, myClassInDll, "<init>", arguments);
286
	if (!MID_initi) {
287
        	printf("Error: MyClassInDll.<init>() not found\n");
288
       	 return NULL;
289
        }
290
     
291
    if(argument1) {
292

  
293
	     obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, argument1);
294
    } else {
295
	
296
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi);
297
     }
298
      if (!obj) {
299
        printf("Error: failed to allocate an object\n");
300
        return NULL;
301
      }
302
    return obj;
303
}
304

  
305

  
306
/*
307
 * Callback to check for exceptions. When called it returns the exception as a string 
308
 */
309
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject){
310

  
311
    if ((*(environ.env))->ExceptionCheck(environ.env)) {
312

  
313
        jthrowable exc = (*(environ.env))->ExceptionOccurred(environ.env);
314
#ifdef DEBUG
315
        (*(environ.env))->ExceptionDescribe(environ.env);
316
#endif
317
 	if(exc) {
318
		printf("Exception Occurred!");
319
	}
320
        jclass exccls = (jclass) (*(environ.env))->GetObjectClass(environ.env, exc);
321

  
322
        jclass clscls = (jclass) (*(environ.env))->FindClass(environ.env, "java/lang/Class");
323
        
324
        jmethodID getName = (jmethodID)(*(environ.env))->GetMethodID(environ.env, clscls, "getName", "()Ljava/lang/String;");
325
        jstring name = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exccls, getName));
326
        char const* utfName = (*(environ.env))->GetStringUTFChars(environ.env, name, NULL);
327
        
328
        if(callingObject != NULL && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
329
  		
330
		jclass saxonExcClass = (*(environ.env))->FindClass(environ.env, "java/lang/Throwable");
331
		
332
		jmethodID  getMessage =  (jmethodID)(*(environ.env))->GetMethodID(environ.env, exccls, "getMessage", "()Ljava/lang/String;");
333
		
334
        if(getMessage) {
335
            
336
            jstring message = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exc, getMessage));
337
       
338
	if(!message){
339
	
340
	(*(environ.env))->ExceptionClear(environ.env);
341
	return 0;
342
	}
343
            char const* utfMessage= (*(environ.env))->GetStringUTFChars(environ.env, message, NULL);
344
      
345
            if(utfMessage != NULL) {
346
		(*(environ.env))->ReleaseStringUTFChars(environ.env, name, utfName);
347
            }
348
       
349
	    (*(environ.env))->ExceptionClear(environ.env);
350
	    return utfMessage;
351
	}
352
    }
353
     (*(environ.env))->ReleaseStringUTFChars(environ.env, name, utfName);      
354
    }
355
(*(environ.env))->ExceptionClear(environ.env);
356
    return NULL;
357
}
358

  
359

  
360
/*
361
 * Clean up and destroy Java VM to release memory used. 
362
 */
363
void finalizeJavaRT (JavaVM* jvm)
364
{
365

  
366
  if(!jvm){
367
	  printf("\njvm is null\n");	
368
  }
369
  (*jvm)->DestroyJavaVM (jvm);
370
}
371

  
372

  
373
/*
374
 * Get a parameter from list 
375
 */
376
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name){
377
	int i =0;
378
	for(i =0; i< parLen;i++) {
379
		if(strcmp(parameters[i].name, name) == 0)
380
			return (jobject)parameters[i].value;			
381
	}
382
	return NULL;
383
}
384

  
385

  
386
/*
387
 * Get a property from list 
388
 */
389
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name){
390
	int i =0;
391
	for(i =0; i< propLen;i++) {
392
		if(strcmp(properties[i].name, name) == 0)
393
			return properties[i].value;			
394
	}
395
	return 0;
396
}
397

  
398

  
399
/*
400
 * set a parameter 
401
 */
402
void setParameter(sxnc_parameter **parameters, int * parLen, int * parCap, const char * namespacei, const char * name, jobject value){
403

  
404
	if(getParameter(*parameters, (*parLen), "", name) != 0){
405
		return;			
406
	}
407
	(*parLen)++;	
408
	if((*parLen) >= (*parCap)) {
409
		(*parCap) *=2; 
410
		sxnc_parameter* temp = (sxnc_parameter*)malloc(sizeof(sxnc_parameter)*(*parCap));	
411
		int i =0;
412
		for(i =0; i< (*parLen)-1;i++) {
413
			temp[i] = (*parameters)[i];			
414
		}
415
		free(parameters);
416
		parameters = &temp;
417
	}
418
	int nameLen = strlen(name)+7;	
419
	char *newName = malloc(sizeof(char)*nameLen);
420
  	snprintf(newName, nameLen, "%s%s", "param:", name );
421
	(*parameters)[(*parLen)-1].name = (char*)newName;	
422
	(*parameters)[(*parLen)-1].value = (jobject)value;
423
}
424

  
425

  
426
/*
427
 * set a property 
428
 */
429
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value){	
430
	if(getProperty(*properties, (*propLen), "", name) != 0){
431
		return;			
432
	}
433
		
434
	if(((*propLen)+1) >= (*propCap)) {
435
		(*propCap) *=2; 
436
		sxnc_property* temp = (sxnc_property*)malloc(sizeof(sxnc_property)*  (*propCap));
437
		int i =0;	
438
		for(i =0; i< (*propLen)-1;i++) {
439
			temp[i] = (*properties)[i];			
440
		}
441
		free(properties);
442
		properties = &temp;
443

  
444
	}
445
	int nameLen = strlen(name)+1;	
446
	char *newName = (char*)malloc(sizeof(char)*nameLen);
447
  	snprintf(newName, nameLen, "%s", name );
448
	char *newValue = (char*)malloc(sizeof(char)*strlen(value)+1);
449
  	snprintf(newValue, strlen(value)+1, "%s", value );
450
	(*properties)[(*propLen)].name = (char*)newName;	
451
	(*properties)[(*propLen)].value = (char*)newValue;
452
        (*propLen)++;
453
}
454

  
455
/*
456
 * clear parameter 
457
 */
458
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen){
459
	int i =0;
460
	free(*parameters);
461
	free(*parameters);
462
	/*for(i =0; i< parLen; i++){
463
		free((*parameters[i].name);
464
		free(parameters[i].value);
465
	}
466
	for(i =0; i< propLen; i++){
467
		free(properties[i].name);
468
		free(properties[i].value);
469
	}*/
470

  
471
    	*parameters = (sxnc_parameter *)calloc(10, sizeof(sxnc_parameter));
472
    	*properties = (sxnc_property *)calloc(10, sizeof(sxnc_property));
473
	(*parLen) = 0;
474
	(*propLen) = 0;
475
}
476

  
477

  
478
const char * stringValue(sxnc_environment environ, jobject value){
479
	jclass  objClass = lookForClass(environ.env, "java/lang/Object");
480
	static jmethodID strMID = NULL;
481
	if(!strMID) {
482
		strMID = (jmethodID)(*(environ.env))->GetMethodID(environ.env, objClass, "toString", "()Ljava/lang/String;");
483
		if(!strMID) {
484
	 		 printf("\nError: Object %s() not found\n","toString");
485
  	 		 fflush (stdout);
486
         		 return NULL;
487
		}
488
        }
489
	jstring result = (jstring)((*(environ.env))->CallObjectMethod(environ.env, value, strMID));
490
 	if(result) {
491
	       	const char * str = (*(environ.env))->GetStringUTFChars(environ.env, result, NULL);    
492
		return str;
493
        }
494

  
495
    //checkForException(environ, cppClass, cpp);
496
    return 0;
497
	
498
}
499

  
500

  
501

  
502

  
latest9.6/hec/Saxon.C.API/EEC/SaxonCGlue.h
1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2016 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

  
8
#ifndef SAXONCGLUE_H 
9
#define SAXONCGLUE_H
10
#include <jni.h>
11

  
12

  
13
#if defined __linux__ || defined __APPLE__
14
#include <stdlib.h>
15
#include <string.h>
16
#include <dlfcn.h>
17

  
18

  
19
#define HANDLE void*
20
#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
21
#define GetProcAddress(x,y) dlsym(x,y)
22
#else
23
#include <windows.h>
24
#endif
25

  
26
#ifdef __cplusplus
27
#define EXTERN_C extern "C" {
28
#define EXTERN_C_END }
29
#else
30
#define EXTERN_C
31
#define EXTERN_C_END
32
#endif
33

  
34
#ifndef __cplusplus
35
#ifndef _BOOL
36
typedef unsigned char bool;
37
static const bool false = 0;
38
static const bool true = 1;
39
#endif
40
#endif
41

  
42
#ifndef __cplusplus 
43
	#if defined(LICENSE)
44
		#define license true;
45
	#else
46
		#define license false
47
	#endif
48
#endif
49

  
50

  
51
//#define DEBUG
52

  
53

  
54
EXTERN_C
55

  
56

  
57

  
58

  
59
static char dllname[] =
60
    #ifdef __linux__
61
        "/usr/lib/libsaxoneec.so";  //rename according to product edition (-hec or -pec) Also make change in the c file
62
    #elif  defined (__APPLE__) && defined(__MACH__)
63
        "/usr/lib/libsaxoneec.dylib";
64
    #else
65
         "C:\\Program Files\\Saxonica\\SaxonEEC1.0.0\\libsaxoneec.dll";
66
    #endif
67

  
68
static char resources_dir[] = 
69
     #ifdef __linux__
70
        "/usr/lib/saxon-data";
71
    #elif  defined (__APPLE__) && defined(__MACH__)
72
        "/usr/lib/saxon-data";
73
    #else
74
         "C:\\Program Files\\Saxonica\\SaxonEEC1.0.0\\saxon-data";
75
    #endif
76

  
77

  
78
//===============================================================================================//
79
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
80
 * <p/>
81
 */
82
typedef struct {
83
		JNIEnv *env;
84
		HANDLE myDllHandle;
85
		JavaVM *jvm;
86
	} sxnc_environment;
87

  
88

  
89
//===============================================================================================//
90

  
91
/*! <code>sxnc_parameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
92
 * <p/>
93
 */
94
typedef struct {
95
		char* name;
96
		jobject value;
97
	} sxnc_parameter;
98

  
99
//===============================================================================================//
100

  
101
/*! <code>sxnc_property</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
102
 * <p/>
103
 */
104
typedef struct {
105
		char * name;
106
		char * value;
107
	} sxnc_property;
108

  
109

  
110

  
111
extern jobject cpp;
112

  
113

  
114

  
115
extern const char * failure;
116

  
117

  
118
/*
119
* Get Dll name.
120
*/
121

  
122
char * getDllname();
123

  
124

  
125
/*
126
* Set Dll name. Also set the saxon resources directory. 
127
* If the SAXON_HOME environmental variable is set then use that as base.
128
*/
129
void setDllname();
130

  
131
/*
132
 * Load dll using the default setting in Saxon/C
133
 * Recommended method to use to load library
134
 */
135
HANDLE loadDefaultDll();
136

  
137

  
138
/*
139
 * Load dll.
140
 * name - The dll library
141
 */
142
HANDLE loadDll(char* name);
143

  
144

  
145
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
146

  
147
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
148

  
149
/*
150
 * Initialize JET run-time with simplified method. The initJavaRT method will be called 
151
 * with the arguments expanded from environ
152
 * @param environ - the Evironment is passed
153
 */
154
void initDefaultJavaRT(sxnc_environment ** environ);
155

  
156

  
157
/*
158
 * Initialize JET run-time.
159
 */
160
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
161

  
162

  
163
/*
164
 * Look for class.
165
 */
166
jclass lookForClass (JNIEnv* penv, const char* name);
167

  
168

  
169
/*
170
 * Create an object and invoke the instance method
171
 */
172
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
173

  
174

  
175

  
176

  
177
/*
178
 * Invoke the static method
179
 */
180
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
181

  
182

  
183
/*
184
 * Find a constructor with a set arguments
185
 */
186
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
187

  
188
/*
189
 * Create the Java SaxonProcessor
190
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
191
 */
192
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
193

  
194
/*
195
 * Create the Java SaxonProcessor
196
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
197
 */
198
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
199

  
200
/*
201
 * Callback to check for exceptions. When called it returns the exception as a string 
202
 */
203
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
204

  
205
/*
206
 * Clean up and destroy Java VM to release memory used. 
207
 */
208
void finalizeJavaRT (JavaVM* jvm);
209

  
210

  
211
/*
212
 * Get a parameter from list 
213
 */
214
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name);
215

  
216
/*
217
 * Get a property from list 
218
 */
219
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
220

  
221

  
222
/*
223
 * set a parameter 
224
 */
225
void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
226

  
227

  
228
/*
229
 * set a property 
230
 */
231
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
232

  
233
/*
234
 * clear parameter 
235
 */
236
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
237

  
238

  
239

  
240
const char * stringValue(sxnc_environment environ, jobject value);
241

  
242
EXTERN_C_END
243

  
244

  
245
#endif //SAXONCGLUE_H
latest9.6/hec/Saxon.C.API/HEC/SaxonCGlue.c
1
#include "SaxonCGlue.h"
2

  
3
jobject cpp;
4
/*
5
* Set Dll name. Also set the saxon resources directory. 
6
* If the SAXONC_HOME sxnc_environmental variable is set then use that as base.
7
*/
8
void setDllname(){
9
	if(getenv("SAXONC_HOME")!= NULL) {
10

  
11
		char * env = getenv("SAXONC_HOME");
12
		size_t env_len = strlen(env);
13
		size_t name_len =  15;
14
		size_t rDir_len = 11;
15
		//dllname =malloc(sizeof(char)*name_len);
16
		//resources_dir =malloc(sizeof(char)*rDir_len);
17
		memset(&dllname[0], 0, sizeof(dllname));
18
		memset(&resources_dir[0], 0, sizeof(resources_dir));
19
		strncat(resources_dir, env,  env_len);
20
		strncat(resources_dir, "/saxon-data", rDir_len);
21
		strncat(dllname, env, env_len);
22
		strncat(dllname, "/libsaxonhec.so", name_len); //rename according to product edition (-hec or -pec)
23
#ifdef DEBUG	
24
		printf("resources_dir: %s\n", resources_dir);	
25
		printf("envDir: %s\n", env);
26
		printf("size of env %i\n", strlen(env));
27
		printf("size of dllname %i\n", strlen(dllname));
28
		printf("dllName: %s\n", dllname);
29
		printf("resources_dir: %s\n", resources_dir);
30
#endif
31
	}
32
#ifdef DEBUG	
33
		printf("resources_dir: %s\n", resources_dir);	
34
		printf("size of dllname %i\n", strlen(dllname));
35
		printf("dllName: %s\n", dllname);
36
		printf("resources_dir: %s\n", resources_dir);
37
		printf("size of resources dir %i\n", strlen(resources_dir));
38
#endif 	
39

  
40
}
41

  
42
char * getDllname(){
43
	return dllname;
44
}
45

  
46
/*
47
 * Load dll using the default setting in Saxon/C
48
 * Recommended method to use to load library
49
 */
50
HANDLE loadDefaultDll(){
51
	return loadDll(NULL);
52
}
53

  
54

  
55
/*
56
 * Load dll.
57
 */
58
HANDLE loadDll(char* name)
59
{
60
	if(name == NULL) {
61
		setDllname();
62
		name = getDllname();
63
		//perror("Error1: ");
64
	}
65

  
66
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
67
    HANDLE hDll = LoadLibrary (_T(name)); // Used for windows only
68
#else
69
    HANDLE hDll = LoadLibrary(name);
70
#endif
71

  
72
    if (!hDll) {
73
        printf ("Unable to load %s\n", name);
74
	perror("Error: ");
75
        exit(1);
76
    }
77
#ifdef DEBUG
78
    printf ("%s loaded\n", name);
79
#endif
80

  
81
    return hDll;
82
}
83

  
84

  
85

  
86
jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
87
jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
88

  
89

  
90

  
91
void initDefaultJavaRT(sxnc_environment ** env){
92
	sxnc_environment *environ = *env;
93
	initJavaRT((environ->myDllHandle), &(environ->jvm), &(environ->env));
94
}
95

  
96
/*
97
 * Initialize JET run-time.
98
 */
99
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv)
100
{
101
    //perror ("initJavaRT - load Saxon/C library\n");
102
    int result;
103
    JavaVMInitArgs args;
104
    JNI_GetDefaultJavaVMInitArgs_func =
105
    (jint (JNICALL *) (void *args))
106
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
107
    GetProcAddress ((HMODULE)myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
108
#else
109
    GetProcAddress (myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
110
#endif
111
    
112
    JNI_CreateJavaVM_func =
113
    (jint (JNICALL *) (JavaVM **pvm, void **penv, void *args))
114
    
115
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
116
    GetProcAddress ((HMODULE)myDllHandle, "JNI_CreateJavaVM");
117
#else
118
    GetProcAddress (myDllHandle, "JNI_CreateJavaVM");
119
    
120
#endif
121
    
122
    if(!JNI_GetDefaultJavaVMInitArgs_func) {
123
        printf ("%s doesn't contain public JNI_GetDefaultJavaVMInitArgs\n", getDllname());
124
        exit (1);
125
    }
126
    
127
    if(!JNI_CreateJavaVM_func) {
128
        printf ("%s doesn't contain public JNI_CreateJavaVM\n", getDllname());
129
        exit (1);
130
    }
131
    
132
    memset (&args, 0, sizeof(args));
133
    
134
    args.version = JNI_VERSION_1_2;
135
    result = JNI_GetDefaultJavaVMInitArgs_func(&args);
136
    if (result != JNI_OK) {
137
        printf("JNI_GetDefaultJavaVMInitArgs() failed with result\n");
138
        exit(1);
139
    }  
140
    /*
141
     * NOTE: no JVM is actually created
142
     * this call to JNI_CreateJavaVM is intended for JET RT initialization
143
     */
144
    result = JNI_CreateJavaVM_func (pjvm, (void **)penv, &args);
145
    if (result != JNI_OK) {
146
        printf("JNI_CreateJavaVM() failed with result\n");
147
        exit(1);
148
    }
149

  
150
#ifdef DEBUG
151
    printf ("JET RT initialized\n");
152

  
153
#endif
154
    fflush (stdout);
155
}
156

  
157

  
158
/*
159
 * Look for class.
160
 */
161
jclass lookForClass (JNIEnv* penv, const char* name)
162
{
163
    jclass clazz = (*penv)->FindClass (penv, name);
164

  
165
    if (!clazz) {
166
        printf("Unable to find class %s\n", name);
167
	return NULL;
168
    }
169
#ifdef DEBUG
170
    printf ("Class %s found\n", name);
171
    fflush (stdout);
172
#endif
173

  
174
    return clazz;
175
}
176

  
177

  
178
/*
179
 * Create an object and invoke the instance method
180
 */
181
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments)
182
{
183
    jmethodID MID_init, MID_name;
184
    jobject obj;
185

  
186
    MID_init = (*penv)->GetMethodID (penv, myClassInDll, "<init>", "()V");
187
    if (!MID_init) {
188
        printf("Error: MyClassInDll.<init>() not found\n");
189
        return;
190
    }
191

  
192
    obj = (*penv)->NewObject(penv, myClassInDll, MID_init);
193
    if (!obj) {
194
        printf("Error: failed to allocate an object\n");
195
        return;
196
    }
197

  
198
    MID_name = (*penv)->GetMethodID (penv, myClassInDll, name, arguments);
199

  
200
    if (!MID_name) {
201
        printf("Error: %s not found\n", name);
202
        return;
203
    }
204
    
205
    (*(penv))->CallVoidMethod (penv, obj, MID_name);
206
}
207

  
208

  
209

  
210

  
211
/*
212
 * Invoke the static method
213
 */
214
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments)
215
{
216
    jmethodID MID_name;
217

  
218
    MID_name = (*penv)->GetStaticMethodID(penv, myClassInDll, name, arguments);
219
    if (!MID_name) {
220
        printf("\nError: method %s not found\n", name);
221
        return;
222
    }
223
    
224
    (*penv)->CallStaticVoidMethod(penv, myClassInDll, MID_name);
225
}
226

  
227

  
228
/*
229
 * Find a constructor with a set arguments
230
 */
231
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments)
232
{
233
    jmethodID MID_initj;
234
    jobject obj;
235

  
236
    MID_initj = (jmethodID)(*penv)->GetMethodID (penv, myClassInDll, "<init>", arguments);
237
    if (!MID_initj) {
238
        printf("Error: MyClassInDll.<init>() not found\n");
239
	fflush (stdout);
240
        return 0;
241
    }
242

  
243
  return MID_initj;
244
}
245

  
246
/*
247
 * Create the Java SaxonProcessor
248
 */
249
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean license)
250
{
251
    jmethodID MID_initi;
252

  
253
    jobject obj;
254

  
255
    MID_initi = (jmethodID)(*(penv))->GetMethodID (penv, myClassInDll, "<init>", arguments);
256
	if (!MID_initi) {
257
        	printf("Error: MyClassInDll.<init>() not found\n");
258
       	 return NULL;
259
        }
260
     
261
    if(argument1) {
262

  
263
	     obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, argument1, license);
264
    } else {
265
	
266
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, license);
267
     }
268
      if (!obj) {
269
        printf("Error: failed to allocate an object\n");
270
        return NULL;
271
      }
272
    return obj;
273
}
274

  
275

  
276
/*
277
 * Create the Java SaxonProcessor without boolean license argument
278
 */
279
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1)
280
{
281
    jmethodID MID_initi;
282

  
283
    jobject obj;
284

  
285
    MID_initi = (jmethodID)(*(penv))->GetMethodID (penv, myClassInDll, "<init>", arguments);
286
	if (!MID_initi) {
287
        	printf("Error: MyClassInDll.<init>() not found\n");
288
       	 return NULL;
289
        }
290
     
291
    if(argument1) {
292

  
293
	     obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, argument1);
294
    } else {
295
	
296
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi);
297
     }
298
      if (!obj) {
299
        printf("Error: failed to allocate an object\n");
300
        return NULL;
301
      }
302
    return obj;
303
}
304

  
305

  
306
/*
307
 * Callback to check for exceptions. When called it returns the exception as a string 
308
 */
309
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject){
310

  
311
    if ((*(environ.env))->ExceptionCheck(environ.env)) {
312

  
313
        jthrowable exc = (*(environ.env))->ExceptionOccurred(environ.env);
314
#ifdef DEBUG
315
        (*(environ.env))->ExceptionDescribe(environ.env);
316
#endif
317
 	if(exc) {
318
		printf("Exception Occurred!");
319
	}
320
        jclass exccls = (jclass) (*(environ.env))->GetObjectClass(environ.env, exc);
321

  
322
        jclass clscls = (jclass) (*(environ.env))->FindClass(environ.env, "java/lang/Class");
323
        
324
        jmethodID getName = (jmethodID)(*(environ.env))->GetMethodID(environ.env, clscls, "getName", "()Ljava/lang/String;");
325
        jstring name = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exccls, getName));
326
        char const* utfName = (*(environ.env))->GetStringUTFChars(environ.env, name, NULL);
327
        
328
        if(callingObject != NULL && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
329
  		
330
		jclass saxonExcClass = (*(environ.env))->FindClass(environ.env, "java/lang/Throwable");
331
		
332
		jmethodID  getMessage =  (jmethodID)(*(environ.env))->GetMethodID(environ.env, exccls, "getMessage", "()Ljava/lang/String;");
333
		
334
        if(getMessage) {
335
            
336
            jstring message = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exc, getMessage));
337
       
338
	if(!message){
339
	
340
	(*(environ.env))->ExceptionClear(environ.env);
341
	return 0;
342
	}
343
            char const* utfMessage= (*(environ.env))->GetStringUTFChars(environ.env, message, NULL);
344
      
345
            if(utfMessage != NULL) {
346
		(*(environ.env))->ReleaseStringUTFChars(environ.env, name, utfName);
347
            }
348
       
349
	    (*(environ.env))->ExceptionClear(environ.env);
350
	    return utfMessage;
351
	}
352
    }
353
     (*(environ.env))->ReleaseStringUTFChars(environ.env, name, utfName);      
354
    }
355
(*(environ.env))->ExceptionClear(environ.env);
356
    return NULL;
357
}
358

  
359

  
360
/*
361
 * Clean up and destroy Java VM to release memory used. 
362
 */
363
void finalizeJavaRT (JavaVM* jvm)
364
{
365

  
366
  if(!jvm){
367
	  printf("\njvm is null\n");	
368
  }
369
  (*jvm)->DestroyJavaVM (jvm);
370
}
371

  
372

  
373
/*
374
 * Get a parameter from list 
375
 */
376
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name){
377
	int i =0;
378
	for(i =0; i< parLen;i++) {
379
		if(strcmp(parameters[i].name, name) == 0)
380
			return (jobject)parameters[i].value;			
381
	}
382
	return NULL;
383
}
384

  
385

  
386
/*
387
 * Get a property from list 
388
 */
389
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name){
390
	int i =0;
391
	for(i =0; i< propLen;i++) {
392
		if(strcmp(properties[i].name, name) == 0)
393
			return properties[i].value;			
394
	}
395
	return 0;
396
}
397

  
398

  
399
/*
400
 * set a parameter 
401
 */
402
void setParameter(sxnc_parameter **parameters, int * parLen, int * parCap, const char * namespacei, const char * name, jobject value){
403

  
404
	if(getParameter(*parameters, (*parLen), "", name) != 0){
405
		return;			
406
	}
407
	(*parLen)++;	
408
	if((*parLen) >= (*parCap)) {
409
		(*parCap) *=2; 
410
		sxnc_parameter* temp = (sxnc_parameter*)malloc(sizeof(sxnc_parameter)*(*parCap));	
411
		int i =0;
412
		for(i =0; i< (*parLen)-1;i++) {
413
			temp[i] = (*parameters)[i];			
414
		}
415
		free(parameters);
416
		parameters = &temp;
417
	}
418
	int nameLen = strlen(name)+7;	
419
	char *newName = malloc(sizeof(char)*nameLen);
420
  	snprintf(newName, nameLen, "%s%s", "param:", name );
421
	(*parameters)[(*parLen)-1].name = (char*)newName;	
422
	(*parameters)[(*parLen)-1].value = (jobject)value;
423
}
424

  
425

  
426
/*
427
 * set a property 
428
 */
429
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value){	
430
	if(getProperty(*properties, (*propLen), "", name) != 0){
431
		return;			
432
	}
433
		
434
	if(((*propLen)+1) >= (*propCap)) {
435
		(*propCap) *=2; 
436
		sxnc_property* temp = (sxnc_property*)malloc(sizeof(sxnc_property)*  (*propCap));
437
		int i =0;	
438
		for(i =0; i< (*propLen)-1;i++) {
439
			temp[i] = (*properties)[i];			
440
		}
441
		free(properties);
442
		properties = &temp;
443

  
444
	}
445
	int nameLen = strlen(name)+1;	
446
	char *newName = (char*)malloc(sizeof(char)*nameLen);
447
  	snprintf(newName, nameLen, "%s", name );
448
	char *newValue = (char*)malloc(sizeof(char)*strlen(value)+1);
449
  	snprintf(newValue, strlen(value)+1, "%s", value );
450
	(*properties)[(*propLen)].name = (char*)newName;	
451
	(*properties)[(*propLen)].value = (char*)newValue;
452
        (*propLen)++;
453
}
454

  
455
/*
456
 * clear parameter 
457
 */
458
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen){
459
	int i =0;
460
	free(*parameters);
461
	free(*parameters);
462
	/*for(i =0; i< parLen; i++){
463
		free((*parameters[i].name);
464
		free(parameters[i].value);
465
	}
466
	for(i =0; i< propLen; i++){
467
		free(properties[i].name);
468
		free(properties[i].value);
469
	}*/
470

  
471
    	*parameters = (sxnc_parameter *)calloc(10, sizeof(sxnc_parameter));
472
    	*properties = (sxnc_property *)calloc(10, sizeof(sxnc_property));
473
	(*parLen) = 0;
474
	(*propLen) = 0;
475
}
476

  
477

  
478
const char * stringValue(sxnc_environment environ, jobject value){
479
	jclass  objClass = lookForClass(environ.env, "java/lang/Object");
480
	static jmethodID strMID = NULL;
481
	if(!strMID) {
482
		strMID = (jmethodID)(*(environ.env))->GetMethodID(environ.env, objClass, "toString", "()Ljava/lang/String;");
483
		if(!strMID) {
484
	 		 printf("\nError: Object %s() not found\n","toString");
485
  	 		 fflush (stdout);
486
         		 return NULL;
487
		}
488
        }
489
	jstring result = (jstring)((*(environ.env))->CallObjectMethod(environ.env, value, strMID));
490
 	if(result) {
491
	       	const char * str = (*(environ.env))->GetStringUTFChars(environ.env, result, NULL);    
492
		return str;
493
        }
494

  
495
    //checkForException(environ, cppClass, cpp);
496
    return 0;
497
	
498
}
499

  
500

  
501

  
502

  
latest9.6/hec/Saxon.C.API/HEC/SaxonCGlue.h
1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2016 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

  
8
#ifndef SAXONCGLUE_H 
9
#define SAXONCGLUE_H
10
#include <jni.h>
11

  
12

  
13
#if defined __linux__ || defined __APPLE__
14
#include <stdlib.h>
15
#include <string.h>
16
#include <dlfcn.h>
17

  
18

  
19
#define HANDLE void*
20
#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
21
#define GetProcAddress(x,y) dlsym(x,y)
22
#else
23
#include <windows.h>
24
#endif
25

  
26
#ifdef __cplusplus
27
#define EXTERN_C extern "C" {
28
#define EXTERN_C_END }
29
#else
30
#define EXTERN_C
31
#define EXTERN_C_END
32
#endif
33

  
34
#ifndef __cplusplus
35
#ifndef _BOOL
36
typedef unsigned char bool;
37
static const bool false = 0;
38
static const bool true = 1;
39
#endif
40
#endif
41

  
42
#ifndef __cplusplus 
43
	#if defined(LICENSE)
44
		#define license true;
45
	#else
46
		#define license false
47
	#endif
48
#endif
49

  
50

  
51
//#define DEBUG
52

  
53

  
54
EXTERN_C
55

  
56

  
57

  
58

  
59
static char dllname[] =
60
    #ifdef __linux__
61
        "/usr/lib/libsaxonhec.so";  //rename according to product edition (hec or pec) Also make change in the c file
62
    #elif  defined (__APPLE__) && defined(__MACH__)
63
        "/usr/lib/libsaxoneec.dylib";
64
    #else
65
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.0\\libsaxonhec.dll";
66
    #endif
67

  
68
static char resources_dir[] = 
69
     #ifdef __linux__
70
        "/usr/lib/saxon-data";
71
    #elif  defined (__APPLE__) && defined(__MACH__)
72
        "/usr/lib/saxon-data";
73
    #else
74
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.0\\saxon-data";
75
    #endif
76

  
77

  
78
//===============================================================================================//
79
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
80
 * <p/>
81
 */
82
typedef struct {
83
		JNIEnv *env;
84
		HANDLE myDllHandle;
85
		JavaVM *jvm;
86
	} sxnc_environment;
87

  
88

  
89
//===============================================================================================//
90

  
91
/*! <code>sxnc_parameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
92
 * <p/>
93
 */
94
typedef struct {
95
		char* name;
96
		jobject value;
97
	} sxnc_parameter;
98

  
99
//===============================================================================================//
100

  
101
/*! <code>sxnc_property</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
102
 * <p/>
103
 */
104
typedef struct {
105
		char * name;
106
		char * value;
107
	} sxnc_property;
108

  
109

  
110

  
111
extern jobject cpp;
112

  
113

  
114

  
115
extern const char * failure;
116

  
117

  
118
/*
119
* Get Dll name.
120
*/
121

  
122
char * getDllname();
123

  
124

  
125
/*
126
* Set Dll name. Also set the saxon resources directory. 
127
* If the SAXON_HOME environmental variable is set then use that as base.
128
*/
129
void setDllname();
130

  
131
/*
132
 * Load dll using the default setting in Saxon/C
133
 * Recommended method to use to load library
134
 */
135
HANDLE loadDefaultDll();
136

  
137

  
138
/*
139
 * Load dll.
140
 * name - The dll library
141
 */
142
HANDLE loadDll(char* name);
143

  
144

  
145
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
146

  
147
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
148

  
149
/*
150
 * Initialize JET run-time with simplified method. The initJavaRT method will be called 
151
 * with the arguments expanded from environ
152
 * @param environ - the Evironment is passed
153
 */
154
void initDefaultJavaRT(sxnc_environment ** environ);
155

  
156

  
157
/*
158
 * Initialize JET run-time.
159
 */
160
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
161

  
162

  
163
/*
164
 * Look for class.
165
 */
166
jclass lookForClass (JNIEnv* penv, const char* name);
167

  
168

  
169
/*
170
 * Create an object and invoke the instance method
171
 */
172
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
173

  
174

  
175

  
176

  
177
/*
178
 * Invoke the static method
179
 */
180
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
181

  
182

  
183
/*
184
 * Find a constructor with a set arguments
185
 */
186
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
187

  
188
/*
189
 * Create the Java SaxonProcessor
190
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
191
 */
192
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
193

  
194
/*
195
 * Create the Java SaxonProcessor
196
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
197
 */
198
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
199

  
200
/*
201
 * Callback to check for exceptions. When called it returns the exception as a string 
202
 */
203
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
204

  
205
/*
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff