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/EEC/SaxonCGlue.c
40 40
	size_t rDir_len = strlen(tempResources_dir);
41 41
	char * env = getenv("SAXONC_HOME");
42 42
	size_t env_len;
43
	if (env != NULL) {
43
	if (env != nullptr) {
44 44

  
45 45

  
46 46
		env_len = strlen(env);
......
67 67
		resources_dir = malloc(sizeof(char)*rbufSize);
68 68

  
69 69
#ifdef DEBUG
70
		if (dllname == NULL || resources_dir == NULL)
70
		if (dllname == nullptr || resources_dir == nullptr)
71 71
		{
72 72
			// error
73 73
			printf("Error in allocation of Dllname\n");
......
118 118
 * Recommended method to use to load library
119 119
 */
120 120
HANDLE loadDefaultDll() {
121
	return loadDll(NULL);
121
	return loadDll(nullptr);
122 122
}
123 123

  
124 124

  
......
127 127
 */
128 128
HANDLE loadDll(char* name)
129 129
{
130
	if (name == NULL) {
130
	if (name == nullptr) {
131 131
		setDllname();
132 132
		name = getDllname();
133 133
		//perror("Error1: ");
......
243 243

  
244 244
	if (!clazz) {
245 245
		printf("Unable to find class %s\n", name);
246
		return NULL;
246
		return nullptr;
247 247
	}
248 248
#ifdef DEBUG
249 249
	printf("Class %s found\n", name);
......
333 333
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
334 334
	if (!MID_initi) {
335 335
		printf("Error: MyClassInDll.<init>() not found\n");
336
		return NULL;
336
		return nullptr;
337 337
	}
338 338

  
339 339
	if (argument1) {
......
346 346
	}
347 347
	if (!obj) {
348 348
		printf("Error: failed to allocate an object\n");
349
		return NULL;
349
		return nullptr;
350 350
	}
351 351
	return obj;
352 352
}
......
364 364
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
365 365
	if (!MID_initi) {
366 366
		printf("Error: MyClassInDll.<init>() not found\n");
367
		return NULL;
367
		return nullptr;
368 368
	}
369 369

  
370 370
	if (argument1) {
......
377 377
	}
378 378
	if (!obj) {
379 379
		printf("Error: failed to allocate an object\n");
380
		return NULL;
380
		return nullptr;
381 381
	}
382 382
	return obj;
383 383
}
......
405 405

  
406 406
		jmethodID getName = (jmethodID)(*(environii->env))->GetMethodID(environii->env, clscls, "getName", "()Ljava/lang/String;");
407 407
		jstring name = (jstring)((*(environii->env))->CallObjectMethod(environii->env, exccls, getName));
408
		char const* utfName = (*(environii->env))->GetStringUTFChars(environii->env, name, NULL);
408
		char const* utfName = (*(environii->env))->GetStringUTFChars(environii->env, name, nullptr);
409 409

  
410
		//if(callingObject != NULL && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
410
		//if(callingObject != nullptr && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
411 411

  
412 412
		jmethodID  getMessage = (jmethodID)(*(environii->env))->GetMethodID(environii->env, exccls, "getMessage", "()Ljava/lang/String;");
413 413

  
......
420 420
				(*(environii->env))->ExceptionClear(environii->env);
421 421
				return 0;
422 422
			}
423
			char const* utfMessage = (*(environii->env))->GetStringUTFChars(environii->env, message, NULL);
423
			char const* utfMessage = (*(environii->env))->GetStringUTFChars(environii->env, message, nullptr);
424 424

  
425
			if (utfMessage != NULL) {
425
			if (utfMessage != nullptr) {
426 426
				(*(environii->env))->ReleaseStringUTFChars(environii->env, name, utfName);
427 427
			}
428 428

  
......
455 455
 */
456 456
jobject getParameter(sxnc_parameter *parameters, int parLen, const char* namespacei, const char * name) {
457 457
	int i = 0;
458
	namespacei = NULL; // variable not used yet
459
	if (namespacei == NULL) {} // avoiding warning. In next release fix this
458
	namespacei = nullptr; // variable not used yet
459
	if (namespacei == nullptr) {} // avoiding warning. In next release fix this
460 460
	for (i = 0; i < parLen; i++) {
461 461
		if (strcmp(parameters[i].name, name) == 0)
462 462
			return (jobject)parameters[i].value;
463 463
	}
464
	return NULL;
464
	return nullptr;
465 465
}
466 466

  
467 467

  
......
470 470
 */
471 471
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name) {
472 472
	int i = 0;
473
	namespacei = NULL; // variable not used yet
474
	if (namespacei == NULL) {} // avoiding warning. In next release fix this
473
	namespacei = nullptr; // variable not used yet
474
	if (namespacei == nullptr) {} // avoiding warning. In next release fix this
475 475
	for (i = 0; i < propLen; i++) {
476 476
		if (strcmp(properties[i].name, name) == 0)
477 477
			return properties[i].value;
......
485 485
 */
486 486
void setParameter(sxnc_parameter **parameters, int * parLen, int * parCap, const char * namespacei, const char * name, jobject value) {
487 487

  
488
	namespacei = NULL;
488
	namespacei = nullptr;
489 489
	if (getParameter(*parameters, (*parLen), "", name) != 0) {
490 490
		return;
491 491
	}
......
558 558

  
559 559
const char * stringValue(sxnc_environment *environi, jobject value) {
560 560
	jclass  objClass = lookForClass(environi->env, "java/lang/Object");
561
	static jmethodID strMID = NULL;
561
	static jmethodID strMID = nullptr;
562 562
	if (!strMID) {
563 563
		strMID = (jmethodID)(*(environi->env))->GetMethodID(environi->env, objClass, "toString", "()Ljava/lang/String;");
564 564
		if (!strMID) {
565 565
			printf("\nError: Object %s() not found\n", "toString");
566 566
			fflush(stdout);
567
			return NULL;
567
			return nullptr;
568 568
		}
569 569
	}
570 570
	jstring result = (jstring)((*(environi->env))->CallObjectMethod(environi->env, value, strMID));
571 571
	if (result) {
572
		const char * str = (*(environi->env))->GetStringUTFChars(environi->env, result, NULL);
572
		const char * str = (*(environi->env))->GetStringUTFChars(environi->env, result, nullptr);
573 573
		return str;
574 574
	}
575 575

  
latest10/hec/Saxon.C.API/HEC/SaxonCGlue.c
41 41
	size_t rDir_len = strlen(tempResources_dir);
42 42
	char * env = getenv("SAXONC_HOME");
43 43
	size_t env_len;
44
	if (env != NULL) {
44
	if (env != nullptr) {
45 45

  
46 46

  
47 47
		env_len = strlen(env);
......
68 68
		resources_dir = malloc(sizeof(char)*rbufSize);
69 69

  
70 70
#ifdef DEBUG
71
		if (dllname == NULL || resources_dir == NULL)
71
		if (dllname == nullptr || resources_dir == nullptr)
72 72
		{
73 73
			// error
74 74
			printf("Error in allocation of Dllname\n");
......
119 119
 * Recommended method to use to load library
120 120
 */
121 121
HANDLE loadDefaultDll() {
122
	return loadDll(NULL);
122
	return loadDll(nullptr);
123 123
}
124 124

  
125 125

  
......
128 128
 */
129 129
HANDLE loadDll(char* name)
130 130
{
131
	if (name == NULL) {
131
	if (name == nullptr) {
132 132
		setDllname();
133 133
		name = getDllname();
134 134
		//perror("Error1: ");
......
244 244

  
245 245
	if (!clazz) {
246 246
		printf("Unable to find class %s\n", name);
247
		return NULL;
247
		return nullptr;
248 248
	}
249 249
#ifdef DEBUG
250 250
	printf("Class %s found\n", name);
......
334 334
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
335 335
	if (!MID_initi) {
336 336
		printf("Error: MyClassInDll.<init>() not found\n");
337
		return NULL;
337
		return nullptr;
338 338
	}
339 339

  
340 340
	if (argument1) {
......
347 347
	}
348 348
	if (!obj) {
349 349
		printf("Error: failed to allocate an object\n");
350
		return NULL;
350
		return nullptr;
351 351
	}
352 352
	return obj;
353 353
}
......
365 365
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
366 366
	if (!MID_initi) {
367 367
		printf("Error: MyClassInDll.<init>() not found\n");
368
		return NULL;
368
		return nullptr;
369 369
	}
370 370

  
371 371
	if (argument1) {
......
378 378
	}
379 379
	if (!obj) {
380 380
		printf("Error: failed to allocate an object\n");
381
		return NULL;
381
		return nullptr;
382 382
	}
383 383
	return obj;
384 384
}
......
406 406

  
407 407
		jmethodID getName = (jmethodID)(*(environii->env))->GetMethodID(environii->env, clscls, "getName", "()Ljava/lang/String;");
408 408
		jstring name = (jstring)((*(environii->env))->CallObjectMethod(environii->env, exccls, getName));
409
		char const* utfName = (*(environii->env))->GetStringUTFChars(environii->env, name, NULL);
409
		char const* utfName = (*(environii->env))->GetStringUTFChars(environii->env, name, nullptr);
410 410

  
411
		//if(callingObject != NULL && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
411
		//if(callingObject != nullptr && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
412 412

  
413 413
		jmethodID  getMessage = (jmethodID)(*(environii->env))->GetMethodID(environii->env, exccls, "getMessage", "()Ljava/lang/String;");
414 414

  
......
421 421
				(*(environii->env))->ExceptionClear(environii->env);
422 422
				return 0;
423 423
			}
424
			char const* utfMessage = (*(environii->env))->GetStringUTFChars(environii->env, message, NULL);
424
			char const* utfMessage = (*(environii->env))->GetStringUTFChars(environii->env, message, nullptr);
425 425

  
426
			if (utfMessage != NULL) {
426
			if (utfMessage != nullptr) {
427 427
				(*(environii->env))->ReleaseStringUTFChars(environii->env, name, utfName);
428 428
			}
429 429

  
......
456 456
 */
457 457
jobject getParameter(sxnc_parameter *parameters, int parLen, const char* namespacei, const char * name) {
458 458
	int i = 0;
459
	namespacei = NULL; // variable not used yet
460
	if (namespacei == NULL) {} // avoiding warning. In next release fix this
459
	namespacei = nullptr; // variable not used yet
460
	if (namespacei == nullptr) {} // avoiding warning. In next release fix this
461 461
	for (i = 0; i < parLen; i++) {
462 462
		if (strcmp(parameters[i].name, name) == 0)
463 463
			return (jobject)parameters[i].value;
464 464
	}
465
	return NULL;
465
	return nullptr;
466 466
}
467 467

  
468 468

  
......
471 471
 */
472 472
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name) {
473 473
	int i = 0;
474
	namespacei = NULL; // variable not used yet
475
	if (namespacei == NULL) {} // avoiding warning. In next release fix this
474
	namespacei = nullptr; // variable not used yet
475
	if (namespacei == nullptr) {} // avoiding warning. In next release fix this
476 476
	for (i = 0; i < propLen; i++) {
477 477
		if (strcmp(properties[i].name, name) == 0)
478 478
			return properties[i].value;
......
486 486
 */
487 487
void setParameter(sxnc_parameter **parameters, int * parLen, int * parCap, const char * namespacei, const char * name, jobject value) {
488 488

  
489
	namespacei = NULL;
489
	namespacei = nullptr;
490 490
	if (getParameter(*parameters, (*parLen), "", name) != 0) {
491 491
		return;
492 492
	}
......
559 559

  
560 560
const char * stringValue(sxnc_environment *environi, jobject value) {
561 561
	jclass  objClass = lookForClass(environi->env, "java/lang/Object");
562
	static jmethodID strMID = NULL;
562
	static jmethodID strMID = nullptr;
563 563
	if (!strMID) {
564 564
		strMID = (jmethodID)(*(environi->env))->GetMethodID(environi->env, objClass, "toString", "()Ljava/lang/String;");
565 565
		if (!strMID) {
566 566
			printf("\nError: Object %s() not found\n", "toString");
567 567
			fflush(stdout);
568
			return NULL;
568
			return nullptr;
569 569
		}
570 570
	}
571 571
	jstring result = (jstring)((*(environi->env))->CallObjectMethod(environi->env, value, strMID));
572 572
	if (result) {
573
		const char * str = (*(environi->env))->GetStringUTFChars(environi->env, result, NULL);
573
		const char * str = (*(environi->env))->GetStringUTFChars(environi->env, result, nullptr);
574 574
		return str;
575 575
	}
576 576

  
latest10/hec/Saxon.C.API/Makefile
62 62

  
63 63
libphp$(PHP_MAJOR_VERSION).la: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
64 64
	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -rpath $(phptempdir) $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@
65
	-@$(LIBTOOL) --silent --mode=install cp $@ $(phptempdir)/$@ >/dev/null 2>&1
65
	-@$(LIBTOOL) --silent --mode=install cp $@ $(phptempdir)/$@ >/dev/nullptr 2>&1
66 66

  
67 67
libs/libphp$(PHP_MAJOR_VERSION).bundle: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
68 68
	$(CC) $(MH_BUNDLE_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so
......
88 88
	@test -d modules && \
89 89
	$(mkinstalldirs) $(INSTALL_ROOT)$(EXTENSION_DIR)
90 90
	@echo "Installing shared extensions:     $(INSTALL_ROOT)$(EXTENSION_DIR)/"
91
	@rm -f modules/*.la >/dev/null 2>&1
91
	@rm -f modules/*.la >/dev/nullptr 2>&1
92 92
	@$(INSTALL) modules/* $(INSTALL_ROOT)$(EXTENSION_DIR)
93 93

  
94 94
install-headers:
......
111 111
				$(INSTALL_DATA) $(top_builddir)/$$src $(INSTALL_ROOT)$(phpincludedir)/$$i; \
112 112
			else \
113 113
				(cd $(top_srcdir)/$$src && $(INSTALL_DATA) *.h $(INSTALL_ROOT)$(phpincludedir)/$$i; \
114
				cd $(top_builddir)/$$src && $(INSTALL_DATA) *.h $(INSTALL_ROOT)$(phpincludedir)/$$i) 2>/dev/null || true; \
114
				cd $(top_builddir)/$$src && $(INSTALL_DATA) *.h $(INSTALL_ROOT)$(phpincludedir)/$$i) 2>/dev/nullptr || true; \
115 115
			fi \
116 116
		done; \
117 117
	fi
......
132 132

  
133 133
test: all
134 134
	@if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \
135
		INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \
135
		INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/nullptr`; \
136 136
		if test "$$INI_FILE"; then \
137 137
			$(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_FILE" > $(top_builddir)/tmp-php.ini; \
138 138
		else \
139 139
			echo > $(top_builddir)/tmp-php.ini; \
140 140
		fi; \
141
		INI_SCANNED_PATH=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r '$$a = explode(",\n", trim(php_ini_scanned_files())); echo $$a[0];' 2> /dev/null`; \
141
		INI_SCANNED_PATH=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r '$$a = explode(",\n", trim(php_ini_scanned_files())); echo $$a[0];' 2> /dev/nullptr`; \
142 142
		if test "$$INI_SCANNED_PATH"; then \
143 143
			INI_SCANNED_PATH=`$(top_srcdir)/build/shtool path -d $$INI_SCANNED_PATH`; \
144 144
			$(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_SCANNED_PATH"/*.ini >> $(top_builddir)/tmp-php.ini; \
latest10/hec/Saxon.C.API/PEC/SaxonCGlue.c
41 41
	size_t rDir_len = strlen(tempResources_dir);
42 42
	char * env = getenv("SAXONC_HOME");
43 43
	size_t env_len;
44
	if (env != NULL) {
44
	if (env != nullptr) {
45 45

  
46 46

  
47 47
		env_len = strlen(env);
......
68 68
		resources_dir = malloc(sizeof(char)*rbufSize);
69 69

  
70 70
#ifdef DEBUG
71
		if (dllname == NULL || resources_dir == NULL)
71
		if (dllname == nullptr || resources_dir == nullptr)
72 72
		{
73 73
			// error
74 74
			printf("Error in allocation of Dllname\n");
......
119 119
 * Recommended method to use to load library
120 120
 */
121 121
HANDLE loadDefaultDll() {
122
	return loadDll(NULL);
122
	return loadDll(nullptr);
123 123
}
124 124

  
125 125

  
......
128 128
 */
129 129
HANDLE loadDll(char* name)
130 130
{
131
	if (name == NULL) {
131
	if (name == nullptr) {
132 132
		setDllname();
133 133
		name = getDllname();
134 134
		//perror("Error1: ");
......
244 244

  
245 245
	if (!clazz) {
246 246
		printf("Unable to find class %s\n", name);
247
		return NULL;
247
		return nullptr;
248 248
	}
249 249
#ifdef DEBUG
250 250
	printf("Class %s found\n", name);
......
334 334
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
335 335
	if (!MID_initi) {
336 336
		printf("Error: MyClassInDll.<init>() not found\n");
337
		return NULL;
337
		return nullptr;
338 338
	}
339 339

  
340 340
	if (argument1) {
......
347 347
	}
348 348
	if (!obj) {
349 349
		printf("Error: failed to allocate an object\n");
350
		return NULL;
350
		return nullptr;
351 351
	}
352 352
	return obj;
353 353
}
......
365 365
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
366 366
	if (!MID_initi) {
367 367
		printf("Error: MyClassInDll.<init>() not found\n");
368
		return NULL;
368
		return nullptr;
369 369
	}
370 370

  
371 371
	if (argument1) {
......
378 378
	}
379 379
	if (!obj) {
380 380
		printf("Error: failed to allocate an object\n");
381
		return NULL;
381
		return nullptr;
382 382
	}
383 383
	return obj;
384 384
}
......
406 406

  
407 407
		jmethodID getName = (jmethodID)(*(environii->env))->GetMethodID(environii->env, clscls, "getName", "()Ljava/lang/String;");
408 408
		jstring name = (jstring)((*(environii->env))->CallObjectMethod(environii->env, exccls, getName));
409
		char const* utfName = (*(environii->env))->GetStringUTFChars(environii->env, name, NULL);
409
		char const* utfName = (*(environii->env))->GetStringUTFChars(environii->env, name, nullptr);
410 410

  
411
		//if(callingObject != NULL && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
411
		//if(callingObject != nullptr && strcmp(utfName, "net.sf.saxon.s9api.SaxonApiException") == 0){
412 412

  
413 413
		jmethodID  getMessage = (jmethodID)(*(environii->env))->GetMethodID(environii->env, exccls, "getMessage", "()Ljava/lang/String;");
414 414

  
......
421 421
				(*(environii->env))->ExceptionClear(environii->env);
422 422
				return 0;
423 423
			}
424
			char const* utfMessage = (*(environii->env))->GetStringUTFChars(environii->env, message, NULL);
424
			char const* utfMessage = (*(environii->env))->GetStringUTFChars(environii->env, message, nullptr);
425 425

  
426
			if (utfMessage != NULL) {
426
			if (utfMessage != nullptr) {
427 427
				(*(environii->env))->ReleaseStringUTFChars(environii->env, name, utfName);
428 428
			}
429 429

  
......
456 456
 */
457 457
jobject getParameter(sxnc_parameter *parameters, int parLen, const char* namespacei, const char * name) {
458 458
	int i = 0;
459
	namespacei = NULL; // variable not used yet
460
	if (namespacei == NULL) {} // avoiding warning. In next release fix this
459
	namespacei = nullptr; // variable not used yet
460
	if (namespacei == nullptr) {} // avoiding warning. In next release fix this
461 461
	for (i = 0; i < parLen; i++) {
462 462
		if (strcmp(parameters[i].name, name) == 0)
463 463
			return (jobject)parameters[i].value;
464 464
	}
465
	return NULL;
465
	return nullptr;
466 466
}
467 467

  
468 468

  
......
471 471
 */
472 472
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name) {
473 473
	int i = 0;
474
	namespacei = NULL; // variable not used yet
475
	if (namespacei == NULL) {} // avoiding warning. In next release fix this
474
	namespacei = nullptr; // variable not used yet
475
	if (namespacei == nullptr) {} // avoiding warning. In next release fix this
476 476
	for (i = 0; i < propLen; i++) {
477 477
		if (strcmp(properties[i].name, name) == 0)
478 478
			return properties[i].value;
......
486 486
 */
487 487
void setParameter(sxnc_parameter **parameters, int * parLen, int * parCap, const char * namespacei, const char * name, jobject value) {
488 488

  
489
	namespacei = NULL;
489
	namespacei = nullptr;
490 490
	if (getParameter(*parameters, (*parLen), "", name) != 0) {
491 491
		return;
492 492
	}
......
559 559

  
560 560
const char * stringValue(sxnc_environment *environi, jobject value) {
561 561
	jclass  objClass = lookForClass(environi->env, "java/lang/Object");
562
	static jmethodID strMID = NULL;
562
	static jmethodID strMID = nullptr;
563 563
	if (!strMID) {
564 564
		strMID = (jmethodID)(*(environi->env))->GetMethodID(environi->env, objClass, "toString", "()Ljava/lang/String;");
565 565
		if (!strMID) {
566 566
			printf("\nError: Object %s() not found\n", "toString");
567 567
			fflush(stdout);
568
			return NULL;
568
			return nullptr;
569 569
		}
570 570
	}
571 571
	jstring result = (jstring)((*(environi->env))->CallObjectMethod(environi->env, value, strMID));
572 572
	if (result) {
573
		const char * str = (*(environi->env))->GetStringUTFChars(environi->env, result, NULL);
573
		const char * str = (*(environi->env))->GetStringUTFChars(environi->env, result, nullptr);
574 574
		return str;
575 575
	}
576 576

  
latest10/hec/Saxon.C.API/Query.c
1
#include <jni.h>
2

  
3
#ifdef __linux__
4
    #include <stdlib.h>
5
    #include <string.h>
6
    #include <dlfcn.h>
7
    #include <stdio.h>  
8
    #define HANDLE void*
9
    #define LoadLibrary(x) dlopen(x, RTLD_LAZY)
10
//    #define FreeLibrary(x) dlclose(x, RTLD_LAZY)
11
    #define GetProcAddress(x,y) dlsym(x,y)
12
#else
13
    #include <windows.h>
14
#endif
15

  
16
typedef int bool;
17
#define true 1
18
#define false 0
19

  
20

  
21
char dllname[] =
22
    #ifdef __linux__
23
#ifdef EEC
24
        "/usr/lib/libsaxoneec.so";
25
#elif defined PEC
26
	"/usr/lib/libsaxonpec.so";
27
#else
28
	"/usr/lib/libsaxonhec.so";
29
#endif
30
    #else
31
#ifdef EEC
32
        "Saxon-eec.dll";
33
#elif defined PEC
34
	"Saxon-pec.dll";
35
#else
36
	"Saxon-hec.dll";
37
#endif
38
    #endif
39

  
40
//===============================================================================================//
41
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
42
 * <p/>
43
 */
44
typedef struct {
45
		JNIEnv *env;
46
		HANDLE myDllHandle;
47
		JavaVM *jvm;
48
	} Environment;
49

  
50

  
51
//===============================================================================================//
52

  
53
/*! <code>MyParameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
54
 * <p/>
55
 */
56
typedef struct {
57
		char* name;
58
		jobject value;
59
	} MyParameter;
60

  
61
//===============================================================================================//
62

  
63
/*! <code>MyProperty</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
64
 * <p/>
65
 */
66
typedef struct {
67
		char * name;
68
		char * value;
69
	} MyProperty;
70

  
71
jobject cpp;
72

  
73

  
74

  
75
const char * failure;
76
/*
77
 * Load dll.
78
 */
79
HANDLE loadDll(char* name)
80
{
81
    HANDLE hDll = LoadLibrary (name);
82

  
83
    if (!hDll) {
84
        printf ("Unable to load %s\n", name);
85
        exit(1);
86
    }
87
#ifdef DEBUG
88
    printf ("%s loaded\n", name);
89
#endif
90
    return hDll;
91
}
92

  
93

  
94
jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
95
jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
96

  
97
/*
98
 * Initialize JET run-time.
99
 */
100
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv)
101
{
102
    int            result;
103
    JavaVMInitArgs args;
104

  
105
    JNI_GetDefaultJavaVMInitArgs_func = 
106
             (jint (JNICALL *) (void *args))
107
             GetProcAddress (myDllHandle, "JNI_GetDefaultJavaVMInitArgs");
108

  
109
    JNI_CreateJavaVM_func =
110
             (jint (JNICALL *) (JavaVM **pvm, void **penv, void *args))
111
             GetProcAddress (myDllHandle, "JNI_CreateJavaVM");
112

  
113
    if(!JNI_GetDefaultJavaVMInitArgs_func) {
114
        printf ("%s doesn't contain public JNI_GetDefaultJavaVMInitArgs\n", dllname);
115
        exit (1);
116
    }
117

  
118
    if(!JNI_CreateJavaVM_func) {
119
        printf ("%s doesn't contain public JNI_CreateJavaVM\n", dllname);
120
        exit (1);
121
    }
122

  
123
    memset (&args, 0, sizeof(args));
124

  
125
    args.version = JNI_VERSION_1_2;
126
    result = JNI_GetDefaultJavaVMInitArgs_func(&args);
127
    if (result != JNI_OK) {
128
        printf ("JNI_GetDefaultJavaVMInitArgs() failed with result %d\n", result);
129
        exit(1);
130
    }
131
  
132
    /*
133
     * NOTE: no JVM is actually created
134
     * this call to JNI_CreateJavaVM is intended for JET RT initialization
135
     */
136
    result = JNI_CreateJavaVM_func (pjvm, (void **)penv, &args);
137
    if (result != JNI_OK) {
138
        printf ("JNI_CreateJavaVM() failed with result %d\n", result);
139
        exit(1);
140
    }
141
#ifdef DEBUG
142
    printf ("JET RT initialized\n");
143
    fflush (stdout);
144
#endif
145
}
146

  
147

  
148
/*
149
 * Look for class.
150
 */
151
jclass lookForClass (JNIEnv* penv, char* name)
152
{
153
    jclass clazz = (*penv)->FindClass (penv, name);
154

  
155
    if (!clazz) {
156
        printf("Unable to find class %s\n", name);
157
	return NULL;
158
    }
159
#ifdef DEBUG
160
    printf ("Class %s found\n", name);
161
    fflush (stdout);
162
#endif
163

  
164
    return clazz;
165
}
166

  
167

  
168
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments)
169
{
170
    jmethodID MID_init, mID;
171
    jobject obj;
172

  
173
    MID_init = (jmethodID)(*penv)->GetMethodID (penv, myClassInDll, "<init>", arguments);
174
    if (!MID_init) {
175
        printf("Error: MyClassInDll.<init>() not found\n");
176
	fflush (stdout);
177
        return 0;
178
    }
179

  
180
  return MID_init;
181
}
182

  
183
jobject createObject (JNIEnv* penv, jclass myClassInDll, const char * arguments)
184
{
185
    jmethodID MID_init, mID;
186
    jobject obj;
187

  
188
    MID_init = (jmethodID)(*(penv))->GetMethodID (penv, myClassInDll, "<init>", arguments);
189
    if (!MID_init) {
190
        printf("Error: MyClassInDll.<init>() not found\n");
191
        return NULL;
192
    }
193

  
194
      obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_init, (jboolean)true);
195
      if (!obj) {
196
        printf("Error: failed to allocate an object\n");
197
        return NULL;
198
      }
199
    return obj;
200
}
201

  
202
void checkForException(Environment environ, jclass callingClass,  jobject callingObject){
203

  
204
    if ((*(environ.env))->ExceptionCheck(environ.env)) {
205
	char *  result1;
206
	const char * errorCode = NULL;
207
	jthrowable exc = (*(environ.env))->ExceptionOccurred(environ.env);
208
	(*(environ.env))->ExceptionDescribe(environ.env); //comment code
209
	 jclass exccls = (jclass)(*(environ.env))->GetObjectClass(environ.env, exc);
210
        jclass clscls = (jclass)(*(environ.env))->FindClass(environ.env, "java/lang/Class");
211

  
212
        jmethodID getName = (jmethodID)(*(environ.env))->GetMethodID(environ.env, clscls, "getName", "()Ljava/lang/String;");
213
        jstring name =(jstring)((*(environ.env))->CallObjectMethod(environ.env, exccls, getName));
214
        char const* utfName = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, name, 0);
215
	printf(utfName);
216

  
217
	 jmethodID  getMessage = (jmethodID)(*(environ.env))->GetMethodID(environ.env, exccls, "getMessage", "()Ljava/lang/String;");
218
	if(getMessage) {
219

  
220
		jstring message = (jstring)((*(environ.env))->CallObjectMethod(environ.env, exc, getMessage));
221
		if(message) {        	
222
			char const* utfMessage = (char const*)(*(environ.env))->GetStringUTFChars(environ.env, message, 0);
223
		}
224
	
225
	}
226

  
227
     }
228
	//return NULL;
229

  
230
}
231

  
232

  
233
void finalizeJavaRT (JavaVM* jvm)
234
{
235
    (*jvm)->DestroyJavaVM (jvm);
236
}
237

  
238

  
239

  
240

  
241

  
242
int query(Environment environ, int argc, const char* argv[]) {
243

  
244

  
245
    jmethodID MID_foo;
246
    jclass transClass = lookForClass(environ.env, "net/sf/saxon/Query");
247
    char methodName[] = "main";
248
    char args[] = "([Ljava/lang/String;)V";
249
    jobjectArray stringArray = NULL;
250
    MID_foo = (jmethodID)(*(environ.env))->GetStaticMethodID(environ.env, transClass, methodName, args);
251
    if (!MID_foo) {
252
	printf("\nError: MyClassInDll %s() not found\n",methodName);
253
	fflush (stdout);
254
        return -1;
255
    }
256
     if(argc < 2) {
257
	printf("\nError: Not enough arguments in Query");
258
	return 0;
259
    }
260
	   jclass stringClass = lookForClass(environ.env, "java/lang/String");
261
	   stringArray = (*(environ.env))->NewObjectArray(environ.env, (jint)argc-1, stringClass, 0 );
262
	   if(!stringArray) { return 0;}
263
  int i, j;
264
  for(i=1, j=0; i< argc; i++, j++) {
265
	     (*(environ.env))->SetObjectArrayElement(environ.env, stringArray, j, (*(environ.env))->NewStringUTF(environ.env, argv[i]));
266
	   }
267

  
268
   (*(environ.env))->CallStaticVoidMethod(environ.env, transClass, MID_foo, stringArray);
269
   
270
  (*(environ.env))->DeleteLocalRef(environ.env, stringArray);
271
	return 0;
272
}
273

  
274

  
275

  
276

  
277
int main( int argc, const char* argv[] )
278
{
279
    HANDLE myDllHandle;
280
    //JNIEnv *(environ.env);
281
    //JavaVM *jvm;
282
    jclass  myClassInDll;
283

  
284
    Environment environ;
285
    /*
286
     * First of all, load required component.
287
     * By the time of JET initialization, all components should be loaded.
288
     */
289
    environ.myDllHandle = loadDll (dllname);
290
   
291

  
292
    /*
293
     * Initialize JET run-time.
294
     * The handle of loaded component is used to retrieve Invocation API.
295
     */
296
    initJavaRT (environ.myDllHandle, &environ.jvm, &environ.env);
297
    query(environ, argc, argv);	
298

  
299
  
300
fflush(stdout);
301
    /*
302
     * Finalize JET run-time.
303
     */
304
    finalizeJavaRT (environ.jvm);
305

  
306
    return 0;
307
}
latest10/hec/Saxon.C.API/SaxonApiException.cpp
26 26

  
27 27

  
28 28
	SaxonApiException::SaxonApiException(const char * m, const char * ec, const char * sysId, int linenumber){
29
		if(m != NULL) {
29
		if(m != nullptr) {
30 30
		    message = std::string(m);
31 31
		} else {
32 32
		    message = "";
......
34 34

  
35 35
        lineNumber = linenumber;
36 36

  
37
        if (ec != NULL) {
37
        if (ec != nullptr) {
38 38
            errorCode = std::string(ec);
39 39
        } else {
40 40
            errorCode = "";
41 41
        }
42 42

  
43
        if(sysId != NULL) {
43
        if(sysId != nullptr) {
44 44
            systemId = sysId;
45 45
        } else {
46 46
            systemId = "";
......
53 53
    /**
54 54
     * A destructor.
55 55
     */
56
	SaxonApiException::~SaxonApiException() throw {
56
	SaxonApiException::~SaxonApiException() noexcept {
57 57
        message.clear();
58 58
        errorCode.clear();
59 59
        systemId.clear();
......
62 62
    /**
63 63
     * Get the error code associated with the ith exception in the vector, if there is one
64 64
     * @param i - ith exception in the vector
65
     * @return the associated error code, or null if no error code is available
65
     * @return the associated error code, or nullptr if no error code is available
66 66
     */
67 67
	const char * SaxonApiException::getErrorCode(){
68 68
		return errorCode.c_str();
latest10/hec/Saxon.C.API/SaxonApiException.h
65 65

  
66 66
    /**
67 67
     * Get the error code associated with the exception, if it exists
68
     * @return the associated error code, or null if no error code is available
68
     * @return the associated error code, or nullptr if no error code is available
69 69
     */
70 70
	const char * getErrorCode();
71 71

  
......
76 76
    /**
77 77
     * Returns the detail message string of the throwable, if there is one
78 78
     * @return the detail message string of this <tt>Throwable</tt> instance
79
     *         (which may be <tt>null</tt>).
79
     *         (which may be <tt>nullptr</tt>).
80 80
     */
81 81
	const char * getMessage();
82 82

  
latest10/hec/Saxon.C.API/SaxonCGlue.h
198 198

  
199 199
/*
200 200
 * Create the Java SaxonProcessor
201
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
201
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be nullptr or Processor object
202 202
 */
203 203
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
204 204

  
205 205
/*
206 206
 * Create the Java SaxonProcessor
207
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
207
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be nullptr or Processor object
208 208
 */
209 209
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
210 210

  
latest10/hec/Saxon.C.API/SaxonCProcessor.c
184 184

  
185 185
	
186 186
      if(result) {
187
        const char * str = (*(environi.env))->GetStringUTFChars(environi.env, result, NULL);    
187
        const char * str = (*(environi.env))->GetStringUTFChars(environi.env, result, NULL);
188 188
	return str;
189 189
     }
190 190

  
......
201 201
		cpp = (jobject) createSaxonProcessor (environi.env, cppClass, "(Z)V", NULL, (jboolean)sxn_license);
202 202
	}
203 203
 	
204
	if(queryFileID == NULL) {	
204
	if(queryFileID == NULL) {
205 205
		queryFileID = (jmethodID)(*(environi.env))->GetMethodID (environi.env, cppClass,"executeQueryToFile", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
206 206
 		if (!queryFileID) {
207 207
        		printf("Error: MyClassInDll. executeQueryToString not found\n");
......
242 242
	   
243 243
	}
244 244
	}
245
      (*(environi.env))->CallVoidMethod(environi.env,cpp, queryFileID, (cwd== NULL ? (*(environi.env))->NewStringUTF(environi.env, "") : (*(environi.env))->NewStringUTF(environi.env, cwd)), (*(environi.env))->NewStringUTF(environi.env, outputfile), stringArray, objectArray );    
245
      (*(environi.env))->CallVoidMethod(environi.env,cpp, queryFileID, (cwd== NULL ? (*(environi.env))->NewStringUTF(environi.env, "") : (*(environi.env))->NewStringUTF(environi.env, cwd)), (*(environi.env))->NewStringUTF(environi.env, outputfile), stringArray, objectArray );
246 246
	  (*(environi.env))->DeleteLocalRef(environi.env, objectArray);
247 247
	  (*(environi.env))->DeleteLocalRef(environi.env, stringArray);
248 248

  
latest10/hec/Saxon.C.API/SaxonCXPath.c
10 10
jobject booleanValue(sxnc_environment *environi, bool b){ 
11 11
	
12 12
	 if(environi->env == NULL) {
13
		printf("Error: Saxon-C env variable is null\n");
13
		printf("Error: Saxon-C env variable is NULL\n");
14 14
		fflush (stdout);
15 15
           	return NULL;
16 16
	 }
......
35 35
jobject integerValue(sxnc_environment *environi, int i){ 
36 36
	
37 37
	 if(environi->env == NULL) {
38
		printf("Error: Saxon-C env variable is null\n");
38
		printf("Error: Saxon-C env variable is NULL\n");
39 39
		fflush (stdout);
40 40
           	return NULL;
41 41
	 }
......
67 67
jobject doubleValue(sxnc_environment *environi, double d){ 
68 68
	
69 69
	 if(environi->env == NULL) {
70
		printf("Error: Saxon-C env variable is null\n");
70
		printf("Error: Saxon-C env variable is NULL\n");
71 71
		fflush (stdout);
72 72
           	return NULL;
73 73
	 }
......
92 92
jobject floatValue(sxnc_environment *environi, float f){ 
93 93
	
94 94
	 if(environi->env == NULL) {
95
		printf("Error: Saxon-C env variable is null\n");
95
		printf("Error: Saxon-C env variable is NULL\n");
96 96
		fflush (stdout);
97 97
           	return NULL;
98 98
	 }
......
118 118
jobject longValue(sxnc_environment *environi, long l){ 
119 119
	
120 120
	 if(environi->env == NULL) {
121
		printf("Error: Saxon-C env variable is null\n");
121
		printf("Error: Saxon-C env variable is NULL\n");
122 122
		fflush (stdout);
123 123
           	return NULL;
124 124
	 }
......
143 143
jobject getJavaStringValue(sxnc_environment *environi, const char *str){ 
144 144
	
145 145
	 if(environi->env == NULL) {
146
		printf("Error: Saxon-C env variable is null\n");
146
		printf("Error: Saxon-C env variable is NULL\n");
147 147
		fflush (stdout);
148 148
           	return NULL;
149 149
	 }
......
166 166
	
167 167
	jclass  saxoncClass = lookForClass(environi->env, "net/sf/saxon/option/cpp/SaxonCAPI");
168 168
	 if(environi->env == NULL) {
169
		printf("Error: Saxon-C env variable is null\n");
169
		printf("Error: Saxon-C env variable is NULL\n");
170 170
		fflush (stdout);
171 171
           	return NULL;
172 172
	 }
......
198 198
	
199 199
	jclass  saxoncClass = lookForClass(environi->env, "net/sf/saxon/option/cpp/SaxonCAPI");
200 200
	 if(environi->env == NULL) {
201
		printf("Error: Saxon-C env variable is null\n");
201
		printf("Error: Saxon-C env variable is NULL\n");
202 202
		fflush (stdout);
203 203
           	return NULL;
204 204
	 }
......
360 360
	
361 361
	jclass  xdmValueClass = lookForClass(environi->env, "net/sf/saxon/s9api/XdmValue");
362 362
	 if(environi->env == NULL) {
363
		printf("Error: Saxon-C env variable is null\n");
363
		printf("Error: Saxon-C env variable is NULL\n");
364 364
		fflush (stdout);
365 365
           	return 0;
366 366
	 }
......
386 386
	
387 387
	jclass  xdmValueClass = lookForClass(environi->env, "net/sf/saxon/s9api/XdmValue");
388 388
	 if(environi->env == NULL) {
389
		printf("Error: Saxon-C env variable is null\n");
389
		printf("Error: Saxon-C env variable is NULL\n");
390 390
		fflush (stdout);
391 391
           	return 0;
392 392
	 }
......
418 418
	
419 419
jclass  xdmItemClass = lookForClass(environi->env, "net/sf/saxon/s9api/XdmItem");
420 420
	 if(environi->env == NULL) {
421
		printf("Error: Saxon-C env variable is null\n");
421
		printf("Error: Saxon-C env variable is NULL\n");
422 422
		fflush (stdout);
423 423
           	return 0;
424 424
	 }
......
441 441
int getIntegerValue(sxnc_environment *environi, sxnc_value value,  int failureVal){
442 442
	
443 443
	const char * valueStr = getStringValue(environi, value);
444
	if(valueStr != NULL) {		
444
	if(valueStr != NULL) {
445 445
		int value = atoi(valueStr);
446 446
		if(value != 0) {
447 447
			return value;
......
473 473
long getLongValue(sxnc_environment *environi, sxnc_value value,  long failureVal){
474 474
	
475 475
	const char * valueStr = getStringValue(environi, value);
476
	if(valueStr != NULL) {		
476
	if(valueStr != NULL) {
477 477
		long value = atol(valueStr);
478 478
		if(value != 0) {
479 479
			return value;
......
511 511
double getDoubleValue(sxnc_environment *environi, sxnc_value value, double failureVal){
512 512
	
513 513
	const char * valueStr = getStringValue(environi, value);
514
	if(valueStr != NULL) {		
514
	if(valueStr != NULL) {
515 515
		double value = atof(valueStr);
516 516
		if(value != 0) {
517 517
			return value;
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.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff