Project

Profile

Help

Revision 4e3fba42

Added by O'Neil Delpratt over 5 years ago

Saxon/C bug fix relating to static sxn_environ

View differences:

latest9.6/hec/Saxon.C.API/SchemaValidator.cpp
15 15
	/*
16 16
	 * Look for class.
17 17
	 */
18
	cppClass = lookForClass(sxn_environ->env,
18
	cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
19 19
			"net/sf/saxon/option/cpp/SchemaValidatorForCpp");
20 20
	if ((proc->proc) == NULL) {
21 21
		std::cerr << "Processor is NULL" << std::endl;
22 22
	}
23 23

  
24
	cppV = createSaxonProcessor2(sxn_environ->env, cppClass,
24
	cppV = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
25 25
			"(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
26 26

  
27 27
#ifdef DEBUG
28
	jmethodID debugMID = sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
29
	sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
28
	jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
29
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
30 30
#endif    
31 31

  
32 32
	proc->exception = NULL;
......
39 39
				if(proc->exception != NULL) {
40 40
					delete proc->exception;
41 41
				}
42
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
42
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
43 43
				
44 44
     			
45 45
			
46 46
#ifdef DEBUG
47
		sxn_environ->env->ExceptionDescribe();
47
		SaxonProcessor::sxn_environ->env->ExceptionDescribe();
48 48
#endif
49 49
		proc->exceptionClear();
50 50
	}
......
63 63

  
64 64
  XdmNode * SchemaValidator::getValidationReport(){
65 65
	jmethodID mID =
66
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "getValidationReport", "()Lnet/sf/saxon/s9api/XdmNode;");
66
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "getValidationReport", "()Lnet/sf/saxon/s9api/XdmNode;");
67 67
	if (!mID) {
68 68
		std::cerr << "Error: libsaxon." << "validate.getValidationReport()" << " not found\n"
69 69
			<< std::endl;
70 70
	} else {
71 71
		jobject result = (jobject)(
72
			sxn_environ->env->CallObjectMethod(cppV, mID));
72
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppV, mID));
73 73
		
74 74
		if (result) {
75 75
			XdmNode * node = new XdmNode(result);
......
87 87
        }
88 88
	
89 89
	jmethodID mID =
90
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "registerSchema",
90
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "registerSchema",
91 91
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
92 92
	if (!mID) {
93 93
		std::cerr << "Error: libsaxon." << "validate" << " not found\n"
......
95 95
	} else {
96 96
	jobjectArray stringArray = NULL;
97 97
	jobjectArray objectArray = NULL;
98
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
99
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
98
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
99
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
100 100

  
101 101
	int size = parameters.size() + properties.size();
102 102
#ifdef DEBUG
......
105 105
		std::cerr<<"size:"<<size<<std::endl;
106 106
#endif
107 107
	if (size > 0) {
108
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
108
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
109 109
				objectClass, 0);
110
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
110
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
111 111
				stringClass, 0);
112 112
		int i = 0;
113 113
		for (std::map<std::string, XdmValue*>::iterator iter = parameters.begin();
114 114
				iter != parameters.end(); ++iter, i++) {
115
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
116
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
117
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
115
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
116
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
117
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
118 118
					(iter->second)->getUnderlyingValue(proc));
119 119
#ifdef DEBUG
120 120
				std::string s1 = typeid(iter->second).name();
......
133 133
		}
134 134
		for (std::map<std::string, std::string>::iterator iter = properties.begin();
135 135
				iter != properties.end(); ++iter, i++) {
136
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
137
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
138
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
139
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
136
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
137
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
138
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
139
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
140 140
		}
141 141
	}
142 142
	
143
			sxn_environ->env->CallVoidMethod(cppV, mID,
144
					sxn_environ->env->NewStringUTF(cwdV.c_str()),
145
					sxn_environ->env->NewStringUTF(sourceFile), stringArray, objectArray);
143
			SaxonProcessor::sxn_environ->env->CallVoidMethod(cppV, mID,
144
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()),
145
					SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile), stringArray, objectArray);
146 146

  
147 147
	if (size > 0) {
148
		sxn_environ->env->DeleteLocalRef(stringArray);
149
		sxn_environ->env->DeleteLocalRef(objectArray);
148
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
149
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
150 150
	}
151 151

  
152 152
}
......
154 154
				if(proc->exception != NULL) {
155 155
					delete proc->exception;
156 156
				}
157
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
157
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
158 158
				
159 159
     			
160 160
			
