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/XsltProcessor.cpp
26 26
	/*
27 27
	 * Look for class.
28 28
	 */
29
	cppClass = lookForClass(sxn_environ->env,
29
	cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
30 30
			"net/sf/saxon/option/cpp/XsltProcessor");
31 31
	if ((proc->proc) == NULL) {
32 32
		cerr << "Processor is NULL" << endl;
33 33
	}
34 34

  
35
	cppXT = createSaxonProcessor2(sxn_environ->env, cppClass,
35
	cppXT = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
36 36
			"(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
37 37

  
38 38
#ifdef DEBUG
39
	jmethodID debugMID = sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
40
	sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
39
	jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
40
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
41 41
#endif    
42 42

  
43 43
	nodeCreated = false;
......
153 153
 if(proc->exception != NULL) {
154 154
 	delete proc->exception;
155 155
 	proc->exception = NULL;
156
	sxn_environ->env->ExceptionClear();
156
	SaxonProcessor::sxn_environ->env->ExceptionClear();
157 157
 }
158 158
  
159 159
 }
......
167 167
	 proc->exception = proc->checkForException(environ, cppClass, cpp);
168 168
	 }
169 169
	 return proc->exception;*/
170
	return checkForException(*(sxn_environ), cppClass, cppXT);
170
	return checkForException(*(SaxonProcessor::sxn_environ), cppClass, cppXT);
171 171
}
172 172

  
173 173
int XsltProcessor::exceptionCount(){
......
179 179

  
180 180
void XsltProcessor::compileFromString(const char* stylesheetStr) {
181 181
	static jmethodID cStringmID =
182
			(jmethodID) sxn_environ->env->GetMethodID(cppClass,
182
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
183 183
					"createStylesheetFromString",
184 184
					"(Ljava/lang/String;Ljava/lang/String;)Lnet/sf/saxon/s9api/XsltExecutable;");
185 185
	if (!cStringmID) {
......
189 189
	} else {
190 190

  
191 191
		stylesheetObject = (jobject)(
192
				sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
193
						sxn_environ->env->NewStringUTF(cwdXT.c_str()),
194
						sxn_environ->env->NewStringUTF(stylesheetStr)));
192
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
193
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
194
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr)));
195 195
		if (!stylesheetObject) {
196 196
			if(exceptionOccurred()) {
197 197
				
198 198
				if(proc->exception != NULL) {
199 199
					delete proc->exception;
200 200
				}
201
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
201
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
202 202
				proc->exceptionClear();
203 203
     			}
204 204
		}
......
208 208

  
209 209
void XsltProcessor::compileFromXdmNode(XdmNode * node) {
210 210
	static jmethodID cNodemID =
211
			(jmethodID) sxn_environ->env->GetMethodID(cppClass,
211
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
212 212
					"createStylesheetFromFile",
213 213
					"(Ljava/lang/String;Lnet/sf/saxon/s9api/XdmNode;)Lnet/sf/saxon/s9api/XsltExecutable;");
214 214
	if (!cNodemID) {
......
218 218
	} else {
219 219
		releaseStylesheet();
220 220
		stylesheetObject = (jobject)(
221
				sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
222
						sxn_environ->env->NewStringUTF(cwdXT.c_str()),
221
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
222
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
223 223
						node->getUnderlyingValue(proc)));
224 224
		if (!stylesheetObject) {
225 225
			if(exceptionOccurred()) {
226 226
				if(proc->exception != NULL) {
227 227
					delete proc->exception;
228 228
				}
229
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
229
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
230 230
				proc->exceptionClear();
231 231
     			}
232 232
			//cout << "Error in compileFromXdmNode" << endl;
......
237 237

  
238 238
void XsltProcessor::compileFromFile(const char* stylesheet) {
239 239
	static jmethodID cFilemID =
240
			(jmethodID) sxn_environ->env->GetMethodID(cppClass,
240
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
241 241
					"createStylesheetFromFile",
242 242
					"(Ljava/lang/String;Ljava/lang/String;)Lnet/sf/saxon/s9api/XsltExecutable;");
243 243
	if (!cFilemID) {
......
248 248
		releaseStylesheet();
249 249

  
250 250
		stylesheetObject = (jobject)(
251
				sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
252
						sxn_environ->env->NewStringUTF(cwdXT.c_str()),
253
						sxn_environ->env->NewStringUTF(stylesheet)));
251
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
252
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
253
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet)));
254 254
		if (!stylesheetObject) {
255 255
			if(exceptionOccurred()) {
256 256
				
257 257
				if(proc->exception != NULL) {
258 258
					delete proc->exception;
259 259
				}
260
				proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
260
				proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
261 261
				proc->exceptionClear();
262 262
	   		}
263 263
     		
264 264
		}
265
		//sxn_environ->env->NewGlobalRef(stylesheetObject);
265
		//SaxonProcessor::sxn_environ->env->NewGlobalRef(stylesheetObject);
266 266
	}
267 267

  
268 268
}
......
285 285

  
286 286
	setProperty("resources", proc->getResourcesDirectory());
287 287
	static jmethodID mID =
288
			(jmethodID) sxn_environ->env->GetMethodID(cppClass,
288
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
289 289
					"transformToNode",
290 290
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmNode;");
291 291
	if (!mID) {
......
295 295
	} else {
296 296
		jobjectArray stringArray = NULL;
297 297
		jobjectArray objectArray = NULL;
298
		jclass objectClass = lookForClass(sxn_environ->env,
298
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
299 299
				"java/lang/Object");
300
		jclass stringClass = lookForClass(sxn_environ->env,
300
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
301 301
				"java/lang/String");
302 302

  
303 303
		int size = parameters.size() + properties.size();
304 304
		if (size > 0) {
305
			objectArray = sxn_environ->env->NewObjectArray((jint) size,
305
			objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
306 306
					objectClass, 0);
307
			stringArray = sxn_environ->env->NewObjectArray((jint) size,
307
			stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
308 308
					stringClass, 0);
309 309
			int i = 0;
310 310
			for (map<std::string, XdmValue*>::iterator iter =
311 311
					parameters.begin(); iter != parameters.end(); ++iter, i++) {
312
				sxn_environ->env->SetObjectArrayElement(stringArray, i,
313
						sxn_environ->env->NewStringUTF(
312
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
313
						SaxonProcessor::sxn_environ->env->NewStringUTF(
314 314
								(iter->first).c_str()));
315
				sxn_environ->env->SetObjectArrayElement(objectArray, i,
315
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
316 316
						(iter->second)->getUnderlyingValue(proc));
317 317
			}
318 318
			for (map<std::string, std::string>::iterator iter =
319 319
					properties.begin(); iter != properties.end(); ++iter, i++) {
320
				sxn_environ->env->SetObjectArrayElement(stringArray, i,
321
						sxn_environ->env->NewStringUTF(
320
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
321
						SaxonProcessor::sxn_environ->env->NewStringUTF(
322 322
								(iter->first).c_str()));
323
				sxn_environ->env->SetObjectArrayElement(objectArray, i,
324
						sxn_environ->env->NewStringUTF(
323
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
324
						SaxonProcessor::sxn_environ->env->NewStringUTF(
325 325
								(iter->second).c_str()));
326 326
			}
327 327
		}
328 328
		jobject result = (jobject)(
329
				sxn_environ->env->CallObjectMethod(cppXT, mID,
330
						sxn_environ->env->NewStringUTF(cwdXT.c_str()),
329
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
330
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
331 331
						(sourcefile != NULL ?
332
								sxn_environ->env->NewStringUTF(sourcefile) :
332
								SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) :
333 333
								NULL),
334 334
						(stylesheetfile != NULL ?
335
								sxn_environ->env->NewStringUTF(
335
								SaxonProcessor::sxn_environ->env->NewStringUTF(
336 336
										stylesheetfile) :
337 337
								NULL), stringArray, objectArray));
338 338
		if (size > 0) {
339
			sxn_environ->env->DeleteLocalRef(stringArray);
340
			sxn_environ->env->DeleteLocalRef(objectArray);
339
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
340
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
341 341
		}
342 342
		if (result) {
343 343
			XdmNode * node = new XdmNode(result);
......
348 348
			if(proc->exception != NULL) {
349 349
				delete proc->exception;
350 350
			}
351
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
351
			proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
352 352
			proc->exceptionClear();
353 353
	   		
354 354
     		}
......
367 367
	}
368 368
	setProperty("resources", proc->getResourcesDirectory());
369 369
	jmethodID mID =
370
			(jmethodID) sxn_environ->env->GetMethodID(cppClass,
370
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
371 371
					"transformToFile",
372 372
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
373 373
	if (!mID) {
......
377 377
	} else {
378 378
		jobjectArray stringArray = NULL;
379 379
		jobjectArray objectArray = NULL;
380
		jclass objectClass = lookForClass(sxn_environ->env,
380
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
381 381
				"java/lang/Object");
382
		jclass stringClass = lookForClass(sxn_environ->env,
382
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
383 383
				"java/lang/String");
384 384

  
385 385
		int size = parameters.size() + properties.size();
......
389 389
		cerr<<"size:"<<size<<endl;
390 390
#endif
391 391
		if (size > 0) {
392
			objectArray = sxn_environ->env->NewObjectArray((jint) size,
392
			objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
393 393
					objectClass, 0);
394
			stringArray = sxn_environ->env->NewObjectArray((jint) size,
394
			stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
395 395
					stringClass, 0);
396 396
			if (objectArray == NULL) {
397 397
				cerr << "objectArray is NULL" << endl;
......
407 407
				cerr<<"map 1"<<endl;
408 408
				cerr<<"iter->first"<<(iter->first).c_str()<<endl;
409 409
#endif
410
				sxn_environ->env->SetObjectArrayElement(stringArray, i,
411
						sxn_environ->env->NewStringUTF(
410
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
411
						SaxonProcessor::sxn_environ->env->NewStringUTF(
412 412
								(iter->first).c_str()));
413 413
#ifdef DEBUG
414 414
				string s1 = typeid(iter->second).name();
......
424 424
					cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<endl;
425 425
				}
426 426
#endif
427
				sxn_environ->env->SetObjectArrayElement(objectArray, i,
427
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
428 428
						(iter->second)->getUnderlyingValue(proc));
429 429

  
430 430
			}
431 431

  
432 432
			for (map<std::string, std::string>::iterator iter =
433 433
					properties.begin(); iter != properties.end(); ++iter, i++) {
434
				sxn_environ->env->SetObjectArrayElement(stringArray, i,
435
						sxn_environ->env->NewStringUTF(
434
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
435
						SaxonProcessor::sxn_environ->env->NewStringUTF(
436 436
								(iter->first).c_str()));
437
				sxn_environ->env->SetObjectArrayElement(objectArray, i,
438
						sxn_environ->env->NewStringUTF(
437
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
438
						SaxonProcessor::sxn_environ->env->NewStringUTF(
439 439
								(iter->second).c_str()));
440 440
			}
441 441
		}
442
		sxn_environ->env->CallObjectMethod(cppXT, mID,
443
								sxn_environ->env->NewStringUTF(cwdXT.c_str()),
442
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
443
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
444 444
								(source != NULL ?
445
										sxn_environ->env->NewStringUTF(
445
										SaxonProcessor::sxn_environ->env->NewStringUTF(
446 446
												source) :
447 447
										NULL),
448
								sxn_environ->env->NewStringUTF(stylesheet),NULL,
448
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),NULL,
449 449
								stringArray, objectArray);
450 450
		if (size > 0) {
451
			sxn_environ->env->DeleteLocalRef(stringArray);
452
			sxn_environ->env->DeleteLocalRef(objectArray);
451
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
452
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
453 453
		}
454 454
		
455 455
	}
......
458 458
			if(proc->exception != NULL) {
459 459
				delete proc->exception;
460 460
			}
461
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
461
			proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
462 462
			proc->exceptionClear();
463 463
	   		
464 464
     		}
......
469 469

  
470 470
XdmValue * XsltProcessor::getXslMessages(){
471 471

  
472
jmethodID mID =   (jmethodID) sxn_environ->env->GetMethodID(cppClass,
472
jmethodID mID =   (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
473 473
					"getXslMessages",
474 474
					"()[Lnet/sf/saxon/s9api/XdmValue;");
475 475
	if (!mID) {
......
478 478

  
479 479
	} else {
480 480
jobjectArray results = (jobjectArray)(
481
			sxn_environ->env->CallObjectMethod(cppXT, mID));
482
	int sizex = sxn_environ->env->GetArrayLength(results);
481
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID));
482
	int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
483 483

  
484 484
	if (sizex>0) {
485 485
		XdmValue * value = new XdmValue();
486 486
		
487 487
		for (int p=0; p < sizex; ++p) 
488 488
		{
489
			jobject resulti = sxn_environ->env->GetObjectArrayElement(results, p);
489
			jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
490 490
			value->addUnderlyingValue(resulti);
491 491
		}
492
		sxn_environ->env->DeleteLocalRef(results);
492
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(results);
493 493
		return value;
494 494
	}
495 495
    }
......
506 506
	}
507 507
	setProperty("resources", proc->getResourcesDirectory());
508 508
	jmethodID mID =
509
			(jmethodID) sxn_environ->env->GetMethodID(cppClass,
509
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
510 510
					"transformToString",
511 511
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
512 512
	if (!mID) {
......
516 516
	} else {
517 517
		jobjectArray stringArray = NULL;
518 518
		jobjectArray objectArray = NULL;
519
		jclass objectClass = lookForClass(sxn_environ->env,
519
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
520 520
				"java/lang/Object");
521
		jclass stringClass = lookForClass(sxn_environ->env,
521
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
522 522
				"java/lang/String");
523 523

  
524 524
		int size = parameters.size() + properties.size();
......
527 527
		cerr<<"Parameter size: "<<parameters.size()<<endl;
528 528
#endif
529 529
		if (size > 0) {
530
			objectArray = sxn_environ->env->NewObjectArray((jint) size,
530
			objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
531 531
					objectClass, 0);
532
			stringArray = sxn_environ->env->NewObjectArray((jint) size,
532
			stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
533 533
					stringClass, 0);
534 534
			if (objectArray == NULL) {
535 535
				cerr << "objectArray is NULL" << endl;
......
545 545
				cerr<<"map 1"<<endl;
546 546
				cerr<<"iter->first"<<(iter->first).c_str()<<endl;
547 547
#endif
548
				sxn_environ->env->SetObjectArrayElement(stringArray, i,
549
						sxn_environ->env->NewStringUTF(
548
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
549
						SaxonProcessor::sxn_environ->env->NewStringUTF(
550 550
								(iter->first).c_str()));
551 551
#ifdef DEBUG
552 552
				string s1 = typeid(iter->second).name();
......
562 562
					cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<endl;
563 563
				}
564 564
#endif
565
				sxn_environ->env->SetObjectArrayElement(objectArray, i,
565
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
566 566
						(iter->second)->getUnderlyingValue(proc));
567 567

  
568 568
			}
569 569

  
570 570
			for (map<std::string, std::string>::iterator iter =
571 571
					properties.begin(); iter != properties.end(); ++iter, i++) {
572
				sxn_environ->env->SetObjectArrayElement(stringArray, i,
573
						sxn_environ->env->NewStringUTF(
572
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
573
						SaxonProcessor::sxn_environ->env->NewStringUTF(
574 574
								(iter->first).c_str()));
575
				sxn_environ->env->SetObjectArrayElement(objectArray, i,
576
						sxn_environ->env->NewStringUTF(
575
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
576
						SaxonProcessor::sxn_environ->env->NewStringUTF(
577 577
								(iter->second).c_str()));
578 578
			}
579 579
		}
......
581 581
	jstring result = NULL;
582 582
	jobject obj =
583 583
				(
584
						sxn_environ->env->CallObjectMethod(cppXT, mID,
585
								sxn_environ->env->NewStringUTF(cwdXT.c_str()),
584
						SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
585
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
586 586
								(source != NULL ?
587
										sxn_environ->env->NewStringUTF(
587
										SaxonProcessor::sxn_environ->env->NewStringUTF(
588 588
												source) :
589 589
										NULL),
590
								sxn_environ->env->NewStringUTF(stylesheet),
590
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),
591 591
								stringArray, objectArray));
592 592
		if(obj) {
593 593
			result = (jstring)obj;
594 594
		}		
595 595
		if (size > 0) {
596
			sxn_environ->env->DeleteLocalRef(stringArray);
597
			sxn_environ->env->DeleteLocalRef(objectArray);
596
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
597
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
598 598
		}
599 599
		if (result) {
600
			const char * str = sxn_environ->env->GetStringUTFChars(result,
600
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
601 601
					NULL);
602 602
			//return "result should be ok";
603 603
			return str;
......
605 605
			if(proc->exception != NULL) {
606 606
				delete proc->exception;
607 607
			}
608
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
608
			proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
609 609
			proc->exceptionClear();
610 610
	   		
611 611
     		}

Also available in: Unified diff