Project

Profile

Help

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

he / latest9.6 / hec / Saxon.C.API / EEC / SaxonCGlue.h @ 2ebe3898

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
(2-2/2)