161 161
#ifdef DEBUG
162
		sxn_environ->env->ExceptionDescribe();
162
		SaxonProcessor::sxn_environ->env->ExceptionDescribe();
163 163
#endif
164 164
		proc->exceptionClear();
165 165
	}
......
173 173
	     return;
174 174
        }
175 175
	jmethodID mID =
176
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "registerSchemaString",
176
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "registerSchemaString",
177 177
				"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
178 178

  
179 179
	if (!mID) {
......
182 182
	} else {
183 183
	jobjectArray stringArray = NULL;
184 184
	jobjectArray objectArray = NULL;
185
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
186
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
185
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
186
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
187 187

  
188 188
	int size = parameters.size() + properties.size();
189 189
#ifdef DEBUG
......
193 193
#endif
194 194

  
195 195
	if (size > 0) {
196
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
196
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
197 197
				objectClass, 0);
198
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
198
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
199 199
				stringClass, 0);
200 200
		int i = 0;
201 201
		for (std::map<std::string, XdmValue*>::iterator iter = parameters.begin();
202 202
				iter != parameters.end(); ++iter, i++) {
203
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
204
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
205
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
203
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
204
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
205
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
206 206
					(iter->second)->getUnderlyingValue(proc));
207 207
#ifdef DEBUG
208 208
				std::string s1 = typeid(iter->second).name();
......
221 221
		}
222 222
		for (std::map<std::string, std::string>::iterator iter = properties.begin();
223 223
				iter != properties.end(); ++iter, i++) {
224
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
225
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
226
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
227
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
224
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
225
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
226
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
227
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
228 228
		}
229 229
	}
230 230

  
231 231
	
232
			sxn_environ->env->CallVoidMethod(cppV, mID,
233
					sxn_environ->env->NewStringUTF(cwdV.c_str()),
234
					(sourceStr != NULL ? sxn_environ->env->NewStringUTF(sourceStr) : NULL), NULL, stringArray, objectArray);
232
			SaxonProcessor::sxn_environ->env->CallVoidMethod(cppV, mID,
233
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()),
234
					(sourceStr != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceStr) : NULL), NULL, stringArray, objectArray);
235 235

  
236 236
	if (size > 0) {
237
		sxn_environ->env->DeleteLocalRef(stringArray);
238
		sxn_environ->env->DeleteLocalRef(objectArray);
237
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
238
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
239 239
	}
240 240

  
241 241
}
......
245 245
				if(proc->exception != NULL) {
246 246
					delete proc->exception;
247 247
				}
248
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
248
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
249 249
				
250 250
     			
251 251
#ifdef DEBUG
252
			sxn_environ->env->ExceptionDescribe();
252
			SaxonProcessor::sxn_environ->env->ExceptionDescribe();
253 253
#endif
254 254
			proc->exceptionClear();
255 255
		}
......
264 264
        }*/
265 265
setProperty("resources", proc->getResourcesDirectory());
266 266
jmethodID mID =
267
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "validate",
267
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "validate",
268 268
				"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
269 269
if (!mID) {
270 270
	std::cerr << "Error: libsaxon." << "validate" << " not found\n"
......
273 273
} else {
274 274
	jobjectArray stringArray = NULL;
275 275
	jobjectArray objectArray = NULL;
276
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
277
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
276
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
277
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
278 278

  
279 279
	int size = parameters.size() + properties.size();
280 280
#ifdef DEBUG
......
283 283
		std::cerr<<"size:"<<size<<std::endl;
284 284
#endif
285 285
	if (size > 0) {
286
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
286
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
287 287
				objectClass, 0);
288
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
288
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
289 289
				stringClass, 0);
290 290
		int i = 0;
291 291
		for (std::map<std::string, XdmValue*>::iterator iter = parameters.begin();
292 292
				iter != parameters.end(); ++iter, i++) {
293
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
294
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
295
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
293
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
294
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
295
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
296 296
					(iter->second)->getUnderlyingValue(proc));
297 297

  
298 298
#ifdef DEBUG
......
312 312
		}
313 313
		for (std::map<std::string, std::string>::iterator iter = properties.begin();
314 314
				iter != properties.end(); ++iter, i++) {
315
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
316
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
317
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
318
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
315
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
316
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
317
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
318
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
319 319

  
320 320
		}
321 321
	}
322 322
	
323
			sxn_environ->env->CallVoidMethod(cppV, mID,
324
					sxn_environ->env->NewStringUTF(cwdV.c_str()), 
325
					(sourceFile != NULL ? sxn_environ->env->NewStringUTF(sourceFile) : NULL), (outputFile.empty() ? NULL : outputFile.c_str() ), stringArray, objectArray);
323
			SaxonProcessor::sxn_environ->env->CallVoidMethod(cppV, mID,
324
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()), 
325
					(sourceFile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile) : NULL), (outputFile.empty() ? NULL : outputFile.c_str() ), stringArray, objectArray);
326 326

  
327 327
	if (size > 0) {
328
		sxn_environ->env->DeleteLocalRef(stringArray);
329
		sxn_environ->env->DeleteLocalRef(objectArray);
328
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
329
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
330 330
	}
331 331
		if(exceptionOccurred()) {
332 332
			if(proc->exception != NULL) {
333 333
				delete proc->exception;
334 334
			}
335
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
335
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
336 336
				
337 337
     			
338 338

  
339 339

  
340 340
#ifdef DEBUG
341
	sxn_environ->env->ExceptionDescribe();
341
	SaxonProcessor::sxn_environ->env->ExceptionDescribe();
342 342
#endif
343 343
			proc->exceptionClear();
344 344
		}
......
352 352
        }
353 353
setProperty("resources", proc->getResourcesDirectory());
354 354
jmethodID mID =
355
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "validateToNode",
355
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "validateToNode",
356 356
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmNode;");
357 357
if (!mID) {
358 358
	std::cerr << "Error: libsaxon." << "validate" << " not found\n"
......
361 361
} else {
362 362
	jobjectArray stringArray = NULL;
363 363
	jobjectArray objectArray = NULL;
364
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
365
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
364
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
365
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
366 366

  
367 367
	int size = parameters.size() + properties.size();
368 368
#ifdef DEBUG
......
371 371
		std::cerr<<"size:"<<size<<std::endl;
372 372
#endif
373 373
	if (size > 0) {
374
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
374
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
375 375
				objectClass, 0);
376
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
376
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
377 377
				stringClass, 0);
378 378
		int i = 0;
379 379
		for (std::map<std::string, XdmValue*>::iterator iter = parameters.begin();
380 380
				iter != parameters.end(); ++iter, i++) {
381
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
382
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
383
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
381
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
382
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
383
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
384 384
					(iter->second)->getUnderlyingValue(proc));
385 385
#ifdef DEBUG
386 386
				std::string s1 = typeid(iter->second).name();
......
399 399
		}
400 400
		for (std::map<std::string, std::string>::iterator iter = properties.begin();
401 401
				iter != properties.end(); ++iter, i++) {
402
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
403
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
404
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
405
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
402
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
403
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
404
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
405
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
406 406
		}
407 407
	}
408 408
	jobject result = (jobject)(
409
			sxn_environ->env->CallObjectMethod(cppV, mID,
410
					sxn_environ->env->NewStringUTF(cwdV.c_str()),
411
					sxn_environ->env->NewStringUTF(sourceFile), stringArray, objectArray));
409
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppV, mID,
410
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()),
411
					SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile), stringArray, objectArray));
412 412
	if (size > 0) {
413
		sxn_environ->env->DeleteLocalRef(stringArray);
414
		sxn_environ->env->DeleteLocalRef(objectArray);
413
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
414
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
415 415
	}
416 416
	if (result) {
417 417
		XdmNode * node = new XdmNode(result);
......
421 421

  
422 422
}
423 423
#ifdef DEBUG
424
	sxn_environ->env->ExceptionDescribe();
424
	SaxonProcessor::sxn_environ->env->ExceptionDescribe();
425 425
#endif
426
sxn_environ->env->ExceptionClear();
426
SaxonProcessor::sxn_environ->env->ExceptionClear();
427 427

  
428 428
}
429 429

  
......
432 432
 	delete proc->exception;
433 433
 	proc->exception = NULL;
434 434
 }
435
   sxn_environ->env->ExceptionClear();
435
   SaxonProcessor::sxn_environ->env->ExceptionClear();
436 436
 }
437 437

  
438 438
const char * SchemaValidator::getErrorCode(int i) {
......
454 454
	 proc->exception = proc->checkForException(environ, cppClass, cpp);
455 455
	 }
456 456
	 return proc->exception;*/
457
	return checkForException(*(sxn_environ), cppClass, cppV);
457
	return checkForException(*(SaxonProcessor::sxn_environ), cppClass, cppV);
458 458
}
459 459

  
460 460
int SchemaValidator::exceptionCount(){

Also available in: Unified diff