Project

Profile

Help

Revision 5401a5ae

Added by O'Neil Delpratt almost 2 years ago

Saxon/C Development

View differences:

latest9.9/hec/Saxon.C.API/Xslt30Processor.cpp
6 6
#include "XdmItem.h"
7 7
#include "XdmNode.h"
8 8
#include "XdmAtomicValue.h"
9
#include "XdmFunctionItem.h"
9 10
#ifdef DEBUG
10 11
#include <typeinfo> //used for testing only
11 12
#endif
......
37 38
#endif
38 39
	tunnel = false;
39 40
	jitCompilation = false;
40
	proc->exception = NULL;
41
	selection = NULL;
42
	selectionV=NULL;
41
	exception = NULL;
43 42

  
44 43
	if(!(proc->cwd.empty()) && curr.empty()){
45 44
		cwdXT = proc->cwd;
......
48 47
	}
49 48
}
50 49

  
51
     Xslt30Processor::~Xslt30Processor(){
52
	clearProperties();
53
	clearParameters();
54
	if(selectionV != NULL) {
55
	  selectionV->decrementRefCount();
56
	  if(selectionV->getRefCount() == 0) {
57
		delete selectionV;
58
	  }
59
	}
60
	
61
     }
50
    Xslt30Processor::~Xslt30Processor(){
51
	    clearParameters();
52
	    SaxonProcessor::sxn_environ->env->DeleteLocalRef(cppXT);
53
	    cwdXT.erase();
54
    }
62 55

  
63 56

  
64 57
Xslt30Processor::Xslt30Processor(const Xslt30Processor &other) {
65 58
	proc = other.proc;
66 59
	cppClass = other.cppClass;
67 60
	cppXT = other.cppXT;
68
	stylesheetObject = other.stylesheetObject;
69
	selectionV = other.selectionV;
70
	if(selectionV != NULL) {
71
	    setInitialMatchSelection(other.selectionV);
72
	} else {
73
	    selection = other.selection;
74
	}
75 61
    cwdXT = other.cwdXT;
76 62
	tunnel = other.tunnel;
77 63

  
......
81 67

  
82 68
       XdmValue * valuei = paramIter->second;
83 69
       if(valuei == NULL) {
84
    	 	cerr<<"Error in Xslt30Processor copy constructor"<<endl;
70
    	 	//std::cerr<<"Error in Xslt30Processor copy constructor"<<std::endl;
85 71
       } else {
86 72
            parameters[paramIter->first] = new XdmValue(*(valuei));
87 73
       }
......
109 95
	return proc->exceptionOccurred();
110 96
}
111 97

  
112
const char * Xslt30Processor::getErrorCode(int i) {
113
 if(proc->exception == NULL) {return NULL;}
114
 return proc->exception->getErrorCode(i);
98
const char * Xslt30Processor::getErrorCode() {
99
 if(exception == NULL) {return NULL;}
100
 return exception->getErrorCode();
115 101
 }
116 102

  
117 103

  
......
119 105
	if(value != NULL && name != NULL){
120 106
		value->incrementRefCount();
121 107
		int s = parameters.size();
122
		std::String skey = ("sparam:"+std::string(name));
108
		std::string skey = ("sparam:"+std::string(name));
123 109
		parameters[skey] = value;
124 110
		if(s == parameters.size()) {
125 111
            std::map<std::string, XdmValue*>::iterator it;
......
167 153
	        		delete value;
168 154
			}
169 155
        	}
170
				
171
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(selection);
172
		selection = NULL;
156

  
173 157
	} else {
174 158
for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
175 159
		
......
178 162
		
179 163
        	}
180 164

  
181
	selection = NULL;
182 165
	}
183 166
	parameters.clear();
184 167

  
......
194 177

  
195 178

  
196 179
void Xslt30Processor::exceptionClear(){
197
 if(proc->exception != NULL) {
198
 	delete proc->exception;
199
 	proc->exception = NULL;
180
 if(exception != NULL) {
181
 	delete exception;
182
 	exception = NULL;
200 183
	SaxonProcessor::sxn_environ->env->ExceptionClear();
201 184
 }
202 185
  
......
216 199
	return proc->checkException(cppXT);
217 200
}
218 201

  
219
int Xslt30Processor::exceptionCount(){
220
 if(proc->exception != NULL){
221
 return proc->exception->count();
222
 }
223
 return 0;
224
 }
225 202

  
226 203

  
227
    void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
204
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
228 205
	static jmethodID cAndSNodemID = NULL;
229 206

  
230 207
	if(cAndSNodemID == NULL) {
......
243 220
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
244 221
						node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
245 222
		
246
		proc->checkAndCreateException(cppClass);		
223
		exception = proc->checkAndCreateException(cppClass);
247 224

  
248 225
    }
249 226

  
......
270 247
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
271 248
						SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
272 249
		
273
		proc->checkAndCreateException(cppClass);		
250
		exception = proc->checkAndCreateException(cppClass);
274 251

  
275 252
    }
276 253
}
......
295 272
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
296 273
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
297 274
						SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
298
		
299
		proc->checkAndCreateException(cppClass);
275

  
276
		exception = proc->checkAndCreateException(cppClass);
300 277

  
301 278

  
302 279
     }
303 280
}
304 281

  
305
void Xslt30Processor::compileFromString(const char* stylesheetStr) {
282
XsltExecutable * Xslt30Processor::compileFromString(const char* stylesheetStr) {
306 283
	static jmethodID cStringmID = NULL;
307 284
	if (cStringmID == NULL) {
308 285
			cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
......
316 293
		return NULL;
317 294

  
318 295
	} else {
319
		
320
		std::map<std::string,std::string> properties;
321 296

  
322 297
		JParameters comboArrays;
323
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
298
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
324 299
		jobject executableObject = (jobject)(
325 300
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
326 301
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
327 302
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
328 303
		if (!executableObject) {
329
			proc->checkAndCreateException(cppClass);
304
			exception = proc->checkAndCreateException(cppClass);
330 305
			return NULL;
331 306
		}
332 307
		if (comboArrays.stringArray != NULL) {
333 308
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
334 309
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
335 310
		}
336
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
337
		return new XsltExecutable(executableObject);
311

  
312
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
313
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
314
		return executable;
338 315
	}
339 316

  
340 317
}
341 318

  
342
void Xslt30Processor::compileFromXdmNode(XdmNode * node) {
319
XsltExecutable * Xslt30Processor::compileFromXdmNode(XdmNode * node) {
343 320
	static jmethodID cNodemID = NULL;
344 321
    if(cNodemID == NULL) {			
345 322
			cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
......
352 329

  
353 330
	} else {
354 331
		JParameters comboArrays;
355
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
332
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
356 333
		jobject executableObject = (jobject)(
357 334
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
358 335
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
......
365 342
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
366 343
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
367 344
		}
368
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
369
        return new XsltExecutable(executableObject);
345

  
346
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
347
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
348
		return executable;
370 349
	}
371 350

  
372 351
}
373 352

  
374
void Xslt30Processor::compileFromAssociatedFile(const char* source) {
353
XsltExecutable * Xslt30Processor::compileFromAssociatedFile(const char* source) {
375 354
	static jmethodID cFilemID = NULL;
376 355
    if(cFilemID == NULL) {	
377 356
	    cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
......
390 369
			return;
391 370
		}
392 371
		JParameters comboArrays;
393
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
372
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
394 373
		jobject executableObject = (jobject)(
395 374
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
396 375
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
......
403 382
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
404 383
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
405 384
		}
406
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
407
		return new XsltExecutable(executableObject);
385

  
386
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
387
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
388
		return executable;
408 389
	}
409 390

  
410 391
}
411 392

  
412 393

  
413
void Xslt30Processor::compileFromFile(const char* stylesheet) {
394
XsltExecutable * Xslt30Processor::compileFromFile(const char* stylesheet) {
414 395
	static jmethodID cFilemID = NULL;
415 396
	if(cFilemID == NULL) {
416 397
	    cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
......
429 410
			return;
430 411
		}
431 412
		JParameters comboArrays;
432
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
433
		jobject excutableObject = (jobject)(
413
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
414
		jobject executableObject = (jobject)(
434 415
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
435 416
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
436 417
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
......
443 424
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
444 425
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
445 426
		}
446
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
447
		return new XsltExecutable(executableObject);
427

  
428
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
429
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
430
		return executable;
448 431
	}
449 432

  
450 433
}
......
461 444
		return NULL;	
462 445
	}
463 446

  
464
	if(sourcefile == NULL && stylesheetfile == NULL && !stylesheetObject){
447
	if(sourcefile == NULL && stylesheetfile == NULL){
465 448
	
466 449
		return NULL;
467 450
	}
......
480 463

  
481 464
	} else {
482 465
	    JParameters comboArrays;
483
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
466
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
484 467

  
485 468
		jobject result = (jobject)(
486 469
				SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
......
503 486

  
504 487

  
505 488
          			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
506
          				xdmItem = new XdmAtomicValue(result);
489
          				xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
507 490
                        xdmItem->setProcessor(proc);
508 491
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
509 492
                        return xdmItem;
510 493

  
511 494
          			} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
512
          				xdmItem = new XdmNode(result);
495
          				xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
513 496
                        xdmItem->setProcessor(proc);
514 497
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
515 498
                        return xdmItem;
516

  
499
#if CVERSION_API_NO >= 123
517 500
          			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
518
                        xdmItem =  new XdmFunctionItem(result);
501
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
519 502
                        xdmItem->setProcessor(proc);
520 503
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
521 504
                        return xdmItem;
505
#endif
522 506
          			} else {
523 507
					value = new XdmValue(result, true);
524 508
					value->setProcessor(proc);
525 509
					for(int z=0;z<value->size();z++) {
526 510
						value->itemAt(z)->setProcessor(proc);
527 511
					}
512
					SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
528 513
					return value;
529 514
				}
530 515
				value = new XdmValue();
......
535 520
          		return value;
536 521
		}else {
537 522
	
538
			proc->checkAndCreateException(cppClass);
523
			exception = proc->checkAndCreateException(cppClass);
539 524
	   		
540 525
     		}
541 526
	}
......
552 537
		//Require clearing exception.
553 538
		return;	
554 539
	}
555
	if(!stylesheetObject && stylesheet==NULL){
556
		std::cerr<< "Error: stylesheet has not been set or created using the compile methods."<<std::endl;
540
	if(stylesheet==NULL){
541
		std::cerr<< "Error: stylesheet has not been set."<<std::endl;
557 542
		return;
558 543
	}
559
	setProperty("resources", proc->getResourcesDirectory());
544
	//setProperty("resources", proc->getResourcesDirectory());
560 545
	static jmethodID mtfID = NULL;
561 546

  
562 547
	if(mtfID == NULL) {
......
570 555

  
571 556
	} else {
572 557
	    JParameters comboArrays;
573
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
558
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
574 559

  
575 560
		SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
576 561
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
......
582 567
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
583 568
		}
584 569
		}
585
		proc->checkAndCreateException(cppClass);
570
		exception = proc->checkAndCreateException(cppClass);
586 571
	}
587 572

  
588 573

  
......
594 579
		//Require clearing exception.
595 580
		return NULL;	
596 581
	}
597
	if(source == NULL && stylesheet == NULL && !stylesheetObject){
598
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling transformFileToString or check exceptions"<<std::endl;
582
	if(source == NULL && stylesheet == NULL){
583
		std::cerr<< "Error: NULL file name found in transformFiletoString."<<std::endl;
599 584
		return NULL;
600 585
	}
601 586
	setProperty("resources", proc->getResourcesDirectory());
......
612 597

  
613 598
	} else {
614 599
    JParameters comboArrays;
615
    comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
600
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
616 601

  
617 602
	jstring result = NULL;
618 603
	jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
......
635 620
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
636 621
			return str;
637 622
		} else  {
638
			proc->checkAndCreateException(cppClass);  
623
			exception =proc->checkAndCreateException(cppClass);
639 624
	   		
640 625
     		}
641 626
	}
......
644 629

  
645 630

  
646 631

  
647
const char * Xslt30Processor::getErrorMessage(int i ){
648
 	if(proc->exception == NULL) {return NULL;}
649
 	return proc->exception->getErrorMessage(i);
632
const char * Xslt30Processor::getErrorMessage(){
633
 	if(exception == NULL) {return NULL;}
634
 	return exception->getErrorMessage();
650 635
 }
651 636

  

Also available in: Unified diff