Project

Profile

Help

Revision 1a761c15

Added by O'Neil Delpratt almost 6 years ago

Saxon/C added command files

View differences:

.gitattributes
521 521
latest9.6/hec/Saxon.C.API/stdafx.cpp svn_eol_002dstyle=native
522 522
latest9.6/hec/Saxon.C.API/stdafx.h svn_eol_002dstyle=native
523 523
latest9.6/hec/Saxon.C.API/targetver.h svn_eol_002dstyle=native
524
latest9.6/hec/command/query svn_mime_002dtype=application%2Foctet-stream
525
latest9.6/hec/command/transform svn_mime_002dtype=application%2Foctet-stream
526
latest9.6/hec/command/validate svn_mime_002dtype=application%2Foctet-stream
524 527
latest9.6/hec/jar/9.6.0.9/saxon-c/hej/libsaxon-hec.dylib svn_mime_002dtype=application%2Foctet-stream
525 528
latest9.6/hec/jar/9.6.0.9/saxon-c/hej/saxon9he.jar svn_mime_002dtype=application%2Foctet-stream
526 529
latest9.6/hec/jar/libsaxon.dylib svn_mime_002dtype=application%2Foctet-stream
latest9.6/hec/command/Query.c
1
#include <jni.h>
2

  
3
#ifdef __linux__
4
    #include <stdlib.h>
5
    #include <string.h>
6
    #include <dlfcn.h>
7
    #include <stdio.h>  
8
    #define HANDLE void*
9
    #define LoadLibrary(x) dlopen(x, RTLD_LAZY)
10
//    #define FreeLibrary(x) dlclose(x, RTLD_LAZY)
11
    #define GetProcAddress(x,y) dlsym(x,y)
12
#else
13
    #include <windows.h>
14
#endif
15

  
16
typedef int bool;
17
#define true 1
18
#define false 0
19

  
20

  
21
char dllname[] =
22
    #ifdef __linux__
23
#ifdef EEC
24
        "/usr/lib/libsaxoneec.so";
25
#elif defined PEC
26
	"/usr/lib/libsaxonpec.so";
27
#else
28
	"/usr/lib/libsaxonhec.so";
29
#endif
30
    #else
31
#ifdef EEC
32
        "Saxon-eec.dll";
33
#elif defined PEC
34
	"Saxon-pec.dll";
35
#else
36
	"Saxon-hec.dll";
37
#endif
38
    #endif
39

  
40
//===============================================================================================//
41
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
42
 * <p/>
43
 */
44
typedef struct {
45
		JNIEnv *env;
46
		HANDLE myDllHandle;
47
		JavaVM *jvm;
48
	} Environment;
49

  
50

  
51
//===============================================================================================//
52

  
53
/*! <code>MyParameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
54
 * <p/>
55
 */
56
typedef struct {
57
		char* name;
58
		jobject value;
59
	} MyParameter;
60

  
61
//===============================================================================================//
62

  
63
/*! <code>MyProperty</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
64
 * <p/>
65
 */
66
typedef struct {
67
		char * name;
68
		char * value;
69
	} MyProperty;
70

  
71
jobject cpp;
72

  
73

  
74

  
75
const char * failure;
76
/*
77
 * Load dll.
78
 */
79
HANDLE loadDll(char* name)
80
{
81
    HANDLE hDll = LoadLibrary (name);
82

  
83
    if (!hDll) {
84
        printf ("Unable to load %s\n", name);
85
        exit(1);
86
    }
87
#ifdef DEBUG
88
    printf ("%s loaded\n", name);
89
#endif
90
    return hDll;
91
}
92

  
93

  
94
jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
95
jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
96

  
97
/*
98
 * Initialize JET run-time.
99
 */
100
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv)
101
{
102
    int            result;
103
    JavaVMInitArgs args;
104

  
105
    JNI_GetDefaultJavaVMInitArgs_func = 
106
             (jint (JNICALL *) (void *args))
107
             GetProcAddress (myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
108

  
109
    JNI_CreateJavaVM_func =
110
             (jint (JNICALL *) (JavaVM **pvm, void **penv, void *args))
111
             GetProcAddress (myDllHandle, "JNI_CreateJavaVM");
112

  
113
    if(!JNI_GetDefaultJavaVMInitArgs_func) {
114
        printf ("%s doesn't contain public JNI_GetDefaultJavaVMInitArgs\n", dllname);
115
        exit (1);
116
    }
117

  
118
    if(!JNI_CreateJavaVM_func) {
119
        printf ("%s doesn't contain public JNI_CreateJavaVM\n", dllname);
120
        exit (1);
121
    }
122

  
123
    memset (&args, 0, sizeof(args));
124

  
125
    args.version = JNI_VERSION_1_2;
126
    result = JNI_GetDefaultJavaVMInitArgs_func(&args);
127
    if (result != JNI_OK) {
128
        printf ("JNI_GetDefaultJavaVMInitArgs() failed with result %d\n", result);
129
        exit(1);
130
    }
131
  
132
    /*
133
     * NOTE: no JVM is actually created
134
     * this call to JNI_CreateJavaVM is intended for JET RT initialization
135
     */
136
    result = JNI_CreateJavaVM_func (pjvm, (void **)penv, &args);
137
    if (result != JNI_OK) {
138
        printf ("JNI_CreateJavaVM() failed with result %d\n", result);
139
        exit(1);
140
    }
141
#ifdef DEBUG
142
    printf ("JET RT initialized\n");
143
    fflush (stdout);
144
#endif
145
}
146

  
147

  
148
/*
149
 * Look for class.
150
 */
151
jclass lookForClass (JNIEnv* penv, char* name)
152
{
153
    jclass clazz = (*penv)->FindClass (penv, name);
154

  
155
    if (!clazz) {
156
        printf("Unable to find class %s\n", name);
157
	return NULL;
158
    }
159
#ifdef DEBUG
160
    printf ("Class %s found\n", name);
161
    fflush (stdout);
162
#endif
163

  
164
    return clazz;
165
}
166

  
167

  
168
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments)
169
{
170
    jmethodID MID_init, mID;
171
    jobject obj;
172

  
173
    MID_init = (jmethodID)(*penv)->GetMethodID (penv, myClassInDll, "<init>", arguments);
174
    if (!MID_init) {
175
        printf("Error: MyClassInDll.<init>() not found\n");
176
	fflush (stdout);
177
        return 0;
178
    }
179

  
180
  return MID_init;
181
}
182

  
183
jobject createObject (JNIEnv* penv, jclass myClassInDll, const char * arguments)
184
{
185
    jmethodID MID_init, mID;
186
    jobject obj;
187

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

  
194
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_init, (jboolean)true);
195
      if (!obj) {
196
        printf("Error: failed to allocate an object\n");
197
        return NULL;
198
      }
199
    return obj;
200
}
201

  
202
void checkForException(Environment environ, jclass callingClass,  jobject callingObject){
203

  
204
    if ((*(environ.env))->ExceptionCheck(environ.env)) {
205
	char *  result1;
206
	const char * errorCode = NULL;
207
	jthrowable exc = (*(environ.env))->ExceptionOccurred(environ.env);
208
	(*(environ.env))->ExceptionDescribe(environ.env); //comment code
209
	 jclass exccls = (jclass)(*(environ.env))->GetObjectClass(environ.env, exc);
210
        jclass clscls = (jclass)(*(environ.env))->FindClass(environ.env, "java/lang/Class");
211

  
212
        jmethodID getName = (jmethodID)(*(environ.env))->GetMethodID(environ.env, clscls, "getName", "()Ljava/lang/String;");
213
        jstring name =(jstring)((*(environ.env))->CallObjectMethod(environ.env, exccls, getName));
214
        char const* utfName = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, name, 0);
215
	printf(utfName);
216

  
217
	 jmethodID  getMessage = (jmethodID)(*(environ.env))->GetMethodID(environ.env, exccls, "getMessage", "()Ljava/lang/String;");
218
	if(getMessage) {
219

  
220
		jstring message = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exc, getMessage));
221
		if(message) {        	
222
			char const* utfMessage = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, message, 0);
223
		}
224
	
225
	}
226

  
227
     }
228
	//return NULL;
229

  
230
}
231

  
232

  
233
void finalizeJavaRT (JavaVM* jvm)
234
{
235
    (*jvm)->DestroyJavaVM (jvm);
236
}
237

  
238

  
239

  
240

  
241

  
242
int query(Environment environ, int argc, const char* argv[]) {
243

  
244

  
245
    jmethodID MID_foo;
246
    jclass transClass = lookForClass(environ.env, "net/sf/saxon/Query");
247
    char methodName[] = "main";
248
    char args[] = "([Ljava/lang/String;)V";
249
    jobjectArray stringArray = NULL;
250
    MID_foo = (jmethodID)(*(environ.env))->GetStaticMethodID(environ.env, transClass, methodName, args);
251
    if (!MID_foo) {
252
	printf("\nError: MyClassInDll %s() not found\n",methodName);
253
	fflush (stdout);
254
        return -1;
255
    }
256
     if(argc < 2) {
257
	printf("\nError: Not enough arguments in Query");
258
	return 0;
259
    }
260
	   jclass stringClass = lookForClass(environ.env, "java/lang/String");
261
	   stringArray = (*(environ.env))->NewObjectArray(environ.env, (jint)argc-1, stringClass, 0 );
262
	   if(!stringArray) { return 0;}
263
  int i, j;
264
  for(i=1, j=0; i< argc; i++, j++) {
265
	     (*(environ.env))->SetObjectArrayElement(environ.env, stringArray, j, (*(environ.env))->NewStringUTF(environ.env, argv[i]));
266
	   }
267

  
268
   (*(environ.env))->CallStaticVoidMethod(environ.env, transClass, MID_foo, stringArray);
269
   
270
  (*(environ.env))->DeleteLocalRef(environ.env, stringArray);
271
	return 0;
272
}
273

  
274

  
275

  
276

  
277
int main( int argc, const char* argv[] )
278
{
279
    HANDLE myDllHandle;
280
    //JNIEnv *(environ.env);
281
    //JavaVM *jvm;
282
    jclass  myClassInDll;
283

  
284
    Environment environ;
285
    /*
286
     * First of all, load required component.
287
     * By the time of JET initialization, all components should be loaded.
288
     */
289
    environ.myDllHandle = loadDll (dllname);
290
   
291

  
292
    /*
293
     * Initialize JET run-time.
294
     * The handle of loaded component is used to retrieve Invocation API.
295
     */
296
    initJavaRT (environ.myDllHandle, &environ.jvm, &environ.env);
297
    query(environ, argc, argv);	
298

  
299
  
300
fflush(stdout);
301
    /*
302
     * Finalize JET run-time.
303
     */
304
    finalizeJavaRT (environ.jvm);
305

  
306
    return 0;
307
}
latest9.6/hec/command/Transform.c
1
#include <jni.h>
2

  
3
#ifdef __linux__
4
    #include <stdlib.h>
5
    #include <string.h>
6
    #include <dlfcn.h>
7
    #include <stdio.h>  
8
    #define HANDLE void*
9
    #define LoadLibrary(x) dlopen(x, RTLD_LAZY)
10
//    #define FreeLibrary(x) dlclose(x, RTLD_LAZY)
11
    #define GetProcAddress(x,y) dlsym(x,y)
12
#else
13
    #include <windows.h>
14
#endif
15

  
16
typedef int bool;
17
#define true 1
18
#define false 0
19

  
20

  
21
char dllname[] =
22
   // #ifdef __linux__
23
#ifdef EEC
24
        "/usr/lib/libsaxoneec.so";
25
#elif defined PEC
26
	"/usr/lib/libsaxonpec.so";
27
#else
28
	"/usr/lib/libsaxonhec.so";
29
#endif
30
/*    #else
31
#ifdef EEC
32
        "Saxon-eec.dll";
33
#elif defined PEC
34
	"Saxon-pec.dll";
35
#else
36
	"Saxon-hec.dll";
37
#endif
38

  
39
#endif
40
*/
41
//===============================================================================================//
42
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
43
 * <p/>
44
 */
45
typedef struct {
46
		JNIEnv *env;
47
		HANDLE myDllHandle;
48
		JavaVM *jvm;
49
	} Environment;
50

  
51

  
52
//===============================================================================================//
53

  
54
/*! <code>MyParameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
55
 * <p/>
56
 */
57
typedef struct {
58
		char* name;
59
		jobject value;
60
	} MyParameter;
61

  
62
//===============================================================================================//
63

  
64
/*! <code>MyProperty</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
65
 * <p/>
66
 */
67
typedef struct {
68
		char * name;
69
		char * value;
70
	} MyProperty;
71

  
72
jobject cpp;
73

  
74

  
75

  
76
const char * failure;
77
/*
78
 * Load dll.
79
 */
80
HANDLE loadDll(char* name)
81
{
82
    HANDLE hDll = LoadLibrary (name);
83

  
84
    if (!hDll) {
85
        printf ("Unable to load %s\n", name);
86
        exit(1);
87
    }
88
#ifdef DEBUG
89
    printf ("%s loaded\n", name);
90
#endif
91
    return hDll;
92
}
93

  
94

  
95
jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
96
jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
97

  
98
/*
99
 * Initialize JET run-time.
100
 */
101
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv)
102
{
103
    int            result;
104
    JavaVMInitArgs args;
105

  
106
    JNI_GetDefaultJavaVMInitArgs_func = 
107
             (jint (JNICALL *) (void *args))
108
             GetProcAddress (myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
109

  
110
    JNI_CreateJavaVM_func =
111
             (jint (JNICALL *) (JavaVM **pvm, void **penv, void *args))
112
             GetProcAddress (myDllHandle, "JNI_CreateJavaVM");
113

  
114
    if(!JNI_GetDefaultJavaVMInitArgs_func) {
115
        printf ("%s doesn't contain public JNI_GetDefaultJavaVMInitArgs\n", dllname);
116
        exit (1);
117
    }
118

  
119
    if(!JNI_CreateJavaVM_func) {
120
        printf ("%s doesn't contain public JNI_CreateJavaVM\n", dllname);
121
        exit (1);
122
    }
123

  
124
    memset (&args, 0, sizeof(args));
125

  
126
    args.version = JNI_VERSION_1_2;
127
    result = JNI_GetDefaultJavaVMInitArgs_func(&args);
128
    if (result != JNI_OK) {
129
        printf ("JNI_GetDefaultJavaVMInitArgs() failed with result %d\n", result);
130
        exit(1);
131
    }
132
  
133
    /*
134
     * NOTE: no JVM is actually created
135
     * this call to JNI_CreateJavaVM is intended for JET RT initialization
136
     */
137
    result = JNI_CreateJavaVM_func (pjvm, (void **)penv, &args);
138
    if (result != JNI_OK) {
139
        printf ("JNI_CreateJavaVM() failed with result %d\n", result);
140
        exit(1);
141
    }
142
#ifdef DEBUG
143
    printf ("JET RT initialized\n");
144
    fflush (stdout);
145
#endif
146
}
147

  
148

  
149
/*
150
 * Look for class.
151
 */
152
jclass lookForClass (JNIEnv* penv, char* name)
153
{
154
    jclass clazz = (*penv)->FindClass (penv, name);
155

  
156
    if (!clazz) {
157
        printf("Unable to find class %s\n", name);
158
	return NULL;
159
    }
160
#ifdef DEBUG
161
    printf ("Class %s found\n", name);
162
    fflush (stdout);
163
#endif
164

  
165
    return clazz;
166
}
167

  
168

  
169

  
170

  
171
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments)
172
{
173
    jmethodID MID_init, mID;
174
    jobject obj;
175

  
176
    MID_init = (jmethodID)(*penv)->GetMethodID (penv, myClassInDll, "<init>", arguments);
177
    if (!MID_init) {
178
        printf("Error: MyClassInDll.<init>() not found\n");
179
	fflush (stdout);
180
        return 0;
181
    }
182

  
183
  return MID_init;
184
}
185

  
186
jobject createObject (JNIEnv* penv, jclass myClassInDll, const char * arguments)
187
{
188
    jmethodID MID_init, mID;
189
    jobject obj;
190

  
191
    MID_init = (jmethodID)(*(penv))->GetMethodID (penv, myClassInDll, "<init>", arguments);
192
    if (!MID_init) {
193
        printf("Error: MyClassInDll.<init>() not found\n");
194
        return NULL;
195
    }
196

  
197
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_init, (jboolean)true);
198
      if (!obj) {
199
        printf("Error: failed to allocate an object\n");
200
        return NULL;
201
      }
202
    return obj;
203
}
204

  
205
void checkForException(Environment environ, jclass callingClass,  jobject callingObject){
206

  
207
    if ((*(environ.env))->ExceptionCheck(environ.env)) {
208
	char *  result1;
209
	const char * errorCode = NULL;
210
	jthrowable exc = (*(environ.env))->ExceptionOccurred(environ.env);
211
	(*(environ.env))->ExceptionDescribe(environ.env); //comment code
212
	 jclass exccls = (jclass)(*(environ.env))->GetObjectClass(environ.env, exc);
213
        jclass clscls = (jclass)(*(environ.env))->FindClass(environ.env, "java/lang/Class");
214

  
215
        jmethodID getName = (jmethodID)(*(environ.env))->GetMethodID(environ.env, clscls, "getName", "()Ljava/lang/String;");
216
        jstring name =(jstring)((*(environ.env))->CallObjectMethod(environ.env, exccls, getName));
217
        char const* utfName = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, name, 0);
218
	printf(utfName);
219

  
220
	 jmethodID  getMessage = (jmethodID)(*(environ.env))->GetMethodID(environ.env, exccls, "getMessage", "()Ljava/lang/String;");
221
	if(getMessage) {
222

  
223
		jstring message = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exc, getMessage));
224
		if(message) {        	
225
			char const* utfMessage = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, message, 0);
226
		}
227
	
228
	}
229

  
230
     }
231
	//return NULL;
232

  
233
}
234

  
235

  
236
void finalizeJavaRT (JavaVM* jvm)
237
{
238
    (*jvm)->DestroyJavaVM (jvm);
239
}
240

  
241

  
242

  
243

  
244

  
245
int transform(Environment environ, int argc, const char* argv[]) {
246

  
247

  
248
    jmethodID MID_foo;
249
    jclass transClass = lookForClass(environ.env, "net/sf/saxon/Transform");
250
    char methodName[] = "main";
251
    char args[] = "([Ljava/lang/String;)V";
252
    jobjectArray stringArray = NULL;
253
    MID_foo = (jmethodID)(*(environ.env))->GetStaticMethodID(environ.env, transClass, methodName, args);
254
    if (!MID_foo) {
255
	printf("\nError: MyClassInDll %s() not found\n",methodName);
256
	fflush (stdout);
257
        return -1;
258
    }
259
     if(argc < 2) {
260
	printf("\nError: Not enough arguments in Transform");
261
	return 0;
262
    }
263
	   jclass stringClass = lookForClass(environ.env, "java/lang/String");
264
	   stringArray = (*(environ.env))->NewObjectArray(environ.env, (jint)argc-1, stringClass, 0 );
265
	   if(!stringArray) { return 0;}
266
  int i, j;
267
  for(i=1, j=0; i< argc; i++, j++) {
268
	     (*(environ.env))->SetObjectArrayElement(environ.env, stringArray, j, (*(environ.env))->NewStringUTF(environ.env, argv[i]));
269
	   }
270

  
271
   (*(environ.env))->CallStaticVoidMethod(environ.env, transClass, MID_foo, stringArray);
272
   
273
  (*(environ.env))->DeleteLocalRef(environ.env, stringArray);
274
	return 0;
275
}
276

  
277

  
278

  
279

  
280
int main( int argc, const char* argv[] )
281
{
282
    HANDLE myDllHandle;
283
    //JNIEnv *(environ.env);
284
    //JavaVM *jvm;
285
    jclass  myClassInDll;
286

  
287
    Environment environ;
288
    /*
289
     * First of all, load required component.
290
     * By the time of JET initialization, all components should be loaded.
291
     */
292
    environ.myDllHandle = loadDll (dllname);
293
   
294

  
295
    /*
296
     * Initialize JET run-time.
297
     * The handle of loaded component is used to retrieve Invocation API.
298
     */
299
    initJavaRT (environ.myDllHandle, &environ.jvm, &environ.env);
300
    transform(environ, argc, argv);	
301

  
302
  
303
fflush(stdout);
304
    /*
305
     * Finalize JET run-time.
306
     */
307
    finalizeJavaRT (environ.jvm);
308

  
309
    return 0;
310
}
latest9.6/hec/command/Validate.c
1
#include <jni.h>
2

  
3
#ifdef __linux__
4
    #include <stdlib.h>
5
    #include <string.h>
6
    #include <dlfcn.h>
7
    #include <stdio.h>  
8
    #define HANDLE void*
9
    #define LoadLibrary(x) dlopen(x, RTLD_LAZY)
10
    #define GetProcAddress(x,y) dlsym(x,y)
11
#else
12
    #include <windows.h>
13
#endif
14

  
15
typedef int bool;
16
#define true 1
17
#define false 0
18

  
19

  
20
char dllname[] =
21
    #ifdef __linux__
22
#ifdef EEC
23
        "/usr/lib/libsaxoneec.so";
24
#elif defined PEC
25
	"/usr/lib/libsaxonpec.so";
26
#else
27
	"/usr/lib/libsaxonhec.so";
28
#endif
29
    #else
30
#ifdef EEC
31
        "Saxon-eec.dll";
32
#elif defined PEC
33
	"Saxon-pec.dll";
34
#else
35
	"Saxon-hec.dll";
36
#endif
37

  
38
#endif
39
//===============================================================================================//
40
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
41
 * <p/>
42
 */
43
typedef struct {
44
		JNIEnv *env;
45
		HANDLE myDllHandle;
46
		JavaVM *jvm;
47
	} Environment;
48

  
49

  
50
//===============================================================================================//
51

  
52
/*! <code>MyParameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
53
 * <p/>
54
 */
55
typedef struct {
56
		char* name;
57
		jobject value;
58
	} MyParameter;
59

  
60
//===============================================================================================//
61

  
62
/*! <code>MyProperty</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
63
 * <p/>
64
 */
65
typedef struct {
66
		char * name;
67
		char * value;
68
	} MyProperty;
69

  
70
jobject cpp;
71

  
72

  
73

  
74
const char * failure;
75
/*
76
 * Load dll.
77
 */
78
HANDLE loadDll(char* name)
79
{
80
    HANDLE hDll = LoadLibrary (name);
81

  
82
    if (!hDll) {
83
        printf ("Unable to load %s\n", name);
84
        exit(1);
85
    }
86
#ifdef DEBUG
87
    printf ("%s loaded\n", name);
88
#endif
89
    return hDll;
90
}
91

  
92

  
93
jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
94
jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
95

  
96
/*
97
 * Initialize JET run-time.
98
 */
99
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv)
100
{
101
    int            result;
102
    JavaVMInitArgs args;
103

  
104
    JNI_GetDefaultJavaVMInitArgs_func = 
105
             (jint (JNICALL *) (void *args))
106
             GetProcAddress (myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
107

  
108
    JNI_CreateJavaVM_func =
109
             (jint (JNICALL *) (JavaVM **pvm, void **penv, void *args))
110
             GetProcAddress (myDllHandle, "JNI_CreateJavaVM");
111

  
112
    if(!JNI_GetDefaultJavaVMInitArgs_func) {
113
        printf ("%s doesn't contain public JNI_GetDefaultJavaVMInitArgs\n", dllname);
114
        exit (1);
115
    }
116

  
117
    if(!JNI_CreateJavaVM_func) {
118
        printf ("%s doesn't contain public JNI_CreateJavaVM\n", dllname);
119
        exit (1);
120
    }
121

  
122
    memset (&args, 0, sizeof(args));
123

  
124
    args.version = JNI_VERSION_1_2;
125
    result = JNI_GetDefaultJavaVMInitArgs_func(&args);
126
    if (result != JNI_OK) {
127
        printf ("JNI_GetDefaultJavaVMInitArgs() failed with result %d\n", result);
128
        exit(1);
129
    }
130
  
131
    /*
132
     * NOTE: no JVM is actually created
133
     * this call to JNI_CreateJavaVM is intended for JET RT initialization
134
     */
135
    result = JNI_CreateJavaVM_func (pjvm, (void **)penv, &args);
136
    if (result != JNI_OK) {
137
        printf ("JNI_CreateJavaVM() failed with result %d\n", result);
138
        exit(1);
139
    }
140
#ifdef DEBUG
141
    printf ("JET RT initialized\n");
142
    fflush (stdout);
143
#endif
144
}
145

  
146

  
147
/*
148
 * Look for class.
149
 */
150
jclass lookForClass (JNIEnv* penv, char* name)
151
{
152
    jclass clazz = (*penv)->FindClass (penv, name);
153

  
154
    if (!clazz) {
155
        printf("Unable to find class %s\n", name);
156
	return NULL;
157
    }
158
#ifdef DEBUG
159
    printf ("Class %s found\n", name);
160
    fflush (stdout);
161
#endif
162

  
163
    return clazz;
164
}
165

  
166

  
167

  
168
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments)
169
{
170
    jmethodID MID_init, mID;
171
    jobject obj;
172

  
173
    MID_init = (jmethodID)(*penv)->GetMethodID (penv, myClassInDll, "<init>", arguments);
174
    if (!MID_init) {
175
        printf("Error: MyClassInDll.<init>() not found\n");
176
	fflush (stdout);
177
        return 0;
178
    }
179

  
180
  return MID_init;
181
}
182

  
183
jobject createObject (JNIEnv* penv, jclass myClassInDll, const char * arguments)
184
{
185
    jmethodID MID_init, mID;
186
    jobject obj;
187

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

  
194
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_init, (jboolean)true);
195
      if (!obj) {
196
        printf("Error: failed to allocate an object\n");
197
        return NULL;
198
      }
199
    return obj;
200
}
201

  
202
void checkForException(Environment environ, jclass callingClass,  jobject callingObject){
203

  
204
    if ((*(environ.env))->ExceptionCheck(environ.env)) {
205
	char *  result1;
206
	const char * errorCode = NULL;
207
	jthrowable exc = (*(environ.env))->ExceptionOccurred(environ.env);
208
	(*(environ.env))->ExceptionDescribe(environ.env); //comment code
209
	 jclass exccls = (jclass)(*(environ.env))->GetObjectClass(environ.env, exc);
210
        jclass clscls = (jclass)(*(environ.env))->FindClass(environ.env, "java/lang/Class");
211

  
212
        jmethodID getName = (jmethodID)(*(environ.env))->GetMethodID(environ.env, clscls, "getName", "()Ljava/lang/String;");
213
        jstring name =(jstring)((*(environ.env))->CallObjectMethod(environ.env, exccls, getName));
214
        char const* utfName = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, name, 0);
215
	printf(utfName);
216

  
217
	 jmethodID  getMessage = (jmethodID)(*(environ.env))->GetMethodID(environ.env, exccls, "getMessage", "()Ljava/lang/String;");
218
	if(getMessage) {
219

  
220
		jstring message = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exc, getMessage));
221
		if(message) {        	
222
			char const* utfMessage = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, message, 0);
223
		}
224
	
225
	}
226

  
227
     }
228
	//return NULL;
229

  
230
}
231

  
232

  
233
void finalizeJavaRT (JavaVM* jvm)
234
{
235
    (*jvm)->DestroyJavaVM (jvm);
236
}
237

  
238

  
239

  
240

  
241

  
242
int validate(Environment environ, int argc, const char* argv[]) {
243

  
244

  
245
    jmethodID MID_foo;
246
    jclass transClass = lookForClass(environ.env, "com/saxonica/Validate");
247
    char methodName[] = "main";
248
    char args[] = "([Ljava/lang/String;)V";
249
    jobjectArray stringArray = NULL;
250
    MID_foo = (jmethodID)(*(environ.env))->GetStaticMethodID(environ.env, transClass, methodName, args);
251
    if (!MID_foo) {
252
	printf("\nError: MyClassInDll %s() not found\n",methodName);
253
	fflush (stdout);
254
        return -1;
255
    }
256
     if(argc < 2) {
257
	printf("\nError: Not enough arguments in Validate");
258
	return 0;
259
    }
260
	   jclass stringClass = lookForClass(environ.env, "java/lang/String");
261
	   stringArray = (*(environ.env))->NewObjectArray(environ.env, (jint)argc-1, stringClass, 0 );
262
	   if(!stringArray) { return 0;}
263
  int i, j;
264
  for(i=1, j=0; i< argc; i++, j++) {
265
	     (*(environ.env))->SetObjectArrayElement(environ.env, stringArray, j, (*(environ.env))->NewStringUTF(environ.env, argv[i]));
266
	   }
267

  
268
   (*(environ.env))->CallStaticVoidMethod(environ.env, transClass, MID_foo, stringArray);
269
   
270
  (*(environ.env))->DeleteLocalRef(environ.env, stringArray);
271
	return 0;
272
}
273

  
274

  
275

  
276

  
277
int main( int argc, const char* argv[] )
278
{
279
    HANDLE myDllHandle;
280
    //JNIEnv *(environ.env);
281
    //JavaVM *jvm;
282
    jclass  myClassInDll;
283

  
284
    Environment environ;
285
    /*
286
     * First of all, load required component.
287
     * By the time of JET initialization, all components should be loaded.
288
     */
289
    environ.myDllHandle = loadDll (dllname);
290
   
291

  
292
    /*
293
     * Initialize JET run-time.
294
     * The handle of loaded component is used to retrieve Invocation API.
295
     */
296
    initJavaRT (environ.myDllHandle, &environ.jvm, &environ.env);
297
    validate(environ, argc, argv);	
298

  
299
  
300
fflush(stdout);
301
    /*
302
     * Finalize JET run-time.
303
     */
304
    finalizeJavaRT (environ.jvm);
305

  
306
    return 0;
307
}
latest9.6/hec/command/buildeec-command.sh
1
#!/bin/sh
2

  
3
#Build file for Saxon/C on C++
4

  
5
#jdkdir=/usr/lib/jvm/java-7-oracle/include
6

  
7
# $jdkdir/bin/javac MyClassInDll.java
8

  
9
#jc =p MyDll.prj
10
#rm -rf MyDll_jetpdb
11
export JET_HOME=/usr/lib/rt
12
export PATH=$JET_HOME/bin:$PATH
13
export LD_LIBRARY_PATH=$JET_HOME/lib/x86/shared:$LD_LIBRARY_PATH
14

  
15

  
16

  
17
gcc  Transform.c -o transform -ldl -lc -lsaxoneec -DEEC $1 $2
18

  
19
gcc  Query.c -o query -ldl -lc -lsaxoneec -DEEC $1 $2
20

  
21
gcc  Validate.c -o validate -ldl -lc -lsaxoneec -DEEC $1 $2
22

  
latest9.6/hec/command/buildhec-command.sh
1
#!/bin/sh
2

  
3
#Build file for Saxon/C on C++
4

  
5
#jdkdir=/usr/lib/jvm/java-7-oracle/include
6

  
7
# $jdkdir/bin/javac MyClassInDll.java
8

  
9
#jc =p MyDll.prj
10
#rm -rf MyDll_jetpdb
11
export JET_HOME=/usr/lib/rt
12
export PATH=$JET_HOME/bin:$PATH
13
export LD_LIBRARY_PATH=$JET_HOME/lib/x86/shared:$LD_LIBRARY_PATH
14

  
15

  
16

  
17
gcc  Transform.c -o transform -ldl -lc -lsaxonhec -DHEC $1 $2
18

  
19
gcc  Query.c -o query -ldl -lc -lsaxonhec -DHEC $1 $2
20

  
21
gcc  Validate.c -o validate -ldl -lc -lsaxonhec -DHEC $1 $2
22

  
latest9.6/hec/command/buildpec-command.sh
1
#!/bin/sh
2

  
3
#Build file for Saxon/C on C++
4

  
5
#jdkdir=/usr/lib/jvm/java-7-oracle/include
6

  
7
# $jdkdir/bin/javac MyClassInDll.java
8

  
9
#jc =p MyDll.prj
10
#rm -rf MyDll_jetpdb
11
export JET_HOME=/usr/lib/rt
12
export PATH=$JET_HOME/bin:$PATH
13
export LD_LIBRARY_PATH=$JET_HOME/lib/x86/shared:$LD_LIBRARY_PATH
14

  
15

  
16

  
17
gcc  Transform.c -o transform -ldl -lc -lsaxonpec -DPEC $1 $2
18

  
19
gcc  Query.c -o query -ldl -lc -lsaxonpec -DPEC $1 $2
20

  
21
gcc  Validate.c -o validate -ldl -lc -lsaxonpec -DPEC $1 $2
22

  

Also available in: Unified diff