Project

Profile

Help

Revision 4ee4355d

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes with exception handling and other

View differences:

src/main/c/Saxon.C.API/SaxonCGlue.c
396 396
/*
397 397
 * Callback to check for exceptions. When called it returns the exception as a string
398 398
 */
399
const char * checkForException(sxnc_environment *environii, jobject callingObject) {
400
	if (callingObject) {} // TODO: Remove the callingObject variable
399
const char * checkForException(sxnc_environment *environii) {
401 400
	if ((*(environii->env))->ExceptionCheck(environii->env)) {
402 401

  
403 402
		jthrowable exc = (*(environii->env))->ExceptionOccurred(environii->env);
......
440 439
		// }
441 440
		(*(environii->env))->ReleaseStringUTFChars(environii->env, name, utfName);
442 441
	}
443
	//(*(environii->env))->ExceptionClear(environii->env);
442

  
444 443
	return 0;
445 444
}
446 445

  
src/main/c/Saxon.C.API/SaxonCGlue.h
211 211
/*
212 212
 * Callback to check for exceptions. When called it returns the exception as a string 
213 213
 */
214
const char * checkForException(sxnc_environment *environi, jobject callingObject);
214
const char * checkForException(sxnc_environment *environi);
215 215

  
216 216
/*
217 217
 * Clean up and destroy Java VM to release memory used. 
src/main/c/Saxon.C.API/SaxonCProcessor.c
306 306
	return str;
307 307
     }
308 308

  
309
    checkForException( *(environi.env), cpp);
309
    checkForException( *(environi.env));
310 310
    return 0;
311 311

  
312 312
}
src/main/c/Saxon.C.API/SaxonCXPath.c
282 282
	return result;
283 283
     }
284 284

  
285
    checkForException(environi,cpp);
285
    checkForException(environi);
286 286
    return 0;
287 287

  
288 288
}
......
344 344
      (*(environi->env))->DeleteLocalRef(environi->env, objectArray);
345 345
      (*(environi->env))->DeleteLocalRef(environi->env, stringArray);
346 346
      if(resultObj) {
347
	 checkForException(environi, cpp);    
347
	 checkForException(environi);
348 348
	return resultObj;
349 349
     }
350 350

  
351
    checkForException(environi, cpp);
351
    checkForException(environi);
352 352
    return 0; //false
353 353
}
354 354

  
src/main/c/Saxon.C.API/SaxonProcessor.cpp
31 31
    return SaxonProcessor::sxn_environ->env->ExceptionCheck() || exception != nullptr;
32 32
}
33 33

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

  
......
792 792
        /*clearParameters();
793 793
        clearProperties();*/
794 794
    } else {
795
//#ifdef DEBUG
795
#ifdef DEBUG
796 796
        std::cerr << "SaxonProc: JVM finalize not called!" << std::endl;
797
//#endif
797
#endif
798 798
    }
799 799
}
800 800

  
......
814 814
    }
815 815
    jobject obj2 = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mssID_atomic, obj));
816 816
    XdmAtomicValue *value = new XdmAtomicValue(obj2, "xs:string");
817
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
818
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj2);
817 819
    return value;
818 820
}
819 821

  
......
830 832
    }
831 833
    jobject obj2 = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, msID_atomic, obj));
832 834
    XdmAtomicValue *value = new XdmAtomicValue(obj2, "xs:string");
835
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
833 836
    return value;
834 837
}
835 838

  
......
845 848
    }
846 849
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, miiID_atomic, (jlong) i));
847 850
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}integer");
851
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
848 852
    return value;
849 853
}
850 854

  
......
856 860
    }
857 861
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mdID_atomic, (jdouble) d));
858 862
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}double");
863
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
859 864
    return value;
860 865
}
861 866

  
......
867 872
    }
868 873
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mfID_atomic, (jfloat) d));
869 874
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}float");
875
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
870 876
    return value;
871 877
}
872 878

  
......
878 884
    }
879 885
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mlID_atomic, (jlong) l));
880 886
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}long");
887
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
881 888
    return value;
882 889
}
883 890

  
......
889 896
    }
890 897
    jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jboolean) b));
891 898
    XdmAtomicValue *value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}boolean");
899
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
892 900
    return value;
893 901
}
894 902

  
895 903
XdmAtomicValue *SaxonProcessor::makeQNameValue(const char *str) {
896 904
    jobject val = xdmValueAsObj(SaxonProcessor::sxn_environ, "QName", str);
897 905
    XdmAtomicValue *value = new XdmAtomicValue(val, "QName");
906
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(val);
898 907
    return value;
899 908
}
900 909

  
901 910
XdmAtomicValue *SaxonProcessor::makeAtomicValue(const char *typei, const char *strValue) {
902 911
    jobject obj = xdmValueAsObj(SaxonProcessor::sxn_environ, typei, strValue);
903 912
    XdmAtomicValue *value = new XdmAtomicValue(obj, typei);
913
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
904 914
    return value;
905 915
}
906 916

  
src/main/c/Saxon.C.API/SaxonProcessor.h
540 540

  
541 541
    static jobjectArray createJArray(XdmValue **values, int length);
542 542

  
543
    static const char *checkException(jobject cpp);
543
    static const char *checkException();
544 544
};
545 545

  
546 546
//===============================================================================================
src/main/c/Saxon.C.API/SchemaValidator.cpp
435 435
}
436 436

  
437 437
const char* SchemaValidator::checkException() {
438
	return proc->checkException(cppV);
438
	return proc->checkException();
439 439
}
440 440

  
441 441
/*int SchemaValidator::exceptionCount(){
src/main/c/Saxon.C.API/XPathProcessor.cpp
490 490

  
491 491

  
492 492
    const char* XPathProcessor::checkException(){
493
	return proc->checkException(cppXP);
493
	return proc->checkException();
494 494
    }
495 495

  
src/main/c/Saxon.C.API/XQueryProcessor.cpp
498 498
		proc->exception = proc->checkForException(SaxonProcessor::sxn_environ->env, cppClass, cppXQ);
499 499
	}
500 500
        return proc->exception;*/
501
	return proc->checkException(cppXQ);
501
	return proc->checkException();
502 502
}
503 503

  
504 504

  
src/main/c/Saxon.C.API/XdmValue.cpp
128 128
XdmValue::~XdmValue() {
129 129
	//bool safeToClear = false;
130 130
	//std::cout<<"xdmValue destructor size= "<<values.size()<<" ref="<<getRefCount()<<" Pointer = "<<(this)<<std::endl;
131
    //if(getRefCount()<1){
132
	//proc->env->ReleaseObject
133 131
	if(values.size() > 0) {
134 132
        for (size_t i = 0; i < values.size(); i++) {
135
            values[i]->decrementRefCount();
136
            if (values[i] != nullptr && values[i]->getRefCount() < 1) {
133
            if (values[i] != nullptr) {
134
                //values[i]->decrementRefCount();
137 135
                delete values[i];
138 136
            }
139 137
        }
......
141 139
    }
142 140
	if (valueType != nullptr) { delete valueType; }
143 141
	if (jValues) {
144
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);
142
		SaxonProcessor::sxn_environ->env->DeleteGlobalRef(jValues);
145 143
	}
146 144
	xdmSize = 0;
147 145

  
148
    //}
149

  
150 146
    if(!toStringValue.empty()) {
151 147
        toStringValue.clear();
152 148
    }
......
159 155
        val->incrementRefCount();
160 156
		xdmSize++;
161 157
        if (jValues) {
162
            std::cout<<"xdmValue jni"<<getRefCount()<<std::endl;
163
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);  //TODO check - this maybe should be DeleteGlobalRef  - check where it is created
158
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(jValues);
164 159
            jValues = nullptr;
165 160
        }
166 161

  
......
222 217
}
223 218

  
224 219
void XdmValue::releaseXdmValue() {
220
    for (size_t i = 0; i < values.size(); i++) {
221
        if (values[i] != nullptr) {
222
            delete values[i];
223
        }
224
    }
225 225

  
226
    if(jValues) {
227
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(jValues);
228
    }
226 229

  
227 230

  
228 231
}
src/main/c/Saxon.C.API/Xslt30Processor.cpp
7 7
#include "XdmNode.h"
8 8
#include "XdmAtomicValue.h"
9 9
#include "XdmFunctionItem.h"
10
#include "XdmMap.h"
11
#include "XdmArray.h"
10 12
#include "XsltExecutable.h"
11 13
#ifdef DEBUG
12 14
#include <typeinfo> //used for testing only
......
42 44
#endif
43 45

  
44 46
	if(cppXT == nullptr) {
45
	    exception = proc->checkAndCreateException(cppClass);
47
        createException();
46 48
	}
47 49

  
48 50
	if(!(proc->cwd.empty()) && curr.empty()){
......
143 145
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
144 146
            XdmValue * value = itr->second;
145 147
            if(value != nullptr) {
146
                value->decrementRefCount();
147 148
#ifdef DEBUG
148 149
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
149 150
#endif
150
                if (value->getRefCount() < 1) {
151 151
                    delete value;
152
                }
152

  
153 153
            }
154 154
        }
155 155

  
156
	} else {
157
        	for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
158

  
159
			parameters.erase(itr);
160
		
161
        	}
162

  
163 156
	}
164 157
	parameters.clear();
165 158
	
......
192 185
    return exception;
193 186
}
194 187

  
188
void Xslt30Processor::createException(const char * message) {
189

  
190
    if(exception != nullptr) {
191
        delete exception;
192
        SaxonProcessor::sxn_environ->env->ExceptionClear();
193
    }
194
    if(message == nullptr) {
195
        exception = proc->checkAndCreateException(cppClass);
196
    } else {
197
        exception = new SaxonApiException(message);
198
    }
199

  
200
}
201

  
195 202

  
196 203

  
197 204
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
......
204 211
	}
205 212
	if (!cAndSNodemID) {
206 213
		std::cerr<<"Error: "<<getDllname()<<"compileFromStringAndSave funtion not found"<<std::endl;
207

  
214
        SaxonProcessor::sxn_environ->env->ExceptionClear();
208 215
	} else {
209 216
        if(cppXT == nullptr) {
210 217
#if defined(DEBUG)
......
217 224
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
218 225
						node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
219 226
		
220
		exception = proc->checkAndCreateException(cppClass);
227
		createException();
221 228

  
222 229
    }
223 230

  
......
233 240
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
234 241
	}
235 242
	if (!cAndSStringmID) {
236
		exception = new SaxonApiException("Error: compileFromStringAndSave function not found\n");
243
        createException("Error: compileFromStringAndSave function not found\n");
237 244

  
238 245
	} else {
239 246
        if(cppXT == nullptr) {
......
248 255
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
249 256
						SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
250 257
		
251
		exception = proc->checkAndCreateException(cppClass);
258
		createException();
252 259

  
253 260
    }
254 261
}
......
264 271
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
265 272
	}
266 273
	if (!cAndFStringmID) {
267
		exception = new SaxonApiException("Error: compileFromFileAndSave function not found");
274
        createException("Error: compileFromFileAndSave function not found");
268 275

  
269 276
	} else {
270 277

  
......
278 285
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
279 286
						SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
280 287

  
281
		exception = proc->checkAndCreateException(cppClass);
288
        createException();
282 289

  
283 290

  
284 291
     }
......
293 300
	}
294 301
					
295 302
	if (cStringmID== nullptr) {
296
		exception = new SaxonApiException(strcat(getDllname(), ".compileFromString funtion not found"));
303
        createException(strcat(getDllname(), ".compileFromString funtion not found"));
297 304
		return nullptr;
298 305

  
299 306
	} else {
......
310 317
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
311 318
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
312 319
		if (!executableObject) {
313
			exception = proc->checkAndCreateException(cppClass);
320
            createException();
314 321
			return nullptr;
315 322
		}
316 323
		if (comboArrays.stringArray != nullptr) {
......
339 346

  
340 347
	} else {
341 348
	    if(node == nullptr) {
342
	        exception = new SaxonApiException("Error in compileFromXdmNode - node argument is NULL");
349
            createException("Error in compileFromXdmNode - node argument is NULL");
343 350
	        return nullptr;
344 351
	    }
345 352
        if(cppXT == nullptr) {
......
355 362
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
356 363
						node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
357 364
		if (!executableObject) {
358
			exception = proc->checkAndCreateException(cppClass);
365
			createException();
359 366
			return nullptr;
360 367
		}
361 368
		if (comboArrays.stringArray != nullptr) {
......
380 387
	if (!cFilemID) {
381 388
		std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
382 389
				<< " not found\n" << std::endl;
390
        SaxonProcessor::sxn_environ->env->ExceptionClear();
383 391
		return nullptr;
384 392

  
385 393
	} else {
386 394
		
387 395
		if(source == nullptr) {
388
			exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is NULL");
396
            createException("Error in compileFromFile method - The Stylesheet file is NULL");
389 397
			return nullptr;
390 398
		}
391 399
        if(cppXT == nullptr) {
......
401 409
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
402 410
						SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
403 411
		if (!executableObject) {
404
			exception = proc->checkAndCreateException(cppClass);
412
			createException();
405 413
     		return nullptr;
406 414
		}
407 415
		if (comboArrays.stringArray != nullptr) {
......
428 436
	if (!cFilemID) {
429 437
		std::cerr << "Error: "<<getDllname() << ".compileFromFile"
430 438
				<< " not found\n" << std::endl;
431
        std::cerr<<"cp0 -testCatalog"<<std::endl;
439
        SaxonProcessor::sxn_environ->env->ExceptionClear();
432 440
		return nullptr;
433 441

  
434 442
	} else {
435 443
        if (stylesheet == nullptr) {
436
            exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is nullptr");
444
            createException("The Stylesheet file is NULL");
437 445
            return nullptr;
438 446
        }
439 447
        if(cppXT == nullptr) {
......
454 462
                                                                           stylesheet), jitCompilation,
455 463
                                                                   comboArrays.stringArray, comboArrays.objectArray));
456 464
        if (!executableObject) {
457
            exception = proc->checkAndCreateException(cppClass);
465
            createException();
458 466
            return nullptr;
459 467

  
460 468
        }
......
482 490
	if(exceptionOccurred()) {
483 491
		//Possible error detected in the compile phase. Processor not in a clean state.
484 492
		//Require clearing exception.
493
		SaxonProcessor::sxn_environ->env->ExceptionDescribe();
494

  
485 495
		return nullptr;
486 496
	}
487 497

  
......
500 510
	}
501 511
	if (!mtvID) {
502 512
        std::cerr<<"Error: "<<getDllname()<<".transformtoValue function not found"<<std::endl;
503

  
513
        SaxonProcessor::sxn_environ->env->ExceptionClear();
504 514
	} else {
505 515
        if(cppXT == nullptr) {
506
#if defined(DEBUG)
516
//#if defined(DEBUG)
507 517
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
508
#endif
518
//#endif
509 519
            return nullptr;
510 520
        }
511 521
	    JParameters comboArrays;
512 522
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
513

  
523
        jstring jcwd = SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str());
524
        jstring jsourcefile = (sourcefile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr);
525
        jstring jstylesheetfile = (stylesheetfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetfile) : nullptr);
514 526
		jobject result = (jobject)(
515
				SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
516
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
517
						(sourcefile != nullptr ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr),
518
						(stylesheetfile != nullptr ?
519
								SaxonProcessor::sxn_environ->env->NewStringUTF(
520
										stylesheetfile) :
521
								nullptr), comboArrays.stringArray, comboArrays.objectArray));
527
				SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,jcwd, cppXT, nullptr, jsourcefile,
528
						                            jstylesheetfile, comboArrays.stringArray, comboArrays.objectArray));
522 529
		if (comboArrays.stringArray != nullptr) {
523 530
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
524 531
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
525 532
		}
533
        if (jcwd != nullptr) {
534
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(jcwd);
535
        }
536
        if (jsourcefile != nullptr) {
537
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(jsourcefile);
538
        }
539
        if (jstylesheetfile != nullptr) {
540
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(jstylesheetfile);
541
        }
526 542
		if (result) {
543

  
527 544
			jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
528 545
          		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
529 546
          		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
530
			XdmValue * value = nullptr;
547
                jclass mapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
548
                jclass arrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmArray");
549
			    XdmValue * value = nullptr;
531 550
          		XdmItem * xdmItem = nullptr;
532 551

  
533 552

  
534 553
          			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
535
          				xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
554
          				xdmItem = new XdmAtomicValue(result);
536 555
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
537 556
                        return xdmItem;
538 557

  
539 558
          			} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
540
          				xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
559
          				xdmItem = new XdmNode(result);
541 560
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
542 561
                        return xdmItem;
543
#if CVERSION_API_NO >= 123
562

  
544 563
          			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
545
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
564
                        xdmItem =  new XdmFunctionItem(result);
546 565
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
547 566
                        return xdmItem;
548
#endif
549
          			} else {
567

  
568
          			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, mapClass)           == JNI_TRUE) {
569
                        xdmItem =  new XdmMap(result);
570
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
571
                        return xdmItem;
572

  
573
                    } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, arrayClass)           == JNI_TRUE) {
574
                        xdmItem =  new XdmArray(result);
575
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
576
                        return xdmItem;
577

  
578
                    } else {
550 579
					value = new XdmValue(result, true);
551 580
					SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
552 581
					return value;
......
557 586
          		SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
558 587
          		return value;
559 588
		}else {
560
	
561
			exception = proc->checkAndCreateException(cppClass);
562
	   		
589

  
590
			createException();
591

  
563 592
     		}
564 593
	}
565 594
	return nullptr;
......
589 618
	}
590 619
	if (!mtfID) {
591 620
        std::cerr<<"Error: "<<getDllname()<<".transformToFile function not found"<<std::endl;
592

  
621
        SaxonProcessor::sxn_environ->env->ExceptionClear();
593 622
	} else {
594 623
        if(cppXT == nullptr) {
595 624
#if defined(DEBUG)
......
610 639
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
611 640
		}
612 641
		}
613
		exception = proc->checkAndCreateException(cppClass);
642
		createException();
614 643
	}
615 644

  
616 645

  
......
632 661
	if(mtsID == nullptr) {
633 662
			mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
634 663
					"transformToString",
635
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
664
					"(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
636 665
	}
637 666
	if (!mtsID) {
638 667
        std::cerr<<"Error: "<<getDllname()<<".transformFileToString not found"<<std::endl;
639

  
668
        SaxonProcessor::sxn_environ->env->ExceptionClear();
640 669
	} else {
641 670
        if(cppXT == nullptr) {
642 671
#if defined(DEBUG)
......
647 676
    JParameters comboArrays;
648 677
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
649 678

  
650
	jstring result = nullptr;
679
    jbyteArray result = nullptr;
651 680
	jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
652 681
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
653 682
						(source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
......
659 688
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
660 689
    }
661 690
	if(obj) {
662
			result = (jstring)obj;
691
			result = (jbyteArray)obj;
663 692
	}
664 693

  
665 694
	if (result) {
666
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
667
					nullptr);
668
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
669
			return str;
670
		} else  {
671
			exception =proc->checkAndCreateException(cppClass);
695
        jboolean isCopy = false;
696
        jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
697
        jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
698

  
699
        const char *str = new char[num_bytes];
700
        memcpy ((void *) str, b , num_bytes );
701

  
702
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
703
        return str;
704
	} else  {
705
	    createException();
672 706
	   		
673
     		}
707
	}
674 708
	}
675 709
	return nullptr;
676 710
}
src/main/c/Saxon.C.API/Xslt30Processor.h
314 314

  
315 315

  
316 316
private:
317

  
318
    void createException(const char * message=nullptr);
319

  
317 320
	SaxonProcessor* proc;/*! */
318 321
	jclass  cppClass;
319 322
	jobject cppXT;
src/main/c/Saxon.C.API/XsltExecutable.cpp
49 49
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
50 50
        selection = nullptr;
51 51
    }
52

  
53 52
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(executableObject);
54

  
53
    SaxonProcessor::sxn_environ->env->ExceptionClear(); // This is as a precaution to avoid crashing out if JNI gets into an unclean state.
55 54
}
56 55

  
57 56

  
......
97 96
    return SaxonProcessor::sxn_environ->env->ExceptionCheck();
98 97
}
99 98

  
100
const char *XsltExecutable::getErrorCode() {
101
    SaxonApiException *exception = SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass,
102
                                                                        nullptr);
103
    if (exception == nullptr) { return nullptr; }
104
    return exception->getErrorCode();
105
}
106

  
107 99

  
108 100
void XsltExecutable::setGlobalContextItem(XdmItem *value) {
109 101
    if (value != nullptr) {
......
158 150
                XdmValue *valuei = it->second;
159 151
                if(valuei != nullptr) {
160 152
                    valuei->decrementRefCount();
161
                    if (valuei->getRefCount() < 1) {
162
                        delete value;
163
                    }
164 153
                    parameters.erase(skey);
165 154
                    parameters[skey] = value;
166 155
                }
......
242 231

  
243 232
            XdmValue *value = itr->second;
244 233
            if(value != nullptr) {
245
                value->decrementRefCount();
246 234
#ifdef DEBUG
247 235
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
248 236
#endif
249
                if (value->getRefCount() < 1) {
250 237
                    delete value;
251
                }
252 238
            }
253 239
        }
254

  
255

  
256
    } else {
257
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
258
            parameters.erase(itr);
259
            /*if(value != NULL) {
260
                value->decrementRefCount();
261
            }*/
262

  
263
        }
264

  
265 240
    }
266 241
    parameters.clear();
267

  
268 242
}
269 243

  
270 244
void XsltExecutable::clearProperties() {
......
336 310
    if (!atmID) {
337 311
        std::cerr << "Error: " << getDllname() << ".applyTemplatesReturningFile" << " not found\n"
338 312
                  << std::endl;
339

  
313
        SaxonProcessor::sxn_environ->env->ExceptionClear();
340 314
    } else {
341 315
        JParameters comboArrays;
342 316
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
377 351
    if (!atsmID) {
378 352
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsString" << " not found\n"
379 353
                  << std::endl;
380

  
354
        SaxonProcessor::sxn_environ->env->ExceptionClear();
381 355
    } else {
382 356
        JParameters comboArrays;
383 357
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
431 405
    if (!atsvmID) {
432 406
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsValue" << " not found\n"
433 407
                  << std::endl;
434

  
408
        SaxonProcessor::sxn_environ->env->ExceptionClear();
435 409
    } else {
436 410
        JParameters comboArrays;
437 411
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
505 479
    if (!afmID) {
506 480
        std::cerr << "Error: " << getDllname() << "callFunctionReturningFile" << " not found\n"
507 481
                  << std::endl;
482
        SaxonProcessor::sxn_environ->env->ExceptionClear();
508 483
        return;
509 484
    } else {
510 485
        JParameters comboArrays;
......
553 528
    if (!afsmID) {
554 529
        std::cerr << "Error: " << getDllname() << "callFunctionReturningString" << " not found\n"
555 530
                  << std::endl;
556

  
531
        SaxonProcessor::sxn_environ->env->ExceptionClear();
557 532
    } else {
558 533
        JParameters comboArrays;
559 534
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
605 580
    if (!cfvmID) {
606 581
        std::cerr << "Error: " << getDllname() << "callFunctionReturningValue" << " not found\n"
607 582
                  << std::endl;
608

  
583
        SaxonProcessor::sxn_environ->env->ExceptionClear();
609 584
    } else {
610 585
        JParameters comboArrays;
611 586
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
682 657
    if (!ctmID) {
683 658
        std::cerr << "Error: " << getDllname() << "callTemplateReturningFile" << " not found\n"
684 659
                  << std::endl;
685

  
660
        SaxonProcessor::sxn_environ->env->ExceptionClear();
686 661
    } else {
687 662
        JParameters comboArrays;
688 663
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
721 696
    if (!ctsmID) {
722 697
        std::cerr << "Error: " << getDllname() << "callTemplateReturningString" << " not found\n"
723 698
                  << std::endl;
724

  
699
        SaxonProcessor::sxn_environ->env->ExceptionClear();
725 700
    } else {
726 701
        JParameters comboArrays;
727 702
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
774 749
    if (!ctsvmID) {
775 750
        std::cerr << "Error: " << getDllname() << "callTemplateReturningValue" << " not found\n"
776 751
                  << std::endl;
777

  
752
        SaxonProcessor::sxn_environ->env->ExceptionClear();
778 753
    } else {
779 754
        JParameters comboArrays;
780 755
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
853 828
    if (!tfvMID) {
854 829
        std::cerr << "Error: " << getDllname() << ".transformtoValue" << " not found\n"
855 830
                  << std::endl;
856

  
831
        SaxonProcessor::sxn_environ->env->ExceptionClear();
857 832
    } else {
858 833
        JParameters comboArrays;
859 834
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
936 911
    if (!tffMID) {
937 912
        std::cerr << "Error: " << getDllname() << "transformToFile" << " not found\n"
938 913
                  << std::endl;
939

  
914
        SaxonProcessor::sxn_environ->env->ExceptionClear();
940 915
    } else {
941 916
        JParameters comboArrays;
942 917
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
972 947
        if (!messageID) {
973 948
            std::cerr << "Error: "<<"SaxonCMessageListener" << " in " <<getDllname() << " not found\n"
974 949
                      << std::endl;
975

  
950
            SaxonProcessor::sxn_environ->env->ExceptionClear();
976 951
        }
977 952

  
978 953
        if (filename == nullptr) {
......
999 974
        if (!getmessageID) {
1000 975
            std::cerr << "Error: " << getDllname() << ".getXslMessages" << " not found\n"
1001 976
                      << std::endl;
1002

  
977
            SaxonProcessor::sxn_environ->env->ExceptionClear();
1003 978
        } else {
1004 979
            jobjectArray results = (jobjectArray) (
1005 980
                    SaxonProcessor::sxn_environ->env->CallObjectMethod(saxonMessageListenerObj, getmessageID));
......
1035 1010
    if (!tftMID) {
1036 1011
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1037 1012
                  << std::endl;
1038

  
1013
        SaxonProcessor::sxn_environ->env->ExceptionClear();
1039 1014
    } else {
1040 1015
        JParameters comboArrays;
1041 1016
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
1103 1078
    transformFileToFile(nullptr, nullptr);
1104 1079
}
1105 1080

  
1106
const char *XsltExecutable::getErrorMessage() {
1107
    SaxonApiException *exception = SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass,
1108
                                                                        nullptr);
1109
    if (exception == nullptr) { return nullptr; }
1110
    return exception->getMessage();
1111
}
1112

  
1113 1081

  
1114 1082
SaxonApiException *XsltExecutable::getException() {
1115 1083
    return SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
src/main/c/Saxon.C.API/XsltExecutable.h
434 434
     //! Clear any exception thrown
435 435
    void exceptionClear();
436 436

  
437
     //!Get number of errors reported during execution or evaluate of stylesheet
438
    /**
439
     * A transformation may have a number of errors reported against it.
440
     * @return int - Count of the exceptions recorded against the transformation
441
    */
442
    //int exceptionCount();
443

  
444
     //! Get the ith error message if there are any error
445
    /**
446
     * A transformation may have a number of errors reported against it.
447
     * @return char* - The message of the i'th exception
448
    */
449
    const char * getErrorMessage();
450

  
451
     //! Get the ith error code if there are any error
452
    /**
453
     * A transformation may have a number of errors reported against it.
454
     * @return char* - The error code of the i'th exception. The error code are related to the specific specification
455
    */
456
    const char * getErrorCode();
457

  
458

  
459 437

  
460 438

  
461 439
private:
src/main/c/Saxon.C.API/XsltProcessor.cpp
249 249
	 proc->exception = proc->checkForException(environi, cpp);
250 250
	 }
251 251
	 return proc->exception;*/
252
	return proc->checkException(cppXT);
252
	return proc->checkException();
253 253
}
254 254

  
255 255

  
src/main/c/samples/cppTests/testXSLT30.cpp
31 31
*/
32 32
void testApplyTemplatesString1(Xslt30Processor *trans, sResultCount *sresult) {
33 33

  
34
    cout << endl << "Test: testApplyTemplatesString1:" << endl;
34
    cout << "Test: testApplyTemplatesString1:" << endl;
35 35
//    trans->setupXslMessage(false);
36 36

  
37 37
    XsltExecutable *executable = trans->compileFromFile("test.xsl");
......
100 100
        if (output == nullptr) {
101 101
            SaxonProcessor::sxn_environ->env->ExceptionDescribe();
102 102
            printf("result is null ====== FAIL ======  \n");
103
            sresult->failure++;
103 104
            sresult->failureList.push_back("testTransformToStringExnteionFunc");
104 105
        } else {
105 106
            sresult->success++;
......
109 110
        delete output;
110 111
    } else {
111 112
        printf("native Class not foun ====== FAIL ====== ");
113
        sresult->failure++;
112 114
        sresult->failureList.push_back("testTransformToStringExtensionFunc");
113 115
    }
114 116
    delete executable;
......
120 122
*/
121 123
void testApplyTemplatesString2(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
122 124

  
123
    cout << endl << "Test: testApplyTemplatesString2:" << endl;
124
    trans->clearParameters();
125
    cout << "Test: testApplyTemplatesString2:" << endl;
126

  
125 127

  
126 128
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
127 129

  
128 130
    if (input== nullptr) {
129 131
        cout << "Source document is null." << endl;
132
        if(processor->exceptionOccurred()) {
133
            cerr<<processor->getErrorMessage()<<endl;
134
        }
130 135
        sresult->failure++;
131 136
        sresult->failureList.push_back("testApplyTemplatesString2");
132 137
        return;
......
144 149
    }
145 150

  
146 151
    executable->setInitialMatchSelection((XdmValue *) input);
152

  
147 153
    const char *output = executable->applyTemplatesReturningString();
148 154
    if (output== nullptr) {
149 155
        printf("result is null ====== FAIL ======  \n");
150 156
        sresult->failureList.push_back("testApplyTemplatesString2");
157
        sresult->failure++;
151 158
    } else {
152 159
        sresult->success++;
153 160
        printf("%s", output);
......
155 162
        delete output;
156 163
    }
157 164
    fflush(stdout);
165
    delete input;
158 166
    delete executable;
159 167
}
160 168

  
......
162 170
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
163 171
Should be error. Stylesheet file does not exist
164 172
*/
165
void testApplyTemplates2a(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
173
void testApplyTemplates2a_Error(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
174

  
175
    cout << "Test: TransformToString2a_Error:" << endl;
166 176

  
167
    cout << endl << "Test: TransformToString2a:" << endl;
168
    trans->clearParameters();
169 177
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
170 178

  
171 179
    if (input == nullptr) {
172 180
        cout << "Source document is null. ====== FAIL ======" << endl;
181
        if(processor->exceptionOccurred()) {
182
            cerr<<processor->getErrorMessage()<<endl;
183
        }
173 184
        sresult->failure++;
174
        sresult->failureList.push_back("testApplyTemplates2a");
185
        sresult->failureList.push_back("testApplyTemplates2a_Error");
186
        trans->exceptionClear();
175 187
        return;
176 188
    }
177 189
    XsltExecutable * executable = trans->compileFromFile("test-error.xsl");
178 190

  
179 191
    if(executable== nullptr) {
180
        printf("result is null \n");
192
        printf("Expected result is null \n");
181 193
        sresult->success++;
182 194

  
183 195
        if (trans->exceptionOccurred()) {
184
            cerr <<"testApplyTemplates2a error: "<< trans->getErrorMessage() << endl;
196
            cerr <<"testApplyTemplates2a_Error error: "<< trans->getErrorMessage() << endl;
185 197
        }
186 198
        delete input;
187
        cerr<< "testApplyTemplates2a - cp0"<<endl;
188
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
199
        trans->exceptionClear();
189 200
        return;
190 201
    }
191 202

  
192

  
193 203
    sresult->failure++;
194
    cout << endl << "cpp1" << endl;
195
    sresult->failureList.push_back("testApplyTemplates2a");
204
    sresult->failureList.push_back("testApplyTemplates2a_Error");
196 205
    fflush(stdout);
206

  
197 207
    delete executable;
198 208

  
199 209
}
......
205 215
void testTransformToString2b(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
206 216

  
207 217
    cout << endl << "Test: TransformToString2b:" << endl;
208
    trans->clearParameters();
209 218

  
210 219
    const char * result  = trans->transformFileToString("cat-error.xml", "test-error.xsl");
211 220

  
212 221
    if(result== nullptr) {
222
        if(trans->exceptionOccurred()) {
223
            cerr<<"Expected failure = "<<trans->getErrorMessage()<<endl;
224
        }
213 225
        sresult->success++;
226
        trans->exceptionClear();
214 227
        return;
215 228
    }else {
216 229
        delete result;
......
218 231
        sresult->failureList.push_back("testTransformToString2b");
219 232
        cerr << "testTransformToString2b NULL found" << endl;
220 233
        if (trans->exceptionOccurred()) {
221
            cerr <<"testTransformToString2b error: "<< trans->getErrorMessage() << endl;
234
            cerr <<"Error: "<< trans->getErrorMessage() << endl;
222 235
        }
223 236
        trans->exceptionClear();
224 237
        return;
......
234 247
*/
235 248
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
236 249

  
237
    cout << endl << "Test: TransformToString3: param size=" << trans->getParameters().size() << endl;
238
    trans->clearParameters();
250
    cout << endl << "Test: TransformToString3" << endl;
239 251

  
240 252
    XdmNode *inputi = processor->parseXmlFromString(
241 253
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
242 254

  
243 255
    if (inputi== nullptr) {
244
        cout << "Source document inputi is null. ====== FAIL ====== " << endl;
256
        cout << "Source document inputi is null." << endl;
257
        if (trans->exceptionOccurred()) {
258
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
259
        }
260
        sresult->failure++;
245 261
        sresult->failureList.push_back("testTransformToString3");
246 262

  
247 263
        return;
......
249 265

  
250 266
    XdmAtomicValue *value1 = processor->makeIntegerValue(10);
251 267

  
252

  
268
    if (value1== nullptr) {
269
        cout << "value1 is null." << endl;
270
        if (trans->exceptionOccurred()) {
271
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
272
        }
273
        sresult->failure++;
274
        sresult->failureList.push_back("testTransformToString3");
275
        delete inputi;
276
        return;
277
    }
253 278

  
254 279
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
255 280

  
......
265 290
    }
266 291

  
267 292

  
268

  
269
    trans->setParameter("numParam", (XdmValue *) value1);
270

  
271
    cerr << "testTransformToString3  test test " << endl;
293
    executable->setParameter("numParam", (XdmValue *) value1);
272 294

  
273 295
    executable->setInitialMatchSelection((XdmNode *) inputi);
274 296
    const char *output = executable->applyTemplatesReturningString();
......
282 304
    }
283 305
    fflush(stdout);
284 306

  
285
    cout<<"value 1 object ref="<<(value1)<<endl;
286 307
    delete value1;
308
    delete inputi;
287 309
    delete executable;
288 310

  
289 311
}
......
294 316
*/
295 317
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
296 318

  
297
    cout << endl << "Test: testTransformToString4:" << endl;
298
    cout << endl << "cpp0-1" << endl;
299
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
300

  
301
    trans->clearParameters();
302
    cout << endl << "cpp0-2" << endl;
303
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
319
    cout <<  "Test: testTransformToString4:" << endl;
304 320

  
305 321
    XdmNode *input = processor->parseXmlFromString(
306 322
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
307 323

  
308 324
    if (input== nullptr) {
309
        sresult->failure++;
310 325
        cout << "Source document is null. ====== FAIL ====== " << endl;
326
        sresult->failure++;
311 327
        sresult->failureList.push_back("testTransformToString4");
312 328
    }
313 329

  
314 330

  
315 331
    XdmValue *values = new XdmValue();
316
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(10));
317
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(5));
318
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(6));
319
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(7));
332
    XdmAtomicValue * a1 = processor->makeIntegerValue(10);
333
    XdmAtomicValue * a2 = processor->makeIntegerValue(5);
334
    XdmAtomicValue * a3 = processor->makeIntegerValue(6);
335
    XdmAtomicValue * a4 = processor->makeIntegerValue(7);
336
    values->addXdmItem(a1);
337
    values->addXdmItem(a2);
338
    values->addXdmItem(a3);
339
    values->addXdmItem(a4);
320 340

  
321
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
322 341

  
323
   /* XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
342
    XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
324 343

  
325 344
    XsltExecutable *executable = trans->compileFromXdmNode(sheet);
326 345

  
......
340 359
    const char *output = executable->applyTemplatesReturningString();
341 360
    if (output== nullptr) {
342 361
        printf("result is null \n");
362
        sresult->failure++;
343 363
        sresult->failureList.push_back("testTransformToString4");
344 364
    } else {
345 365
        printf("%s", output);
......
348 368
    }
349 369
    fflush(stdout);
350 370
    delete sheet;
351
    delete executable;*/
371
    delete executable;
352 372
    delete input;
353 373
    delete values;
354 374

  
355 375
}
356 376

  
357 377
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
358
    cout << endl << "Test: testTransfromFromstring: param size="<< trans->getParameters().size() << endl;
359
    trans->clearParameters();
378
    cout << endl << "Test: testTransfromFromstring: "<< endl;
379

  
360 380
    if(processor == nullptr) {
361 381
        cout<<" processor is null"<<endl;
362 382
        return;
......
389 409
        return;
390 410
    }
391 411

  
392
    cout<<" checkpoint 00"<<endl;
393

  
394 412
    const char *output = executable->transformToString((XdmNode *) input);
395 413
    if (output== nullptr) {
396 414
        printf("result is null ====== FAIL ====== \n");
415
        sresult->failure++;
397 416
        sresult->failureList.push_back("testTransformFromString");
398 417
        if (trans->exceptionOccurred()) {
399 418
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
......
401 420
    } else {
402 421
        printf("%s", output);
403 422
        printf("result is OK \n");
423
        sresult->success++;
404 424
        delete output;
405 425
    }
406 426
    fflush(stdout);
407

  
408 427
    delete input;
409 428
    delete executable;
410 429

  
......
414 433
//Test case has error in the stylesheet
415 434
void testTransformFromstring2Err(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
416 435
    cout << endl << "Test: testTransfromFromstring2-Error:" << endl;
417
    trans->clearParameters();
418

  
419
    XdmNode *input = processor->parseXmlFromString(
420
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
421 436

  
422 437
    XsltExecutable * executable = trans->compileFromString(
423 438
            "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='2.0'>       <xsl:param name='values' select='(2,3,4)' /><xsl:output method='xml' indent='yes' /><xsl:template match='*'><output><xsl:for-each select='$values' ><out><xsl:value-of select='. * 3'/></out><xsl:for-each></output></xsl:template><xsl:stylesheet>");
424 439

  
425 440
    if(executable== nullptr) {
426
        sresult->failure++;
427
        sresult->failureList.push_back("testTransformFromstring2Err");
428
        cerr << "testTransformFromstring2Err NULL found" << endl;
441
        sresult->success++;
442

  
429 443
        if (trans->exceptionOccurred()) {
430
            cerr <<"testTransformFromstring2Err error: "<< trans->getErrorMessage() << endl;
444
            cerr <<"Error expected: "<< trans->getErrorMessage() << endl;
431 445
        }
432 446
        return;
433 447
    }
434 448

  
435
    executable->setInitialMatchSelection((XdmValue *) input);
436
    const char *output = executable->applyTemplatesReturningString();
437
    if (output== nullptr) {
438
        printf("result is null ====== FAIL ======  \n\nCheck For errors:\n");
439
        sresult->failureList.push_back("testTransformFromstring2Err");
440
        if (executable->exceptionOccurred()) {
441
            cout << "Error message=" << executable->getErrorMessage() << endl;
442
        }
443
    } else {
444
        printf("%s", output);
445
        printf("result is OK \n");
446
    }
447
    fflush(stdout);
448
    delete output;
449 449

  
450
    trans->exceptionClear();
451
    delete input;
450
    sresult->failure++;
451
    sresult->failureList.push_back("testTransfromFromstring2-Error");
452 452
    delete executable;
453 453

  
454 454
}
455 455

  
456 456
void testTrackingOfValueReference(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
457
    trans->clearParameters();
458 457

  
459 458
    cout << endl << "Test: TrackingOfValueReference:" << endl;
460 459
    ostringstream test;
......
472 471
        test.str("");
473 472
        valStr.str("");
474 473
        name.str("");
474

  
475
        if(values == nullptr) {
476
            cerr<<"TrackingOfValueReference failed to create XdmNode object" <<endl;
477
            sresult->failure++;
478
            sresult->failureList.push_back("TrackingOfValueReference");
479

  
480
        }
475 481
    }
476 482

  
477 483
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
......
480 486
        //cout << "Parameter size: " << parMap.size()<< endl;//", Value:"<<trans->getParameters()["value0"]->getHead()->getStringValue()<<endl;
481 487
        ostringstream name1;
482 488
        for (int i = 0; i < 10; i++) {
483
            name1 << "param:value" << i;
489
            name1 << "sparam:value" << i;
484 490
            cout << " i:" << i << " Map size:" << parMap.size() << ", ";
485 491
            XdmValue *valuei = parMap[name1.str()];
486
            if (valuei != NULL) {
492
            if (valuei != nullptr) {
487 493
                cout << name1.str();
488
                if (valuei->itemAt(0) != NULL)
494
                if (valuei->itemAt(0) != nullptr)
489 495
                    cout << "= " << valuei->itemAt(0)->getStringValue();
490 496
                cout << endl;
497

  
491 498
            } else {
492 499
                sresult->failure++;
493 500
                std::cerr << "trackingValueReference ====== FAIL ======" << std::endl;
......
497 504
            name1.str("");
498 505
        }
499 506
    }
507
    if(parMap.size() > 0 ) {
508
        cerr<<"Deleting map"<<endl;
509
        trans->clearParameters(true);
510
    }
500 511
    sresult->success++;
501 512
}
502 513

  
......
509 520
    ostringstream test;
510 521
    ostringstream valStr;
511 522
    ostringstream name;
512
    for (int i = 0; i < 10; i++) {
523
    for (int i = 0; i < 2; i++) {
513 524
        test << "v" << i;
514 525
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
515 526
               << "<value></out>";
516 527
        name << "value" << i;
517 528

  
518 529
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
519
        trans->setParameter(name.str().c_str(), values);
530
        if(values == nullptr) {
531
            cerr<<"values NULL ====== FAIL ======="<<endl;
532
        } else {
533
            trans->setParameter(name.str().c_str(), values);
534
        }
520 535
        test.str("");
521 536
        valStr.str("");
522 537
        name.str("");
......
526 541

  
527 542
    ostringstream name1;
528 543
    bool errorFound = false;
529
    for (int i = 0; i < 10; i++) {
530
        name1 << "param:value" << i;
544
    for (int i = 0; i < 2; i++) {
545
        name1 << "sparam:value" << i;
531 546
        cout << " i:" << i << " Map size:" << parMap.size() << ", ";
532 547
        try {
533 548
            XdmValue *valuei = parMap.at(name1.str());
......
579 594

  
580 595

  
581 596
void testXdmNodeOutput(Xslt30Processor *trans, sResultCount *sresult) {
582
    trans->clearParameters();
583

  
584 597

  
585 598
    std::cout << "testXdmNodeOutput" << std::endl;
586 599
    XsltExecutable * executable = trans->compileFromString(
......
598 611
        cout << "Result is null ====== FAIL ====== " << endl;
599 612
        sresult->failure++;
600 613
        sresult->failureList.push_back("testXdmNodeOutput-0");
614
        delete rootValue;
615
        delete executable;
601 616
        return;
602 617
    }
603 618
    XdmNode *root = (XdmNode *) rootItem;
......
609 624
    const char *result = executable->callTemplateReturningString("go");
610 625
    if (string(result).find(string("<a/>")) != std::string::npos) {
611 626
        sresult->success++;
627
        delete result;
612 628
    } else {
613 629
        //TODO - this test case prints the XML declaration. Check if this correct
614 630
        sresult->failure++;
615 631
        cout << "testXdmNodeOutputAndString ======= FAIL========" << endl;
616 632
        sresult->failureList.push_back("testXdmNodeOutput");
617 633
    }
634
    delete rootValue;
618 635
    delete executable;
619
    delete result;
620 636

  
621 637
}
622 638

  
......
645 661
    }
646 662
    proc->clearParameters();
647 663
    delete executable;
648

  
649 664
}
650 665

  
651 666
void exampleSimple1Err(Xslt30Processor *proc, sResultCount *sresult) {
......
657 672
            cout << "Error Message= "<< proc->getErrorMessage() << endl;
658 673
        }
659 674
        cout << "Result expected as null " << endl;
675
        proc->exceptionClear();
660 676
        sresult->success++;
661 677
        return;
662 678
    } else {
......
665 681

  
666 682
        delete executable;
667 683
    }
668
    proc->clearParameters();
669 684

  
670 685
}
671 686

  
......
702 717
        sresult->failure++;
703 718
        sresult->failureList.push_back("exampleSimple2");
704 719
    }
705
    proc->clearParameters();
706
    executable->clearParameters();
720

  
707 721
    delete executable;
708 722

  
709 723
}
......
712 726
    cout << "<b>exampleSimple3:</b><br/>" << endl;
713 727
    proc->clearParameters();
714 728

  
729
    XdmNode *xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
730
    if (xdmNode== nullptr) {
731
        cout << "Error: xdmNode is null'" << endl;
732
        if(saxonProc->exceptionOccurred()) {
733
            cout<<"Error message="<<saxonProc->getErrorMessage()<<endl;
734
        }
735
        sresult->failure++;
736
        sresult->failureList.push_back("exampleSimple3");
737
        return;
738
    }
739

  
715 740
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
716 741

  
717 742
   if(executable == nullptr) {
......
720 745
		cout << proc->getErrorMessage() <<endl;
721 746
		
722 747
	}
723

  
748
	sresult->failure++;
749
	sresult->failureList.push_back("exampleSimple3");
724 750
	return;
725

  
726 751
   }
727 752

  
728
    XdmNode *xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
729
    if (xdmNode== nullptr) {
730
        cout << "Error: xdmNode is null'" << endl;
731
        sresult->failure++;
732
        sresult->failureList.push_back("exampleSimple3");
733
        return;
734
    }
735 753
    executable->setInitialMatchSelection((XdmNode *) xdmNode);
736
    cout << "end of exampleSimple3" << endl;
737
    executable->clearParameters();
738

  
739 754
    sresult->success++;
755
    delete xdmNode;
740 756
    delete executable;
741

  
742
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
743

  
744 757
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff