Project

Profile

Help

Revision 6304fb8b

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes and development work

View differences:

latest10/hec/Saxon.C.API/SaxonProcessor.cpp
1
#ifndef __linux__ 
1
#ifndef __linux__
2 2
#ifndef __APPLE__
3
	//#include "stdafx.h"
4
	#include <Tchar.h>
3
//#include "stdafx.h"
4
#include <Tchar.h>
5 5
#endif
6 6
#endif
7 7

  
8

  
9
//#include "stdafx.h"
10 8
#include "SaxonProcessor.h"
11 9
#include "XdmValue.h"
12 10
#include "XdmItem.h"
13 11
#include "XdmNode.h"
12
#include "XdmFunctionItem.h"
13
#include "XdmMap.h"
14
#include "XdmArray.h"
14 15
#include "XdmAtomicValue.h"
15
#if CVERSION_API_NO >= 123
16
    #include "XdmFunctionItem.h"
17
    #include "XdmMap.h"
18
    #include "XdmArray.h"
19
#endif
20 16

  
21 17
//#define DEBUG
22 18
#ifdef DEBUG
23 19
#include <signal.h>
24 20
#endif
21

  
25 22
#include <stdio.h>
26 23

  
27 24

  
28 25
//jobject cpp;
29
const char * failure;
30
sxnc_environment * SaxonProcessor::sxn_environ = 0;
31
int SaxonProcessor::jvmCreatedCPP=0;
26
const char *failure;
27
sxnc_environment *SaxonProcessor::sxn_environ = 0;
28
int SaxonProcessor::jvmCreatedCPP = 0;
32 29

  
33
bool SaxonProcessor::exceptionOccurred(){
34
	bool found = SaxonProcessor::sxn_environ->env->ExceptionCheck();
35
	return found;
30
bool SaxonProcessor::exceptionOccurred() {
31
    bool found = SaxonProcessor::sxn_environ->env->ExceptionCheck();
32
    return found;
36 33
}
37 34

  
38
const char* SaxonProcessor::checkException(jobject cpp) {
39
		const char * message = NULL;
40
		message = checkForException(sxn_environ, cpp);
41
		return message;
42
	}
35
const char *SaxonProcessor::checkException(jobject cpp) {
36
    const char *message = nullptr;
37
    message = checkForException(sxn_environ, cpp);
38
    return message;
39
}
43 40

  
44
SaxonApiException * SaxonProcessor::checkAndCreateException(jclass cppClass){
45
		if(exceptionOccurred()) {
46
		    SaxonApiException * exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
41
SaxonApiException *SaxonProcessor::checkAndCreateException(jclass cppClass) {
42
    if (exceptionOccurred()) {
43
        SaxonApiException *exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
47 44
#ifdef DEBUG
48
		    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
45
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
49 46
#endif
50
		    return exception;
51
		}
52
		return NULL;
53
	}
54

  
55
void SaxonProcessor::exceptionClear(){
56
	SaxonProcessor::sxn_environ->env->ExceptionClear();
57
	/* if(exception != NULL && clearCPPException) {
58
		delete exception;
59
	} */
47
        return exception;
48
    }
49
    return nullptr;
60 50
}
61 51

  
52
void SaxonProcessor::exceptionClear() {
53
    SaxonProcessor::sxn_environ->env->ExceptionClear();
54
    /* if(exception != nullptr && clearCPPException) {
55
        delete exception;
56
    } */
57
}
62 58

  
63 59

  
64 60
SaxonProcessor::SaxonProcessor() {
......
67 63
}
68 64

  
69 65

  
70

  
71
SaxonApiException * SaxonProcessor::checkForExceptionCPP(JNIEnv* env, jclass callingClass,  jobject callingObject){
66
SaxonApiException *SaxonProcessor::checkForExceptionCPP(JNIEnv *env, jclass callingClass, jobject callingObject) {
72 67

  
73 68
    if (env->ExceptionCheck()) {
74
	std::string result1 = "";
75
	std::string errorCode = "";
76
	jthrowable exc = env->ExceptionOccurred();
69
        std::string result1 = "";
70
        std::string errorCode = "";
71
        jthrowable exc = env->ExceptionOccurred();
77 72

  
78
#ifdef DEBUG	
79
	env->ExceptionDescribe();
73
#ifdef DEBUG
74
        env->ExceptionDescribe();
80 75
#endif
81
	 jclass exccls(env->GetObjectClass(exc));
76
        jclass exccls(env->GetObjectClass(exc));
82 77
        jclass clscls(env->FindClass("java/lang/Class"));
83 78

  
84 79
        jmethodID getName(env->GetMethodID(clscls, "getName", "()Ljava/lang/String;"));
85 80
        jstring name(static_cast<jstring>(env->CallObjectMethod(exccls, getName)));
86
        char const* utfName(env->GetStringUTFChars(name, 0));
87
	    result1 = (std::string(utfName));
88
	    env->ReleaseStringUTFChars(name, utfName);
89

  
90
	 jmethodID  getMessage(env->GetMethodID(exccls, "getMessage", "()Ljava/lang/String;"));
91
	if(getMessage) {
92

  
93
		jstring message((jstring)(env->CallObjectMethod(exc, getMessage)));
94
		char const* utfMessage = NULL;		
95
		if(!message) {
96
			utfMessage = "";
97
			return NULL;
98
		} else {
99
        		utfMessage = (env->GetStringUTFChars(message, 0));
100
		}
101
		if(utfMessage != NULL) {
102
			result1 = (result1 + " : ") + utfMessage;
103
		} 
104
		
105
		env->ReleaseStringUTFChars(message,utfMessage);
106

  
107
		if(callingObject != NULL && result1.compare(0,43, "net.sf.saxon.s9api.SaxonApiException", 43) == 0){
108

  
109
			jclass saxonApiExceptionClass(env->FindClass("net/sf/saxon/s9api/SaxonApiException"));
110
			static jmethodID lineNumID = NULL;
111
			if(lineNumID == NULL) {
112
			    lineNumID = env->GetMethodID(saxonApiExceptionClass, "getLinenumber", "()I");
113
			}
114
			static jmethodID ecID = NULL;
115
			if(ecID == NULL) {
116
			    ecID = env->GetMethodID(saxonApiExceptionClass, "getErrorCode", "()Ljnet/sf/saxon/s9api/QName;");
117
			}
118
			static jmethodID esysID = NULL;
119
			if(esysID == NULL) {
120
			    esysID = env->GetMethodID(saxonApiExceptionClass, "getSystemId", "()Ljava/lang/String;");
121
			}
122

  
123

  
124
			jobject errCodeQName = (jobject)(env->CallObjectMethod(exc, ecID));
125
			jstring errSystemID = (jstring)(env->CallObjectMethod(exc, esysID));
126
			int linenum = env->CallIntMethod(exc, lineNumID);
127

  
128
			jclass qnameClass(env->FindClass("net/sf/saxon/s9api/QName"));
129
            static jmethodID qnameStrID = NULL;
130
            if(qnameStrID == NULL) {
131
                qnameStrID = env->GetMethodID(qnameClass, "toString", "()Ljava/lang/String;");
81
        char const *utfName(env->GetStringUTFChars(name, 0));
82
        result1 = (std::string(utfName));
83
        env->ReleaseStringUTFChars(name, utfName);
84

  
85
        jmethodID getMessage(env->GetMethodID(exccls, "getMessage", "()Ljava/lang/String;"));
86
        if (getMessage) {
87

  
88
            jstring message((jstring) (env->CallObjectMethod(exc, getMessage)));
89
            char const *utfMessage = nullptr;
90
            if (!message) {
91
                utfMessage = "";
92
                return nullptr;
93
            } else {
94
                utfMessage = (env->GetStringUTFChars(message, 0));
95
            }
96
            if (utfMessage != nullptr) {
97
                result1 = (result1 + " : ") + utfMessage;
132 98
            }
133 99

  
134
            jstring qnameStr = (jstring)(env->CallObjectMethod(errCodeQName, qnameStrID));
135

  
136

  
137
			SaxonApiException * saxonExceptions = new SaxonApiException(result1.c_str(), (qnameStr ? env->GetStringUTFChars(qnameStr,0) : NULL)  ,(errSystemID ? env->GetStringUTFChars(errSystemID,0) : NULL),linenum);
138

  
139
            if(errCodeQName) {
140
			    env->DeleteLocalRef(errCodeQName);
141
			}
142
			if(errSystemID) {
143
			    env->DeleteLocalRef(errSystemID);
144
			}
145
			if(qnameStr) {
146
			    env->DeleteLocalRef(qnameStr);
147
			}
148

  
149
			if(message) {
150
           	    env->DeleteLocalRef(message);
151
   			}
152
			env->ExceptionClear();
153
			return saxonExceptions;
154
		}
155
	}
156
	SaxonApiException * saxonExceptions = new SaxonApiException(result1.c_str());
157
	//env->ExceptionDescribe();
158
	env->ExceptionClear();
159
	return saxonExceptions;
160
     }
161
	return NULL;
100
            env->ReleaseStringUTFChars(message, utfMessage);
101

  
102
            if (callingObject != nullptr && result1.compare(0, 43, "net.sf.saxon.s9api.SaxonApiException", 43) == 0) {
103

  
104
                jclass saxonApiExceptionClass(env->FindClass("net/sf/saxon/s9api/SaxonApiException"));
105
                static jmethodID lineNumID = nullptr;
106
                if (lineNumID == nullptr) {
107
                    lineNumID = env->GetMethodID(saxonApiExceptionClass, "getLinenumber", "()I");
108
                }
109
                static jmethodID ecID = nullptr;
110
                if (ecID == nullptr) {
111
                    ecID = env->GetMethodID(saxonApiExceptionClass, "getErrorCode", "()Ljnet/sf/saxon/s9api/QName;");
112
                }
113
                static jmethodID esysID = nullptr;
114
                if (esysID == nullptr) {
115
                    esysID = env->GetMethodID(saxonApiExceptionClass, "getSystemId", "()Ljava/lang/String;");
116
                }
117

  
118

  
119
                jobject errCodeQName = (jobject) (env->CallObjectMethod(exc, ecID));
120
                jstring errSystemID = (jstring) (env->CallObjectMethod(exc, esysID));
121
                int linenum = env->CallIntMethod(exc, lineNumID);
122

  
123
                jclass qnameClass(env->FindClass("net/sf/saxon/s9api/QName"));
124
                static jmethodID qnameStrID = nullptr;
125
                if (qnameStrID == nullptr) {
126
                    qnameStrID = env->GetMethodID(qnameClass, "toString", "()Ljava/lang/String;");
127
                }
128

  
129
                jstring qnameStr = (jstring) (env->CallObjectMethod(errCodeQName, qnameStrID));
130

  
131

  
132
                SaxonApiException *saxonExceptions = new SaxonApiException(result1.c_str(),
133
                                                                           (qnameStr ? env->GetStringUTFChars(qnameStr,
134
                                                                                                              0)
135
                                                                                     : nullptr),
136
                                                                           (errSystemID ? env->GetStringUTFChars(
137
                                                                                   errSystemID, 0) : nullptr), linenum);
138

  
139
                if (errCodeQName) {
140
                    env->DeleteLocalRef(errCodeQName);
141
                }
142
                if (errSystemID) {
143
                    env->DeleteLocalRef(errSystemID);
144
                }
145
                if (qnameStr) {
146
                    env->DeleteLocalRef(qnameStr);
147
                }
148

  
149
                if (message) {
150
                    env->DeleteLocalRef(message);
151
                }
152
                env->ExceptionClear();
153
                return saxonExceptions;
154
            }
155
        }
156
        SaxonApiException *saxonExceptions = new SaxonApiException(result1.c_str());
157
        //env->ExceptionDescribe();
158
        env->ExceptionClear();
159
        return saxonExceptions;
160
    }
161
    return nullptr;
162 162

  
163 163
}
164 164

  
165 165

  
166
SaxonProcessor::SaxonProcessor(bool l) {
166 167

  
167
SaxonProcessor::SaxonProcessor(bool l){
168

  
169
    cwd="";
168
    cwd = "";
170 169
    licensei = l;
171
    versionStr = NULL;
170
    versionStr = nullptr;
171

  
172
    if (SaxonProcessor::jvmCreatedCPP == 0) {
173
        SaxonProcessor::jvmCreatedCPP = 1;
174
        SaxonProcessor::sxn_environ = new sxnc_environment;//(sxnc_environment *)malloc(sizeof(sxnc_environment));
172 175

  
173
     if(SaxonProcessor::jvmCreatedCPP == 0){
174
	SaxonProcessor::jvmCreatedCPP=1;
175
    SaxonProcessor::sxn_environ= new sxnc_environment;//(sxnc_environment *)malloc(sizeof(sxnc_environment));
176 176

  
177
        /*
178
         * First of all, load required component.
179
         * By the time of JET initialization, all components should be loaded.
180
         */
177 181

  
178
    /*
179
     * First of all, load required component.
180
     * By the time of JET initialization, all components should be loaded.
181
     */
182
        SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll();
182 183

  
183
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
184
	
185
    /*
186
     * Initialize JET run-time.
187
     * The handle of loaded component is used to retrieve Invocation API.
188
     */
189
    initDefaultJavaRT (SaxonProcessor::sxn_environ);
184
        /*
185
         * Initialize JET run-time.
186
         * The handle of loaded component is used to retrieve Invocation API.
187
         */
188
        initDefaultJavaRT(SaxonProcessor::sxn_environ);
190 189
    } else {
191 190
#ifdef DEBUG
192
     std::cerr<<"SaxonProc constructor: jvm exists! jvmCreatedCPP="<<jvmCreatedCPP<<std::endl;
191
        std::cerr<<"SaxonProc constructor: jvm exists! jvmCreatedCPP="<<jvmCreatedCPP<<std::endl;
193 192
#endif
194 193

  
195
}
194
    }
195

  
196 196

  
197
 
198 197
    versionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/Version");
199 198
    procClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/Processor");
200 199
    saxonCAPIClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/SaxonCAPI");
201
    
202
    jobject proci = createSaxonProcessor (SaxonProcessor::sxn_environ->env, procClass, "(Z)V", NULL, licensei);
200

  
201
    jobject proci = createSaxonProcessor(SaxonProcessor::sxn_environ->env, procClass, "(Z)V", nullptr, licensei);
203 202
    proc = SaxonProcessor::sxn_environ->env->NewGlobalRef(proci);
204
	if(!proc) {
205
		std::cout<<"proc is NULL in SaxonProcessor constructor"<<std::endl;
206
	}
203
    if (!proc) {
204
        std::cout << "proc is nullptr in SaxonProcessor constructor" << std::endl;
205
    }
207 206

  
208 207
    xdmAtomicClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
209 208
#ifdef DEBUG
210
	jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "setDebugMode", "(Z)V");
211
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(saxonCAPIClass, debugMID, (jboolean)true);
209
    jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "setDebugMode", "(Z)V");
210
    SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(saxonCAPIClass, debugMID, (jboolean)true);
212 211
#endif
213 212
}
214 213

  
215
SaxonProcessor::SaxonProcessor(const char * configFile){
216
    cwd="";
217
    versionStr = NULL;
214
SaxonProcessor::SaxonProcessor(const char *configFile) {
215
    cwd = "";
216
    versionStr = nullptr;
218 217

  
219
    if(SaxonProcessor::jvmCreatedCPP == 0){
220
	SaxonProcessor::jvmCreatedCPP=1;
221
    //SaxonProcessor::sxn_environ= new sxnc_environment;
222
	SaxonProcessor::sxn_environ= (sxnc_environment *)malloc(sizeof(sxnc_environment));
218
    if (SaxonProcessor::jvmCreatedCPP == 0) {
219
        SaxonProcessor::jvmCreatedCPP = 1;
220
        //SaxonProcessor::sxn_environ= new sxnc_environment;
221
        SaxonProcessor::sxn_environ = (sxnc_environment *) malloc(sizeof(sxnc_environment));
223 222

  
224
    /*
225
     * First of all, load required component.
226
     * By the time of JET initialization, all components should be loaded.
227
     */
223
        /*
224
         * First of all, load required component.
225
         * By the time of JET initialization, all components should be loaded.
226
         */
228 227

  
229
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
228
        SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll();
230 229

  
231
    /*
232
     * Initialize JET run-time.
233
     * The handle of loaded component is used to retrieve Invocation API.
234
     */
235
    initDefaultJavaRT (SaxonProcessor::sxn_environ); 
230
        /*
231
         * Initialize JET run-time.
232
         * The handle of loaded component is used to retrieve Invocation API.
233
         */
234
        initDefaultJavaRT(SaxonProcessor::sxn_environ);
236 235
    }
237
 
236

  
238 237
    versionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/Version");
239 238

  
240 239
    procClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/Processor");
241 240
    saxonCAPIClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/SaxonCAPI");
242 241

  
243
     static jmethodID mIDcreateProc = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,"createSaxonProcessor",
244
					"(Ljava/lang/String;)Lnet/sf/saxon/s9api/Processor;");
245
		if (!mIDcreateProc) {
246
			std::cerr << "Error: SaxonDll." << "getPrimitiveTypeName"
247
				<< " not found\n" << std::endl;
248
			return ;
249
		}
250
	jboject proci = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDcreateProc,SaxonProcessor::sxn_environ->env->NewStringUTF(configFile));
251
	proc = SaxonProcessor::sxn_environ->env->NewGlobalRef(proci);
252
	if(!proc) {
253
		checkAndCreateException(saxonCAPIClass);
254
		std::cerr << "Error: "<<getDllname() << ". processor is NULL in constructor(configFile)"<< std::endl;
255
		return ;	
256
	}
257
	
258
     licensei = true;
242
    static jmethodID mIDcreateProc = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,
243
                                                                                                     "createSaxonProcessor",
244
                                                                                                     "(Ljava/lang/String;)Lnet/sf/saxon/s9api/Processor;");
245
    if (!mIDcreateProc) {
246
        std::cerr << "Error: SaxonDll." << "getPrimitiveTypeName"
247
                  << " not found\n" << std::endl;
248
        return;
249
    }
250
    jobject proci = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDcreateProc,
251
                                                                             SaxonProcessor::sxn_environ->env->NewStringUTF(
252
                                                                                     configFile));
253
    proc = SaxonProcessor::sxn_environ->env->NewGlobalRef(proci);
254
    if (!proc) {
255
        checkAndCreateException(saxonCAPIClass);
256
        std::cerr << "Error: " << getDllname() << ". processor is nullptr in constructor(configFile)" << std::endl;
257
        return;
258
    }
259

  
260
    licensei = true;
259 261
#ifdef DEBUG
260 262

  
261
     std::cerr<<"SaxonProc constructor(configFile)"<<std::endl;
263
    std::cerr<<"SaxonProc constructor(configFile)"<<std::endl;
262 264
#endif
263 265
    xdmAtomicClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
264 266
}
265 267

  
266
    SaxonProcessor::~SaxonProcessor(){
267
	clearConfigurationProperties();
268
	SaxonProcessor::sxn_environ->env->NewDeleteGlobalRef(proc);
269
	if(versionStr != NULL) {
270
		delete versionStr;
271
	}
272
   }
268
SaxonProcessor::~SaxonProcessor() {
269
    clearConfigurationProperties();
270
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(proc);
271
    if (versionStr != nullptr) {
272
        delete versionStr;
273
    }
274
}
273 275

  
274 276

  
275
bool SaxonProcessor::isSchemaAwareProcessor(){
276
	if(!licensei) {
277
		return false;
278
	} else {
279
		static jmethodID MID_schema = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID(procClass, "isSchemaAware", "()Z");
280
    		if (!MID_schema) {
281
        		std::cerr<<"\nError: Saxonc "<<"SaxonProcessor.isSchemaAware()"<<" not found"<<std::endl;
282
        		return false;
283
    		}
277
bool SaxonProcessor::isSchemaAwareProcessor() {
278
    if (!licensei) {
279
        return false;
280
    } else {
281
        static jmethodID MID_schema = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(procClass,
282
                                                                                                "isSchemaAware", "()Z");
283
        if (!MID_schema) {
284
            std::cerr << "\nError: Saxonc " << "SaxonProcessor.isSchemaAware()" << " not found" << std::endl;
285
            return false;
286
        }
284 287

  
285
    		licensei = (jboolean)(SaxonProcessor::sxn_environ->env->CallBooleanMethod(proc, MID_schema));
286
        	return licensei;
288
        licensei = (jboolean) (SaxonProcessor::sxn_environ->env->CallBooleanMethod(proc, MID_schema));
289
        return licensei;
287 290

  
288
	}
291
    }
289 292

  
290 293
}
291 294

  
292
void SaxonProcessor::applyConfigurationProperties(){
293
	if(configProperties.size()>0) {
294
		int size = configProperties.size();
295
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
296
		jobjectArray stringArray1 = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
297
		jobjectArray stringArray2 = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
298
		static jmethodID mIDappConfig = NULL;
299
		if(mIDappConfig == NULL) {
300
			mIDappConfig = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,"applyToConfiguration",
301
					"(Lnet/sf/saxon/s9api/Processor;[Ljava/lang/String;[Ljava/lang/String;)V");
302
			if (!mIDappConfig) {
303
				std::cerr << "Error: SaxonDll." << "applyToConfiguration"
304
				<< " not found\n" << std::endl;
305
				return;
306
			}
307
		}
308
		int i=0;
309
		std::map<std::string, std::string >::iterator iter =configProperties.begin();
310
		for(iter=configProperties.begin(); iter!=configProperties.end(); ++iter, i++) {
311
	     		SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray1, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
312
	     		SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray2, i, SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()) );
313
	   }
314
		SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDappConfig,proc, stringArray1,stringArray2);
315
		if (exceptionOccurred()) {
316
	   		exception = checkAndCreateException(saxonCAPIClass);
317
			exceptionClear();
318
      		 }
319
 	  SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray1);
320
	  SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray2);
321
		
322
	}
295
void SaxonProcessor::applyConfigurationProperties() {
296
    if (configProperties.size() > 0) {
297
        int size = configProperties.size();
298
        jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
299
        jobjectArray stringArray1 = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size, stringClass, 0);
300
        jobjectArray stringArray2 = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size, stringClass, 0);
301
        static jmethodID mIDappConfig = nullptr;
302
        if (mIDappConfig == nullptr) {
303
            mIDappConfig = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,
304
                                                                                           "applyToConfiguration",
305
                                                                                           "(Lnet/sf/saxon/s9api/Processor;[Ljava/lang/String;[Ljava/lang/String;)V");
306
            if (!mIDappConfig) {
307
                std::cerr << "Error: SaxonDll." << "applyToConfiguration"
308
                          << " not found\n" << std::endl;
309
                return;
310
            }
311
        }
312
        int i = 0;
313
        std::map<std::string, std::string>::iterator iter = configProperties.begin();
314
        for (iter = configProperties.begin(); iter != configProperties.end(); ++iter, i++) {
315
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray1, i,
316
                                                                    SaxonProcessor::sxn_environ->env->NewStringUTF(
317
                                                                            (iter->first).c_str()));
318
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray2, i,
319
                                                                    SaxonProcessor::sxn_environ->env->NewStringUTF(
320
                                                                            (iter->second).c_str()));
321
        }
322
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDappConfig, proc, stringArray1,
323
                                                                 stringArray2);
324
        if (exceptionOccurred()) {
325
            exception = checkAndCreateException(saxonCAPIClass);
326
            exceptionClear();
327
        }
328
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray1);
329
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray2);
330

  
331
    }
323 332
}
324 333

  
325 334

  
326
  jobjectArray SaxonProcessor::createJArray(XdmValue ** values, int length){
327
    jobjectArray valueArray = NULL;
335
jobjectArray SaxonProcessor::createJArray(XdmValue **values, int length) {
336
    jobjectArray valueArray = nullptr;
328 337

  
329 338
    jclass xdmValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
330
                   				"net/sf/saxon/s9api/XdmValue");
339
                                        "net/sf/saxon/s9api/XdmValue");
331 340

  
332 341

  
333 342
    valueArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) length,
334
                   					xdmValueClass, 0);
343
                                                                  xdmValueClass, 0);
335 344

  
336
    for (int i=0; i<length; i++) {
345
    for (int i = 0; i < length; i++) {
337 346
#ifdef DEBUG
338
				std::string s1 = typeid(values[i]).name();
339
				std::cerr<<"In createJArray\nType of itr:"<<s1<<std::endl;
347
        std::string s1 = typeid(values[i]).name();
348
        std::cerr<<"In createJArray\nType of itr:"<<s1<<std::endl;
340 349

  
341 350

  
342
				jobject xx = values[i]->getUnderlyingValue();
351
        jobject xx = values[i]->getUnderlyingValue();
343 352

  
344
				if(xx == NULL) {
345
					std::cerr<<"value failed"<<std::endl;
346
				} else {
353
        if(xx == nullptr) {
354
            std::cerr<<"value failed"<<std::endl;
355
        } else {
347 356

  
348
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
349
				}
350
				if(values[i]->getUnderlyingValue() == NULL) {
351
					std::cerr<<"value["<<i<<"]->getUnderlyingValue() is NULL"<<std::endl;
352
				}
357
            std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
358
        }
359
        if(values[i]->getUnderlyingValue() == nullptr) {
360
            std::cerr<<"value["<<i<<"]->getUnderlyingValue() is nullptr"<<std::endl;
361
        }
353 362
#endif
354
        SaxonProcessor::sxn_environ->env->SetObjectArrayElement(valueArray, i,values[i]->getUnderlyingValue());
363
        SaxonProcessor::sxn_environ->env->SetObjectArrayElement(valueArray, i, values[i]->getUnderlyingValue());
355 364
    }
356 365
    return valueArray;
357 366

  
358
  }
367
}
359 368

  
360 369

  
361
JParameters SaxonProcessor::createParameterJArray(std::map<std::string,XdmValue*> parameters, std::map<std::string,std::string> properties){
362
		JParameters comboArrays;
363
		comboArrays.stringArray = NULL;
364
		comboArrays.objectArray = NULL;
365
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
366
				"java/lang/Object");
367
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
368
				"java/lang/String");
370
JParameters SaxonProcessor::createParameterJArray(std::map<std::string, XdmValue *> parameters,
371
                                                  std::map<std::string, std::string> properties) {
372
    JParameters comboArrays;
373
    comboArrays.stringArray = nullptr;
374
    comboArrays.objectArray = nullptr;
375
    jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
376
                                      "java/lang/Object");
377
    jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
378
                                      "java/lang/String");
369 379

  
370
		int size = parameters.size() + properties.size();
380
    int size = parameters.size() + properties.size();
371 381
#ifdef DEBUG
372
		std::cerr<<"Properties size: "<<properties.size()<<std::endl;
373
		std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
382
    std::cerr<<"Properties size: "<<properties.size()<<std::endl;
383
    std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
374 384
#endif
375
		if (size > 0) {
376
		    
377
			comboArrays.objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
378
					objectClass, 0);
379
			comboArrays.stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
380
					stringClass, 0);
381
			int i = 0;
382
			for (std::map<std::string, XdmValue*>::iterator iter =
383
					parameters.begin(); iter != parameters.end(); ++iter, i++) {
385
    if (size > 0) {
386

  
387
        comboArrays.objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
388
                                                                                   objectClass, 0);
389
        comboArrays.stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
390
                                                                                   stringClass, 0);
391
        int i = 0;
392
        for (std::map<std::string, XdmValue *>::iterator iter =
393
                parameters.begin(); iter != parameters.end(); ++iter, i++) {
384 394

  
385 395
#ifdef DEBUG
386
				std::cerr<<"map 1"<<std::endl;
387
				std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
396
            std::cerr<<"map 1"<<std::endl;
397
            std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
388 398
#endif
389
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
390
						SaxonProcessor::sxn_environ->env->NewStringUTF(
391
								(iter->first).c_str()));
399
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
400
                                                                    SaxonProcessor::sxn_environ->env->NewStringUTF(
401
                                                                            (iter->first).c_str()));
392 402
#ifdef DEBUG
393
				std::string s1 = typeid(iter->second).name();
394
				std::cerr<<"Type of itr:"<<s1<<std::endl;
395

  
396
				if((iter->second) == NULL) {std::cerr<<"iter->second is null"<<std::endl;
397
				} else {
398
					std::cerr<<"getting underlying value"<<std::endl;
399
				jobject xx = (iter->second)->getUnderlyingValue();
400

  
401
				if(xx == NULL) {
402
					std::cerr<<"value failed"<<std::endl;
403
				} else {
404

  
405
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
406
				}
407
				if((iter->second)->getUnderlyingValue() == NULL) {
408
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
409
				}}
403
            std::string s1 = typeid(iter->second).name();
404
            std::cerr<<"Type of itr:"<<s1<<std::endl;
405

  
406
            if((iter->second) == nullptr) {std::cerr<<"iter->second is nullptr"<<std::endl;
407
            } else {
408
                std::cerr<<"getting underlying value"<<std::endl;
409
            jobject xx = (iter->second)->getUnderlyingValue();
410

  
411
            if(xx == nullptr) {
412
                std::cerr<<"value failed"<<std::endl;
413
            } else {
414

  
415
                std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
416
            }
417
            if((iter->second)->getUnderlyingValue() == nullptr) {
418
                std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
419
            }}
410 420
#endif
411 421

  
412
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
413
						(iter->second)->getUnderlyingValue());
422
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
423
                                                                    (iter->second)->getUnderlyingValue());
414 424

  
415
			}
425
        }
416 426

  
417
			for (std::map<std::string, std::string>::iterator iter =
418
					properties.begin(); iter != properties.end(); ++iter, i++) {
419
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
420
						SaxonProcessor::sxn_environ->env->NewStringUTF(
421
								(iter->first).c_str()));
422
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
423
						SaxonProcessor::sxn_environ->env->NewStringUTF(
424
								(iter->second).c_str()));
425
			}
427
        for (std::map<std::string, std::string>::iterator iter =
428
                properties.begin(); iter != properties.end(); ++iter, i++) {
429
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
430
                                                                    SaxonProcessor::sxn_environ->env->NewStringUTF(
431
                                                                            (iter->first).c_str()));
432
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
433
                                                                    SaxonProcessor::sxn_environ->env->NewStringUTF(
434
                                                                            (iter->second).c_str()));
435
        }
426 436

  
427
			 return comboArrays;
437
        return comboArrays;
428 438

  
429
		} else {
430
		    return comboArrays;
431
		}
439
    } else {
440
        return comboArrays;
432 441
    }
442
}
433 443

  
434
JParameters SaxonProcessor::createParameterJArray2(std::map<std::string,XdmValue*> parameters){
435
		JParameters comboArrays;
436
		comboArrays.stringArray = NULL;
437
		comboArrays.objectArray = NULL;
438
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
439
				"java/lang/Object");
440
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
441
				"java/lang/String");
444
JParameters SaxonProcessor::createParameterJArray2(std::map<std::string, XdmValue *> parameters) {
445
    JParameters comboArrays;
446
    comboArrays.stringArray = nullptr;
447
    comboArrays.objectArray = nullptr;
448
    jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
449
                                      "java/lang/Object");
450
    jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
451
                                      "java/lang/String");
442 452

  
443
		int size = parameters.size();
453
    int size = parameters.size();
444 454
#ifdef DEBUG
445
		std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
455
    std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
446 456
#endif
447
		if (size > 0) {
457
    if (size > 0) {
448 458

  
449
			comboArrays.objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
450
					objectClass, 0);
451
			comboArrays.stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
452
					stringClass, 0);
453
			int i = 0;
454
			for (std::map<std::string, XdmValue*>::iterator iter =
455
					parameters.begin(); iter != parameters.end(); ++iter, i++) {
459
        comboArrays.objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
460
                                                                                   objectClass, 0);
461
        comboArrays.stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
462
                                                                                   stringClass, 0);
463
        int i = 0;
464
        for (std::map<std::string, XdmValue *>::iterator iter =
465
                parameters.begin(); iter != parameters.end(); ++iter, i++) {
456 466

  
457 467
#ifdef DEBUG
458
				std::cerr<<"map 1"<<std::endl;
459
				std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
468
            std::cerr<<"map 1"<<std::endl;
469
            std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
460 470
#endif
461
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
462
						SaxonProcessor::sxn_environ->env->NewStringUTF(
463
								(iter->first).c_str()));
471
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
472
                                                                    SaxonProcessor::sxn_environ->env->NewStringUTF(
473
                                                                            (iter->first).c_str()));
464 474
#ifdef DEBUG
465
				std::string s1 = typeid(iter->second).name();
466
				std::cerr<<"Type of itr:"<<s1<<std::endl;
467

  
468
				if((iter->second) == NULL) {std::cerr<<"iter->second is null"<<std::endl;
469
				} else {
470
					std::cerr<<"getting underlying value"<<std::endl;
471
				jobject xx = (iter->second)->getUnderlyingValue();
472

  
473
				if(xx == NULL) {
474
					std::cerr<<"value failed"<<std::endl;
475
				} else {
476

  
477
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
478
				}
479
				if((iter->second)->getUnderlyingValue() == NULL) {
480
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
481
				}}
475
            std::string s1 = typeid(iter->second).name();
476
            std::cerr<<"Type of itr:"<<s1<<std::endl;
477

  
478
            if((iter->second) == nullptr) {std::cerr<<"iter->second is nullptr"<<std::endl;
479
            } else {
480
                std::cerr<<"getting underlying value"<<std::endl;
481
            jobject xx = (iter->second)->getUnderlyingValue();
482

  
483
            if(xx == nullptr) {
484
                std::cerr<<"value failed"<<std::endl;
485
            } else {
486

  
487
                std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
488
            }
489
            if((iter->second)->getUnderlyingValue() == nullptr) {
490
                std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
491
            }}
482 492
#endif
483 493

  
484
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
485
						(iter->second)->getUnderlyingValue());
494
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
495
                                                                    (iter->second)->getUnderlyingValue());
486 496

  
487
			}
497
        }
488 498

  
489 499

  
490
			 return comboArrays;
500
        return comboArrays;
491 501

  
492
		} else {
493
		    return comboArrays;
494
		}
502
    } else {
503
        return comboArrays;
495 504
    }
