Project

Profile

Help

How to connect?
Download (5.28 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.6 / hec / Saxon.C.API / 64-bit-code / HEC / SaxonCGlue.h @ 08c871b9

1
#ifndef SAXONCGLUE_H 
2
#define SAXONCGLUE_H
3
#include <jni.h>
4

    
5

    
6
#if defined __linux__ || defined __APPLE__
7
#include <stdlib.h>
8
#include <string.h>
9
#include <dlfcn.h>
10

    
11

    
12
#define HANDLE void*
13
#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
14
#define GetProcAddress(x,y) dlsym(x,y)
15
#else
16
#include <windows.h>
17
#endif
18

    
19
#ifdef __cplusplus
20
#define EXTERN_C extern "C" {
21
#define EXTERN_C_END }
22
#else
23
#define EXTERN_C
24
#define EXTERN_C_END
25
#endif
26

    
27
#ifndef __cplusplus
28
#ifndef _BOOL
29
typedef unsigned char bool;
30
static const bool false = 0;
31
static const bool true = 1;
32
#endif
33
#endif
34

    
35
#ifndef __cplusplus 
36
        #if defined(LICENSE)
37
                #define license true;
38
        #else
39
                #define license false
40
        #endif
41
#endif
42

    
43

    
44
//#define DEBUG
45

    
46

    
47
EXTERN_C
48

    
49

    
50

    
51

    
52
static char dllname[] =
53
    #ifdef __linux__
54
        "/usr/lib64/libsaxonhec.so";  //rename according to product edition (-hec or -pec) Also make change in the c file
55
    #elif  defined (__APPLE__) && defined(__MACH__)
56
        "/usr/lib/libsaxon-hec.dylib";
57
    #else
58
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.0\\libsaxon-hec.dll";
59
    #endif
60

    
61
static char resources_dir[] = 
62
     #ifdef __linux__
63
        "/usr/lib/saxon-data";
64
    #elif  defined (__APPLE__) && defined(__MACH__)
65
        "/usr/lib/saxon-data";
66
    #else
67
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.0\\saxon-data";
68
    #endif
69

    
70

    
71
//===============================================================================================//
72
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
73
 * <p/>
74
 */
75
typedef struct {
76
                JNIEnv *env;
77
                HANDLE myDllHandle;
78
                JavaVM *jvm;
79
        } sxnc_environment;
80

    
81

    
82
//===============================================================================================//
83

    
84
/*! <code>sxnc_parameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
85
 * <p/>
86
 */
87
typedef struct {
88
                char* name;
89
                jobject value;
90
        } sxnc_parameter;
91

    
92
//===============================================================================================//
93

    
94
/*! <code>sxnc_property</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
95
 * <p/>
96
 */
97
typedef struct {
98
                char * name;
99
                char * value;
100
        } sxnc_property;
101

    
102

    
103

    
104
extern jobject cpp;
105

    
106

    
107

    
108
extern const char * failure;
109

    
110

    
111
/*
112
* Get Dll name.
113
*/
114

    
115
char * getDllname();
116

    
117

    
118
/*
119
* Set Dll name. Also set the saxon resources directory. 
120
* If the SAXON_HOME environmental variable is set then use that as base.
121
*/
122
void setDllname();
123

    
124
/*
125
 * Load dll using the default setting in Saxon/C
126
 * Recommended method to use to load library
127
 */
128
HANDLE loadDefaultDll();
129

    
130

    
131
/*
132
 * Load dll.
133
 * name - The dll library
134
 */
135
HANDLE loadDll(char* name);
136

    
137

    
138
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
139

    
140
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
141

    
142
/*
143
 * Initialize JET run-time with simplified method. The initJavaRT method will be called 
144
 * with the arguments expanded from environ
145
 * @param environ - the Evironment is passed
146
 */
147
void initDefaultJavaRT(sxnc_environment ** environ);
148

    
149

    
150
/*
151
 * Initialize JET run-time.
152
 */
153
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
154

    
155

    
156
/*
157
 * Look for class.
158
 */
159
jclass lookForClass (JNIEnv* penv, const char* name);
160

    
161

    
162
/*
163
 * Create an object and invoke the instance method
164
 */
165
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
166

    
167

    
168

    
169

    
170
/*
171
 * Invoke the static method
172
 */
173
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
174

    
175

    
176
/*
177
 * Find a constructor with a set arguments
178
 */
179
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
180

    
181
/*
182
 * Create the Java SaxonProcessor
183
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
184
 */
185
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
186

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

    
193
/*
194
 * Callback to check for exceptions. When called it returns the exception as a string 
195
 */
196
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
197

    
198
/*
199
 * Clean up and destroy Java VM to release memory used. 
200
 */
201
void finalizeJavaRT (JavaVM* jvm);
202

    
203

    
204
/*
205
 * Get a parameter from list 
206
 */
207
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name);
208

    
209
/*
210
 * Get a property from list 
211
 */
212
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
213

    
214

    
215
/*
216
 * set a parameter 
217
 */
218
void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
219

    
220

    
221
/*
222
 * set a property 
223
 */
224
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
225

    
226
/*
227
 * clear parameter 
228
 */
229
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
230

    
231

    
232

    
233
const char * stringValue(sxnc_environment environ, jobject value);
234

    
235
EXTERN_C_END
236

    
237

    
238
#endif //SAXONCGLUE_H
(3-3/3)