505
}
496 506

  
497 507

  
498
SaxonProcessor& SaxonProcessor::operator=( const SaxonProcessor& other ){
499
	versionClass = other.versionClass;
500
	procClass = other.procClass;
501
	saxonCAPIClass = other.saxonCAPIClass;
502
	cwd = other.cwd;
503
	proc = other.proc;
504
	//SaxonProcessor::sxn_environ= other.environ;
505
	parameters = other.parameters;
506
	configProperties = other.configProperties;
507
	licensei = other.licensei;
508
	exception = other.exception;
509
	return *this;
508
SaxonProcessor &SaxonProcessor::operator=(const SaxonProcessor &other) {
509
    versionClass = other.versionClass;
510
    procClass = other.procClass;
511
    saxonCAPIClass = other.saxonCAPIClass;
512
    cwd = other.cwd;
513
    proc = other.proc;
514
    //SaxonProcessor::sxn_environ= other.environ;
515
    parameters = other.parameters;
516
    configProperties = other.configProperties;
517
    licensei = other.licensei;
518
    exception = other.exception;
519
    return *this;
510 520
}
511 521

  
512 522
SaxonProcessor::SaxonProcessor(const SaxonProcessor &other) {
513
	versionClass = other.versionClass;
514
	procClass = other.procClass;
515
	saxonCAPIClass = other.saxonCAPIClass;
516
	cwd = other.cwd;
517
	proc = other.proc;
518
	//SaxonProcessor::sxn_environ= other.environ;
519
	parameters = other.parameters;
520
	configProperties = other.configProperties;
521
	licensei = other.licensei;
522
	exception = other.exception;
523
    versionClass = other.versionClass;
524
    procClass = other.procClass;
525
    saxonCAPIClass = other.saxonCAPIClass;
526
    cwd = other.cwd;
527
    proc = other.proc;
528
    //SaxonProcessor::sxn_environ= other.environ;
529
    parameters = other.parameters;
530
    configProperties = other.configProperties;
531
    licensei = other.licensei;
532
    exception = other.exception;
523 533
}
524 534

  
525
XsltProcessor * SaxonProcessor::newXsltProcessor(){
535
XsltProcessor *SaxonProcessor::newXsltProcessor() {
526 536
    return (new XsltProcessor(this, cwd));
527 537
}
528 538

  
529
Xslt30Processor * SaxonProcessor::newXslt30Processor(){
539
Xslt30Processor *SaxonProcessor::newXslt30Processor() {
530 540
    return (new Xslt30Processor(this, cwd));
531 541
}
532 542

  
533
XQueryProcessor * SaxonProcessor::newXQueryProcessor(){
534
    return (new XQueryProcessor(this,cwd));
543
XQueryProcessor *SaxonProcessor::newXQueryProcessor() {
544
    return (new XQueryProcessor(this, cwd));
535 545
}
536 546

  
537
XPathProcessor * SaxonProcessor::newXPathProcessor(){
547
XPathProcessor *SaxonProcessor::newXPathProcessor() {
538 548
    return (new XPathProcessor(this, cwd));
539 549
}
540 550

  
541
SchemaValidator * SaxonProcessor::newSchemaValidator(){
542
	if(licensei) {
543
		return (new SchemaValidator(this, cwd));
544
	} else {
545
		std::cerr<<"\nError: Processor is not licensed for schema processing!"<<std::endl;
546
		return NULL;
547
	}
551
SchemaValidator *SaxonProcessor::newSchemaValidator() {
552
    if (licensei) {
553
        return (new SchemaValidator(this, cwd));
554
    } else {
555
        std::cerr << "\nError: Processor is not licensed for schema processing!" << std::endl;
556
        return nullptr;
557
    }
548 558
}
549 559

  
550 560

  
561
const char *SaxonProcessor::version() {
562
    if (versionStr == nullptr) {
551 563

  
552
const char * SaxonProcessor::version() {
553
     if(versionStr == NULL) {
554

  
555
     	static jmethodID MID_version = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "getProductVersion", "(Lnet/sf/saxon/s9api/Processor;)Ljava/lang/String;");
556
    	if (!MID_version) {
557
        	std::cerr<<"\nError: MyClassInDll "<<"SaxonCAPI.getProductVersion()"<<" not found"<<std::endl;
558
        	return NULL;
559
    	}
564
        static jmethodID MID_version = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,
565
                                                                                                       "getProductVersion",
566
                                                                                                       "(Lnet/sf/saxon/s9api/Processor;)Ljava/lang/String;");
567
        if (!MID_version) {
568
            std::cerr << "\nError: MyClassInDll " << "SaxonCAPI.getProductVersion()" << " not found" << std::endl;
569
            return nullptr;
570
        }
560 571

  
561
    	jstring jstr = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, MID_version, proc));
562
         const char * tempVersionStr = SaxonProcessor::sxn_environ->env->GetStringUTFChars(jstr, NULL);
563
         int verLen = strlen(tempVersionStr)+22+strlen(CVERSION)+1;
564
         versionStr =new char [verLen];
565
         snprintf(versionStr, verLen, "Saxon/C %s %s %s", CVERSION, "running with", tempVersionStr);
566
         delete tempVersionStr;
572
        jstring jstr = (jstring) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, MID_version,
573
                                                                                           proc));
574
        const char *tempVersionStr = SaxonProcessor::sxn_environ->env->GetStringUTFChars(jstr, nullptr);
575
        int verLen = strlen(tempVersionStr) + 22 + strlen(CVERSION) + 1;
576
        versionStr = new char[verLen];
577
        snprintf(versionStr, verLen, "Saxon/C %s %s %s", CVERSION, "running with", tempVersionStr);
578
        delete tempVersionStr;
567 579

  
568 580
    }
569 581

  
570 582
    return versionStr;
571 583
}
572 584

  
573
void SaxonProcessor::setcwd(const char* dir){
585
void SaxonProcessor::setcwd(const char *dir) {
574 586
    cwd = std::string(dir);
575 587
}
576 588

  
577
const char* SaxonProcessor::getcwd(){
578
	return cwd.c_str();
589
const char *SaxonProcessor::getcwd() {
590
    return cwd.c_str();
579 591
}
580 592

  
581
void SaxonProcessor::setResourcesDirectory(const char* dir){
582
	//memset(&resources_dir[0], 0, sizeof(resources_dir));
583
 #if defined(__linux__) || defined (__APPLE__)
584
	strncat(_getResourceDirectory(), dir, strlen(dir));
585
 #else
586
	int destSize = strlen(dir) + strlen(dir);
587
	strncat_s(_getResourceDirectory(), destSize,dir, strlen(dir));
588 593

  
589
 #endif
590
}
594
void SaxonProcessor::setCatalog(const char *catalogFile, bool isTracing) {
595
    jclass xmlResolverClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/trans/XmlCatalogResolver;");
596
    static jmethodID catalogMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xmlResolverClass, "setCatalog",
597
                                                                                      "(Ljava/lang/String;Lnet/sf/saxon/Configuration;Z)V");
591 598

  
599
    if (!catalogMID) {
600
        std::cerr << "\nError: Saxonc." << "setCatalog()" << " not found" << std::endl;
601
        return;
602
    }
603
    if (catalogFile == nullptr) {
592 604

  
593
void SaxonProcessor::setCatalog(const char* catalogFile, bool isTracing){
594
	jclass xmlResolverClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/trans/XmlCatalogResolver;");
595
	static jmethodID catalogMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xmlResolverClass, "setCatalog", "(Ljava/lang/String;Lnet/sf/saxon/Configuration;Z)V");
596
	
597
	if (!catalogMID) {
598
		std::cerr<<"\nError: Saxonc."<<"setCatalog()"<<" not found"<<std::endl;
599 605
        return;
600
        }
601
	if(catalogFile == NULL) {
602
		
603
		return;
604
	}
605
	static jmethodID configMID = SaxonProcessor::sxn_environ->env->GetMethodID(procClass, "getUnderlyingConfiguration", "()Lnet/sf/saxon/Configuration;");
606
	
607
	if (!configMID) {
608
		std::cerr<<"\nError: Saxonc."<<"getUnderlyingConfiguration()"<<" not found"<<std::endl;
606
    }
607
    static jmethodID configMID = SaxonProcessor::sxn_environ->env->GetMethodID(procClass, "getUnderlyingConfiguration",
608
                                                                               "()Lnet/sf/saxon/Configuration;");
609

  
610
    if (!configMID) {
611
        std::cerr << "\nError: Saxonc." << "getUnderlyingConfiguration()" << " not found" << std::endl;
609 612
        return;
610
        }
613
    }
614

  
611 615

  
616
    if (!proc) {
617
        std::cout << "proc is nullptr in SaxonProcessorsetCatalog" << std::endl;
618
        return;
619
    }
612 620

  
613
	if(!proc) {
614
		std::cout<<"proc is NULL in SaxonProcessorsetCatalog"<<std::endl;
615
		return;
616
	}
621
    jobject configObj = SaxonProcessor::sxn_environ->env->CallObjectMethod(proc, configMID);
617 622

  
618
 	jobject configObj = SaxonProcessor::sxn_environ->env->CallObjectMethod(proc, configMID);
619
  	
620
	if(!configObj) {
621
		std::cout<<"proc is NULL in SaxonProcessor setcatalog - config obj"<<std::endl;
622
		return;
623
	}
624
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(xmlResolverClass, catalogMID, SaxonProcessor::sxn_environ->env->NewStringUTF(catalogFile), configObj ,(jboolean)isTracing);
623
    if (!configObj) {
624
        std::cout << "proc is nullptr in SaxonProcessor setcatalog - config obj" << std::endl;
625
        return;
626
    }
627
    SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(xmlResolverClass, catalogMID,
628
                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(catalogFile),
629
                                                           configObj, (jboolean) isTracing);
625 630
#ifdef DEBUG
626
	SaxonProcessor::sxn_environ->env->ExceptionDescribe();
631
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
627 632
#endif
628 633
}
629 634

  
630
const char * SaxonProcessor::getResourcesDirectory(){
631
	return _getResourceDirectory();
632
}
633 635

  
636
XdmNode *SaxonProcessor::parseXmlFromString(const char *source) {
634 637

  
635
XdmNode * SaxonProcessor::parseXmlFromString(const char* source){
636
	
637
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlString", "(Ljava/lang/String;Lnet/sf/saxon/s9api/Processor;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
638
    jmethodID mID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlString",
639
                                                                                    "(Ljava/lang/String;Lnet/sf/saxon/s9api/Processor;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
638 640
    if (!mID) {
639
	std::cerr<<"\nError: Saxonc."<<"parseXmlString()"<<" not found"<<std::endl;
640
        return NULL;
641
        std::cerr << "\nError: Saxonc." << "parseXmlString()" << " not found" << std::endl;
642
        return nullptr;
641 643
    }
642 644
//TODO SchemaValidator
643 645

  
644
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, SaxonProcessor::sxn_environ->env->NewStringUTF(cwd.c_str()), proc, NULL, SaxonProcessor::sxn_environ->env->NewStringUTF(source));
645
	if(xdmNodei) {
646
		XdmNode * value = new XdmNode(xdmNodei);
647
		value->setProcessor(this);
648
		return value;
649
	}   else if (exceptionOccurred()) {
650
	   	exception = checkAndCreateException(saxonCAPIClass);
651
		exceptionClear();
652
       }
653
   
646
    jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID,
647
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
648
                                                                                        cwd.c_str()), proc, nullptr,
649
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
650
                                                                                        source));
651
    if (xdmNodei) {
652
        XdmNode *value = new XdmNode(xdmNodei);
653
        value->setProcessor(this);
654
        return value;
655
    } else if (exceptionOccurred()) {
656
        exception = checkAndCreateException(saxonCAPIClass);
657
        exceptionClear();
658
    }
659

  
654 660
#ifdef DEBUG
655
	SaxonProcessor::sxn_environ->env->ExceptionDescribe();
661
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
656 662
#endif
657
 
658
   return NULL;
659
}
660 663

  
661
int SaxonProcessor::getNodeKind(jobject obj){
662
	jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmNode;");
663
	static jmethodID nodeKindMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,"getNodeKind", "()Lnet/sf/saxon/s9api/XdmNodeKind;");
664
	if (!nodeKindMID) {
665
		std::cerr << "Error: MyClassInDll." << "getNodeKind" << " not found\n"
666
				<< std::endl;
667
		return 0;
668
	} 
669

  
670
	jobject nodeKindObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(obj, nodeKindMID));
671
	if(!nodeKindObj) {
672
		
673
		return 0;
674
	}
675
	jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/option/cpp/XdmUtils;");
676

  
677
	jmethodID mID2 = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"convertNodeKindType", "(Lnet/sf/saxon/s9api/XdmNodeKind;)I");
678

  
679
	if (!mID2) {
680
		std::cerr << "Error: MyClassInDll." << "convertNodeKindType" << " not found\n"
681
				<< std::endl;
682
		return 0;
683
	} 
684
	if(!nodeKindObj){
685
		return 0;	
686
	}
687
	int nodeKind = (int)(SaxonProcessor::sxn_environ->env->CallStaticIntMethod(xdmUtilsClass, mID2, nodeKindObj));
688
	return nodeKind;
664
    return nullptr;
689 665
}
690 666

  
667
int SaxonProcessor::getNodeKind(jobject obj) {
668
    jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmNode;");
669
    static jmethodID nodeKindMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
670
                                                                                             "getNodeKind",
671
                                                                                             "()Lnet/sf/saxon/s9api/XdmNodeKind;");
672
    if (!nodeKindMID) {
673
        std::cerr << "Error: MyClassInDll." << "getNodeKind" << " not found\n"
674
                  << std::endl;
675
        return 0;
676
    }
677

  
678
    jobject nodeKindObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(obj, nodeKindMID));
679
    if (!nodeKindObj) {
691 680

  
681
        return 0;
682
    }
683
    jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/option/cpp/XdmUtils;");
684

  
685
    jmethodID mID2 = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,
686
                                                                                     "convertNodeKindType",
687
                                                                                     "(Lnet/sf/saxon/s9api/XdmNodeKind;)I");
688

  
689
    if (!mID2) {
690
        std::cerr << "Error: MyClassInDll." << "convertNodeKindType" << " not found\n"
691
                  << std::endl;
692
        return 0;
693
    }
694
    if (!nodeKindObj) {
695
        return 0;
696
    }
697
    int nodeKind = (int) (SaxonProcessor::sxn_environ->env->CallStaticIntMethod(xdmUtilsClass, mID2, nodeKindObj));
698
    return nodeKind;
699
}
692 700

  
693
XdmNode * SaxonProcessor::parseXmlFromFile(const char* source){
694 701

  
695
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlFile", "(Lnet/sf/saxon/s9api/Processor;Ljava/lang/String;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
702
XdmNode *SaxonProcessor::parseXmlFromFile(const char *source) {
703

  
704
    jmethodID mID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlFile",
705
                                                                                    "(Lnet/sf/saxon/s9api/Processor;Ljava/lang/String;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
696 706
    if (!mID) {
697
	std::cerr<<"\nError: Saxonc.Dll "<<"parseXmlFile()"<<" not found"<<std::endl;
698
        return NULL;
707
        std::cerr << "\nError: Saxonc.Dll " << "parseXmlFile()" << " not found" << std::endl;
708
        return nullptr;
699 709
    }
700 710
//TODO SchemaValidator
701
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(cwd.c_str()),  NULL, SaxonProcessor::sxn_environ->env->NewStringUTF(source));
702
     if(exceptionOccurred()) {
703
	 	exception = checkAndCreateException(saxonCAPIClass);
704
	   exceptionClear();
705
	   		
706
     } else {
707

  
708
	XdmNode * value = new XdmNode(xdmNodei);
709
	value->setProcessor(this);
710
	return value;
711
   }
712
   return NULL;
711
    jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc,
712
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
713
                                                                                        cwd.c_str()), nullptr,
714
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
715
                                                                                        source));
716
    if (exceptionOccurred()) {
717
        exception = checkAndCreateException(saxonCAPIClass);
718
        exceptionClear();
719

  
720
    } else {
721

  
722
        XdmNode *value = new XdmNode(xdmNodei);
723
        value->setProcessor(this);
724
        return value;
725
    }
726
    return nullptr;
713 727
}
714 728

  
715
XdmNode * SaxonProcessor::parseXmlFromUri(const char* source){
729
XdmNode *SaxonProcessor::parseXmlFromUri(const char *source) {
716 730

  
717
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlFile", "(Lnet/sf/saxon/s9api/Processor;Ljava/lang/String;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
731
    jmethodID mID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlFile",
732
                                                                                    "(Lnet/sf/saxon/s9api/Processor;Ljava/lang/String;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
718 733
    if (!mID) {
719
	std::cerr<<"\nError: Saxonc.Dll "<<"parseXmlFromUri()"<<" not found"<<std::endl;
720
        return NULL;
721
    }
722
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(""), SaxonProcessor::sxn_environ->env->NewStringUTF(source));
723
     if(exceptionOccurred()) {
724
	   exception = checkAndCreateException(saxonCAPIClass);
725
     } else {
726
	XdmNode * value = new XdmNode(xdmNodei);
727
	value->setProcessor(this);
728
	return value;
729
   }
730
   return NULL;
734
        std::cerr << "\nError: Saxonc.Dll " << "parseXmlFromUri()" << " not found" << std::endl;
735
        return nullptr;
736
    }
737
    jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc,
738
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
739
                                                                                        ""),
740
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
741
                                                                                        source));
742
    if (exceptionOccurred()) {
743
        exception = checkAndCreateException(saxonCAPIClass);
744
    } else {
745
        XdmNode *value = new XdmNode(xdmNodei);
746
        value->setProcessor(this);
747
        return value;
748
    }
749
    return nullptr;
731 750
}
732 751

  
733 752

  
734
  /**
735
     * Set a configuration property.
736
     *
737
     * @param name of the property
738
     * @param value of the property
739
     */
740
    void SaxonProcessor::setConfigurationProperty(const char * name, const char * value){
741
	if(name != NULL){
742
		configProperties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value == NULL ? "" : value))));
743
	}
753
/**
754
   * Set a configuration property.
755
   *
756
   * @param name of the property
757
   * @param value of the property
758
   */
759
void SaxonProcessor::setConfigurationProperty(const char *name, const char *value) {
760
    if (name != nullptr) {
761
        configProperties.insert(
762
                std::pair<std::string, std::string>(std::string(name), std::string((value == nullptr ? "" : value))));
744 763
    }
764
}
745 765

  
746
   void SaxonProcessor::clearConfigurationProperties(){
747
	configProperties.clear();
748
   }
766
void SaxonProcessor::clearConfigurationProperties() {
767
    configProperties.clear();
768
}
749 769

  
750 770

  
771
void SaxonProcessor::release() {
772
    if (SaxonProcessor::jvmCreatedCPP != 0) {
773
        SaxonProcessor::jvmCreatedCPP = 0;
774
        //std::cerr<<"SaxonProc: JVM finalized calling !"<<std::endl;
775
        finalizeJavaRT(SaxonProcessor::sxn_environ->jvm);
751 776

  
752
void SaxonProcessor::release(){
753
 	if(SaxonProcessor::jvmCreatedCPP!=0) {
754
		SaxonProcessor::jvmCreatedCPP =0; 
755
		//std::cerr<<"SaxonProc: JVM finalized calling !"<<std::endl;
756
 		finalizeJavaRT (SaxonProcessor::sxn_environ->jvm);
757
 		
758
		//delete SaxonProcessor::sxn_environ;
759
	/*clearParameters();
760
	clearProperties();*/
761
} else {
777
        //delete SaxonProcessor::sxn_environ;
778
        /*clearParameters();
779
        clearProperties();*/
780
    } else {
762 781
//#ifdef DEBUG
763
     std::cerr<<"SaxonProc: JVM finalize not called!"<<std::endl;
782
        std::cerr << "SaxonProc: JVM finalize not called!" << std::endl;
764 783
//#endif
765
}
784
    }
766 785
}
767 786

  
768 787

  
788
/* ========= Factory method for Xdm ======== */
769 789

  
790
XdmAtomicValue *SaxonProcessor::makeStringValue(const char *str) {
791
    jobject obj = getJavaStringValue(SaxonProcessor::sxn_environ, str);
792
    static jmethodID mssID_atomic = nullptr;
793
    if (mssID_atomic == nullptr) {
794
        mssID_atomic = (jmethodID) (SaxonProcessor::sxn_environ->env->GetMethodID(xdmAtomicClass, "<init>",
795
                                                                                  "(Ljava/lang/String;)V"));
796
    }
797
    if (!mssID_atomic) {
798
        std::cerr << "XdmAtomic constructor (String)" << std::endl;
799
        return nullptr;
800
    }
801
    jobject obj2 = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mssID_atomic, obj));
802
    XdmAtomicValue *value = new XdmAtomicValue(obj2, "xs:string");
803
    value->setProcessor(this);
804
    return value;
805
}
770 806

  
771
/* ========= Factory method for Xdm ======== */
807
XdmAtomicValue *SaxonProcessor::makeStringValue(std::string str) {
808
    jobject obj = getJavaStringValue(SaxonProcessor::sxn_environ, str.c_str());
809
    static jmethodID msID_atomic = nullptr;
810
    if (msID_atomic == nullptr) {
811
        msID_atomic = (jmethodID) (SaxonProcessor::sxn_environ->env->GetMethodID(xdmAtomicClass, "<init>",
812
                                                                                 "(Ljava/lang/String;)V"));
813
    }
814
    if (!msID_atomic) {
815
        std::cerr << "XdmAtomic constructor (String)" << std::endl;
816
        return nullptr;
817
    }
818
    jobject obj2 = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, msID_atomic, obj));
819
    XdmAtomicValue *value = new XdmAtomicValue(obj2, "xs:string");
820
    value->setProcessor(this);
821
    return value;
822
}
772 823

  
773
    XdmAtomicValue * SaxonProcessor::makeStringValue(const char * str){
774
	    jobject obj = getJavaStringValue(SaxonProcessor::sxn_environ, str);
775
	    static jmethodID mssID_atomic = NULL;
776
	    if(mssID_atomic == NULL) {
777
	        mssID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
778
	    }
779
	    if(!mssID_atomic) {
780
	        std::cerr<<"XdmAtomic constructor (String)"<<std::endl;
781
	        return NULL;
782
	    }
783
	    jobject obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mssID_atomic, obj));
784
	    XdmAtomicValue * value = new XdmAtomicValue(obj2, "xs:string");
785
	    value->setProcessor(this);
786
	    return value;
787
    }
788

  
789
    XdmAtomicValue * SaxonProcessor::makeStringValue(std::string str){
790
	    jobject obj = getJavaStringValue(SaxonProcessor::sxn_environ, str.c_str());
791
	    static jmethodID msID_atomic = NULL;
792
	    if(msID_atomic == NULL) {
793
	        msID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
794
	    }
795
	    if(!msID_atomic) {
796
	        std::cerr<<"XdmAtomic constructor (String)"<<std::endl;
797
	        return NULL;
798
	    }
799
	    jobject obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, msID_atomic, obj));
800
	    XdmAtomicValue * value = new XdmAtomicValue(obj2, "xs:string");
801
	    value->setProcessor(this);
802
	    return value;
803
    }
804

  
805
    XdmAtomicValue * SaxonProcessor::makeIntegerValue(int i){
806
	    //jobject obj = integerValue(*SaxonProcessor::sxn_environ, i);
807
	    static jmethodID miiID_atomic = NULL;
808
	    if(miiID_atomic == NULL) {
809
	        miiID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
810
	    }
811
	    if(!miiID_atomic) {
812
	        std::cerr<<"XdmAtomic constructor (J)"<<std::endl;
813
	        return NULL;
814
	    }
815
	    jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, miiID_atomic, (jlong)i));
816
	    XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}integer");
817
	    value->setProcessor(this);
818
	    return value;
819
    }
820

  
821
    XdmAtomicValue * SaxonProcessor::makeDoubleValue(double d){
822
	    //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
823
	    static jmethodID mdID_atomic = NULL;
824
	    if(mdID_atomic == NULL) {
825
	        mdID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(D)V"));
826
	    }
827
	    jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mdID_atomic, (jdouble)d));
828
	    XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}double");
829
	    value->setProcessor(this);
830
	    return value;
831
    }
832

  
833
    XdmAtomicValue * SaxonProcessor::makeFloatValue(float d){
834
	    //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
835
	    static jmethodID mfID_atomic = NULL;
836
	    if(mfID_atomic == NULL) {
837
	        mfID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(F)V"));
838
	    }
839
	    jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mfID_atomic, (jfloat)d));
840
	    XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}float");
841
	    value->setProcessor(this);
842
	    return value;
843
    }
844

  
845
    XdmAtomicValue * SaxonProcessor::makeLongValue(long l){
846
	    //jobject obj = longValue(*SaxonProcessor::sxn_environ, l);
847
	    static jmethodID mlID_atomic = NULL;
848
	    if(mlID_atomic == NULL) {
849
	        mlID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
850
        }
851
	    jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mlID_atomic, (jlong)l));
852
	    XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}long");
853
	    value->setProcessor(this);
854
	    return value;
824
XdmAtomicValue *SaxonProcessor::makeIntegerValue(int i) {
825
    //jobject obj = integerValue(*SaxonProcessor::sxn_environ, i);
826
    static jmethodID miiID_atomic = nullptr;
827
    if (miiID_atomic == nullptr) {
828
        miiID_atomic = (jmethodID) (SaxonProcessor::sxn_environ->env->GetMethodID(xdmAtomicClass, "<init>", "(J)V"));
829
    }
830
    if (!miiID_atomic) {
831
        std::cerr << "XdmAtomic constructor (J)" << std::endl;
832
        return nullptr;
833
    }
834
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, miiID_atomic, (jlong) i));
835
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}integer");
836
    value->setProcessor(this);
837
    return value;
838
}
839

  
840
XdmAtomicValue *SaxonProcessor::makeDoubleValue(double d) {
841
    //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
842
    static jmethodID mdID_atomic = nullptr;
843
    if (mdID_atomic == nullptr) {
844
        mdID_atomic = (jmethodID) (SaxonProcessor::sxn_environ->env->GetMethodID(xdmAtomicClass, "<init>", "(D)V"));
855 845
    }
846
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mdID_atomic, (jdouble) d));
847
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}double");
848
    value->setProcessor(this);
849
    return value;
850
}
856 851

  
857
    XdmAtomicValue * SaxonProcessor::makeBooleanValue(bool b){
858
	    //jobject obj = booleanValue(*SaxonProcessor::sxn_environ, b);
859
	    static jmethodID mID_atomic = NULL;
860
	    if(mID_atomic == NULL) {
861
	        mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Z)V"));
862
	    }
863
	    jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jboolean)b));
864
	    XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}boolean");
865
	    value->setProcessor(this);
866
	    return value;
852
XdmAtomicValue *SaxonProcessor::makeFloatValue(float d) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff