Project

Profile

Help

Revision 1117bc69

Added by O'Neil Delpratt almost 2 years ago

Saxon/C Development - Multithreading feature

View differences:

latest9.9/hec/Saxon.C.API/Xslt30Processor.cpp
115 115
 }
116 116

  
117 117

  
118

  
119
void Xslt30Processor::setGlobalContextItem(XdmItem * value){
120
    if(value != NULL){
121
      value->incrementRefCount();
122
      parameters["node"] = value;
123
    }
124
}
125

  
126
void Xslt30Processor::setGlobalContextFromFile(const char * ifile) {
127
	if(ifile != NULL) {
128
		setProperty("s", ifile);
129
	}
130
}
131

  
132
void Xslt30Processor::setInitialMatchSelection(XdmValue * _selection){
133
     if(_selection != NULL) {
134
      _selection->incrementRefCount();
135
      selectionV = _selection;
136
      selection = _selection->getUnderlyingValue();
137
    }
138
}
139

  
140

  
141
void Xslt30Processor::setInitialMatchSelectionAsFile(const char * filename){
142
    if(filename != NULL) {
143
      selection = SaxonProcessor::sxn_environ->env->NewStringUTF(filename);
144
    }
145
}
146

  
147
void Xslt30Processor::setOutputFile(const char * ofile) {
148
	setProperty("o", ofile);
149
}
150

  
151
void Xslt30Processor::setBaseOutputURI(const char * baseURI) {
152
	if(baseURI != NULL) {
153
  	    setProperty("baseoutput", baseURI);
154
	}
155
}
156

  
157

  
158
void Xslt30Processor::setParameter(const char* name, XdmValue * value, bool _static) {
118
void Xslt30Processor::setParameter(const char* name, XdmValue * value) {
159 119
	if(value != NULL && name != NULL){
160 120
		value->incrementRefCount();
161
		int s = parameter.size();
162
		std::String skey = (_static ? "sparam:"+std::string(name) : "param:"+std::string(name));
121
		int s = parameters.size();
122
		std::String skey = ("sparam:"+std::string(name));
163 123
		parameters[skey] = value;
164
		if(s == parameter.size()) {
124
		if(s == parameters.size()) {
165 125
            std::map<std::string, XdmValue*>::iterator it;
166 126
            it = parameters.find(skey);
167 127
            if (it != parameters.end()) {
......
177 137
	 }
178 138
}
179 139

  
180
    void Xslt30Processor::setInitialTemplateParameters(std::map<std::string,XdmValue*> _itparameters, bool _tunnel){
181
	for(std::map<std::string, XdmValue*>::iterator itr = _itparameters.begin(); itr != _itparameters.end(); itr++){
182
		parameters["itparam:"+std::string(itr->first)] = itr->second;	
183
	}
184
	tunnel = _tunnel;
185
	if(tunnel) {
186
		setProperty("tunnel", "true");
187
    	}
188
   }
189

  
190 140
XdmValue* Xslt30Processor::getParameter(const char* name) {
191 141
        std::map<std::string, XdmValue*>::iterator it;
192
        it = parameters.find("param:"+std::string(name));
142
        it = parameters.find("sparam:"+std::string(name));
193 143
        if (it != parameters.end())
194 144
          return it->second;
195
        else {
196
          it = parameters.find("sparam:"+std::string(name));
197
        if (it != parameters.end())
198
	  return it->second;
199
	  }
200
	return NULL;
145
	    return NULL;
201 146
}
202 147

  
203 148
bool Xslt30Processor::removeParameter(const char* name) {
......
208 153
    jitCompilation = jit;
209 154
}
210 155

  
211
void Xslt30Processor::setResultAsRawValue(bool option) {
212
	if(option) {
213
		setProperty("outvalue", "yes");
214
	}
215
 }
216

  
217
void Xslt30Processor::setProperty(const char* name, const char* value) {	
218
	if(name != NULL) {
219
	    int s = properties.size();
220
		std:string skey = std::string(name);
221
		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == NULL ? "" : value))));
222

  
223
		if(s == properties.size()) {
224
            std::map<std::string, std::string>::iterator it;
225
            it = properties.find(skey);
226
            if (it != properties.end()) {
227
                properties.erase(skey);
228
                properties[skey] = std::string((value == NULL ? "" : value));
229
            }
230
		}
231
	}
232
}
233

  
234
const char* Xslt30Processor::getProperty(const char* name) {
235
        std::map<std::string, std::string>::iterator it;
236
        it = properties.find(std::string(name));
237
        if (it != properties.end())
238
          return it->second.c_str();
239
	return NULL;
240
}
241 156

  
242 157
void Xslt30Processor::clearParameters(bool delValues) {
243 158
	if(delValues){
......
270 185
	
271 186
}
272 187

  
273
void Xslt30Processor::clearProperties() {
274
	properties.clear();
275
	
276
}
277

  
278 188

  
279 189

  
280 190
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
......
282 192
	return ptr;
283 193
}
284 194

  
285
std::map<std::string,std::string>& Xslt30Processor::getProperties(){
286
	std::map<std::string,std::string> &ptr = properties;
287
	return ptr;
288
}
289 195

  
290 196
void Xslt30Processor::exceptionClear(){
291 197
 if(proc->exception != NULL) {
......
319 225

  
320 226

  
321 227
    void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
322
	static jmethodID cAndSNodemID =
323
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
228
	static jmethodID cAndSNodemID = NULL;
229

  
230
	if(cAndSNodemID == NULL) {
231
			cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
324 232
					"compileFromXdmNodeAndSave",
325 233
					"(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
234
	}
326 235
	if (!cAndSNodemID) {
327 236
		std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
328 237
				<< " not found\n" << std::endl;
......
343 252
}
344 253

  
345 254
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
346
	static jmethodID cAndSStringmID =
347
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
255
	static jmethodID cAndSStringmID = NULL;
256
	if(cAndSStringmID == NULL) {
257
	   cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
348 258
					"compileFromStringAndSave",
349 259
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
260
	}
350 261
	if (!cAndSStringmID) {
351 262
		std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
352 263
				<< " not found\n" << std::endl;
......
367 278

  
368 279

  
369 280
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
370
	static jmethodID cAndFStringmID =
371
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
281
	static jmethodID cAndFStringmID =  NULL;
282

  
283
	if (cAndFStringmID == NULL) {
284
	    cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
372 285
					"compileFromFileAndSave",
373 286
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
287
	}
374 288
	if (!cAndFStringmID) {
375 289
		std::cerr << "Error: "<<getDllname() << ".compileFromFileAndSave"
376 290
				<< " not found\n" << std::endl;
......
389 303
}
390 304

  
391 305
void Xslt30Processor::compileFromString(const char* stylesheetStr) {
392
	static jmethodID cStringmID =
393
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
394
					"createStylesheetFromString",
395
					"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
306
	static jmethodID cStringmID = NULL;
307
	if (cStringmID == NULL) {
308
			cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
309
					"compileFromString",
310
					"(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
311
	}
312
					
396 313
	if (!cStringmID) {
397
		std::cerr << "Error: "<<getDllname() << ".createStylesheetFromString"
314
		std::cerr << "Error: "<<getDllname() << ".compileFromString"
398 315
				<< " not found\n" << std::endl;
316
		return NULL;
399 317

  
400 318
	} else {
401
		releaseStylesheet();
402
	    if(jitCompilation) {
403
	        setProperty("jit:", "yes");
404
	    } else {
405
            setProperty("jit:", "no");
406
	    }
319
		
320
		std::map<std::string,std::string> properties;
321

  
407 322
		JParameters comboArrays;
408 323
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
409
		stylesheetObject = (jobject)(
324
		jobject executableObject = (jobject)(
410 325
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
411 326
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
412
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), comboArrays.stringArray, comboArrays.objectArray));
413
		if (!stylesheetObject) {
327
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
328
		if (!executableObject) {
414 329
			proc->checkAndCreateException(cppClass);
330
			return NULL;
415 331
		}
416 332
		if (comboArrays.stringArray != NULL) {
417 333
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
418 334
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
419 335
		}
336
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
337
		return new XsltExecutable(executableObject);
420 338
	}
421 339

  
422 340
}
423 341

  
424 342
void Xslt30Processor::compileFromXdmNode(XdmNode * node) {
425
	static jmethodID cNodemID =
426
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"createStylesheetFromXdmNode",
427
			"(Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
343
	static jmethodID cNodemID = NULL;
344
    if(cNodemID == NULL) {			
345
			cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
346
			"(Ljava/lang/String;Ljava/lang/Object;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
347
	}
428 348
	if (!cNodemID) {
429
		std::cerr << "Error: "<< getDllname() << ".createStylesheetFromXdmNode"
349
		std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
430 350
				<< " not found\n" << std::endl;
351
		return NULL;
431 352

  
432 353
	} else {
433
		releaseStylesheet();
434
	    if(jitCompilation) {
435
	        setProperty("jit:", "yes");
436
	    } else {
437
            setProperty("jit:", "no");
438
	    }
439 354
		JParameters comboArrays;
440 355
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
441
		stylesheetObject = (jobject)(
356
		jobject executableObject = (jobject)(
442 357
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
443 358
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
444
						node->getUnderlyingValue(), comboArrays.stringArray, comboArrays.objectArray));
445
		if (!stylesheetObject) {
359
						node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
360
		if (!executableObject) {
446 361
			proc->checkAndCreateException(cppClass);
447
			//cout << "Error in compileFromXdmNode" << endl;
362
			return NULL;
448 363
		}
449 364
		if (comboArrays.stringArray != NULL) {
450 365
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
451 366
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
452 367
		}
368
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
369
        return new XsltExecutable(executableObject);
453 370
	}
454 371

  
455 372
}
456 373

  
457 374
void Xslt30Processor::compileFromAssociatedFile(const char* source) {
458
	static jmethodID cFilemID =
459
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
460
					"createStylesheetFromAssociatedFile",
461
					"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
375
	static jmethodID cFilemID = NULL;
376
    if(cFilemID == NULL) {	
377
	    cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
378
					"compileFromAssociatedFile",
379
					"(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
380
	}
462 381
	if (!cFilemID) {
463
		std::cerr << "Error: "<<getDllname() << ".createStylesheetFromFile"
382
		std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
464 383
				<< " not found\n" << std::endl;
384
		return NULL;
465 385

  
466 386
	} else {
467
		releaseStylesheet();
387
		
468 388
		if(source == NULL) {
469 389
			std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
470 390
			return;
471 391
		}
472 392
		JParameters comboArrays;
473 393
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
474
		stylesheetObject = (jobject)(
394
		jobject executableObject = (jobject)(
475 395
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
476 396
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
477
						SaxonProcessor::sxn_environ->env->NewStringUTF(source), comboArrays.stringArray, comboArrays.objectArray));
478
		if (!stylesheetObject) {
397
						SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
398
		if (!executableObject) {
479 399
			proc->checkAndCreateException(cppClass);
480
     		
400
     		return NULL;
481 401
		}
482 402
		if (comboArrays.stringArray != NULL) {
483 403
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
484 404
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
485 405
		}
486
		//SaxonProcessor::sxn_environ->env->NewGlobalRef(stylesheetObject);
406
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
407
		return new XsltExecutable(executableObject);
487 408
	}
488 409

  
489 410
}
490 411

  
491 412

  
492 413
void Xslt30Processor::compileFromFile(const char* stylesheet) {
493
	static jmethodID cFilemID =
494
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
495
					"createStylesheetFromFile",
496
					"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
414
	static jmethodID cFilemID = NULL;
415
	if(cFilemID == NULL) {
416
	    cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
417
					"compileFromFile",
418
					"(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
419
	}
497 420
	if (!cFilemID) {
498
		std::cerr << "Error: "<<getDllname() << ".createStylesheetFromFile"
421
		std::cerr << "Error: "<<getDllname() << ".compileFromFile"
499 422
				<< " not found\n" << std::endl;
423
		return NULL;
500 424

  
501 425
	} else {
502
		releaseStylesheet();
426
		
503 427
		if(stylesheet == NULL) {
504 428
			std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
505 429
			return;
506 430
		}
507 431
		JParameters comboArrays;
508 432
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
509
		stylesheetObject = (jobject)(
433
		jobject excutableObject = (jobject)(
510 434
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
511 435
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
512
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet), comboArrays.stringArray, comboArrays.objectArray));
513
		if (!stylesheetObject) {
436
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
437
		if (!executableObject) {
514 438
			proc->checkAndCreateException(cppClass);
439
			return NULL;
515 440
     		
516 441
		}
517 442
		if (comboArrays.stringArray != NULL) {
518 443
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
519 444
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
520 445
		}
521
		//SaxonProcessor::sxn_environ->env->NewGlobalRef(stylesheetObject);
522
	}
523

  
524
}
525

  
526
void Xslt30Processor::releaseStylesheet() {
527
    SaxonProcessor::sxn_environ->env->DeleteLocalRef(stylesheetObject);
528
	stylesheetObject = NULL;
529
	
530
}
531

  
532
    void Xslt30Processor::applyTemplatesReturningFile(const char * stylesheetfile, const char* output_filename){
533
	if(exceptionOccurred()) {
534
		//Possible error detected in the compile phase. Processor not in a clean state.
535
		//Require clearing exception.
536
		return;
537
	}
538

  
539
	if(selection == NULL) {
540
	   std::cerr<< "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."<<std::endl;
541
       		return;
542
	}
543

  
544
	if(stylesheetfile == NULL && !stylesheetObject){
545
	
546
		return;
547
	}
548

  
549
	setProperty("resources", proc->getResourcesDirectory());
550
	static jmethodID atmID =
551
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
552
					"applyTemplatesReturningFile",
553
					"(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
554
	if (!atmID) {
555
		std::cerr << "Error: "<< getDllname() << "applyTemplatesAsFile" << " not found\n"
556
				<< std::endl;
557

  
558
	} else {
559
        JParameters comboArrays;
560
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
561
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, atmID,
562
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),selection,
563
						(stylesheetfile != NULL ?
564
								SaxonProcessor::sxn_environ->env->NewStringUTF(
565
										stylesheetfile) :
566
								NULL), (output_filename != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(
567
                                       						output_filename) : NULL),
568
                                comboArrays.stringArray, comboArrays.objectArray);
569
		if (comboArrays.stringArray != NULL) {
570
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
571
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
572
		}
573
		proc->checkAndCreateException(cppClass);
574
	   	
575
	}
576
	return;
577

  
578
}
579

  
580
const char* Xslt30Processor::applyTemplatesReturningString(const char * stylesheetfile){
581
	if(exceptionOccurred()) {
582
		//Possible error detected in the compile phase. Processor not in a clean state.
583
		//Require clearing exception.
584
		return NULL;	
585
	}
586
	if(selection == NULL) {
587
	   std::cerr<< "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."<<std::endl;
588
       		return NULL;
589
	}
590
	if(stylesheetfile == NULL && !stylesheetObject){
591
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling applyTemplatesReturningString or check exceptions"<<std::endl;
592
		return NULL;
593
	}
594
	setProperty("resources", proc->getResourcesDirectory());
595
	jmethodID atsmID =
596
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
597
					"applyTemplatesReturningString",
598
					"(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
599
	if (!atsmID) {
600
		std::cerr << "Error: "<<getDllname() << "applyTemplatesAsString" << " not found\n"
601
				<< std::endl;
602

  
603
	} else {
604
	    JParameters comboArrays;
605
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
606

  
607
	jstring result = NULL;
608
	jobject obj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, atsmID,
609
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
610
								selection,
611
								(stylesheetfile!= NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetfile) : NULL ),
612
								comboArrays.stringArray, comboArrays.objectArray));
613

  
614
		if(obj) {
615
			result = (jstring)obj;
616
		}		
617
		if (comboArrays.stringArray != NULL) {
618
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
619
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
620
		}
621
		if (result) {
622
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
623
					NULL);
624
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
625
			return str;
626
		} else  {
627
			proc->checkAndCreateException(cppClass);  
628
	   		
629
     		}
446
		SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
447
		return new XsltExecutable(executableObject);
630 448
	}
631
	return NULL;
632

  
633 449

  
634 450
}
635 451

  
636
XdmValue * Xslt30Processor::applyTemplatesReturningValue(const char * stylesheetfile){
637
	if(exceptionOccurred()) {
638
		//Possible error detected in the compile phase. Processor not in a clean state.
639
		//Require clearing exception.
640
		return NULL;
641
	}
642
	if(selection == NULL) {
643
	   std::cerr<< "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."<<std::endl;
644
       		return NULL;
645
	}
646
	if(stylesheetfile == NULL && !stylesheetObject){
647
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling applyTemplatesReturningValue or check exceptions"<<std::endl;
648
		return NULL;
649
	}
650
	setProperty("resources", proc->getResourcesDirectory());
651
	jmethodID atsmID =
652
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
653
					"applyTemplatesReturningValue",
654
					"(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
655
	if (!atsmID) {
656
		std::cerr << "Error: "<<getDllname() << "applyTemplatesAsValue" << " not found\n"
657
				<< std::endl;
658

  
659
	} else {
660
	    JParameters comboArrays;
661
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
662

  
663

  
664
	   // jstring result = NULL;
665
	    jobject result = (jobject)(SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, atsmID,
666
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
667
								selection,
668
								( stylesheetfile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetfile) : NULL),
669
								comboArrays.stringArray, comboArrays.objectArray));
670
		/*if(obj) {
671
			result = (jobject)obj;
672
		}*/
673
		if (comboArrays.stringArray != NULL) {
674
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
675
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
676
		}
677
        if (result) {
678
		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
679
		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
680
		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
681
        	XdmValue * value = NULL;
682
		XdmItem * xdmItem = NULL;
683

  
684

  
685
			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
686
				xdmItem =  new XdmAtomicValue(result);
687
				xdmItem->setProcessor(proc);
688
				SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
689
				return xdmItem;
690

  
691
			} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
692
				xdmItem =  new XdmNode(result);	
693
				xdmItem->setProcessor(proc);
694
				SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
695
				return xdmItem;
696
			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
697
                xdmItem =  new XdmFunctionItem(result);
698
                xdmItem->setProcessor(proc);
699
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
700
                return xdmItem;
701
			} else {
702
				value = new XdmValue(result, true);
703
				value->setProcessor(proc);
704
				for(int z=0;z<value->size();z++) {
705
					value->itemAt(z)->setProcessor(proc);
706
				}
707
				SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
708
				return value;
709
			}
710
		} else  {
711
			proc->checkAndCreateException(cppClass);
712

  
713
     		}
714
	}
715
	return NULL;
716

  
717
}     
718

  
719

  
720

  
721
    void Xslt30Processor::callFunctionReturningFile(const char * stylesheetfile, const char* functionName, XdmValue ** arguments, int argument_length, const char* outfile){
722
        if(exceptionOccurred()) {
723
        		//Possible error detected in the compile phase. Processor not in a clean state.
724
        		//Require clearing exception.
725
        		return;
726
        	}
727

  
728

  
729
        	if(stylesheetfile == NULL && !stylesheetObject){
730

  
731
        		return;
732
        	}
733

  
734
        	setProperty("resources", proc->getResourcesDirectory());
735
        	static jmethodID afmID =
736
        			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
737
        					"callFunctionReturningFile",
738
        					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)V");
739
        	if (!afmID) {
740
        		std::cerr << "Error: "<< getDllname() << "callFunctionReturningFile" << " not found\n"
741
        				<< std::endl;
742
                 return;
743
        	} else {
744
                JParameters comboArrays;
745
        		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
746

  
747
        		jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
748

  
749
        		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, afmID,
750
        						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
751
        						(stylesheetfile != NULL ?
752
        								SaxonProcessor::sxn_environ->env->NewStringUTF(
753
        										stylesheetfile) :
754
        								NULL),
755
        						(functionName != NULL ?
756
        								SaxonProcessor::sxn_environ->env->NewStringUTF(functionName) :
757
        								NULL), argumentJArray,
758
        								(outfile != NULL ?
759
                                        			SaxonProcessor::sxn_environ->env->NewStringUTF(outfile) :
760
                             					NULL),
761
        								comboArrays.stringArray, comboArrays.objectArray);
762
        		if (comboArrays.stringArray != NULL) {
763
        			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
764
        			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
765
        		}
766
        		if(argumentJArray != NULL) {
767
        		    SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
768
        		}
769
        		proc->checkAndCreateException(cppClass);
770

  
771
        	}
772
        	return;
773

  
774

  
775

  
776

  
777
    }
778

  
779
    const char * Xslt30Processor::callFunctionReturningString(const char * stylesheet, const char* functionName, XdmValue ** arguments, int argument_length){
780
    	if(exceptionOccurred()) {
781
    		//Possible error detected in the compile phase. Processor not in a clean state.
782
    		//Require clearing exception.
783
    		return NULL;
784
    	}
785

  
786
    	if(stylesheet == NULL && !stylesheetObject){
787
    		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling callFunctionReturningString or check exceptions"<<std::endl;
788
    		return NULL;
789
    	}
790
    	setProperty("resources", proc->getResourcesDirectory());
791
    	jmethodID afsmID =
792
    			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
793
    					"callFunctionReturningString",
794
    					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
795
    	if (!afsmID) {
796
    		std::cerr << "Error: "<<getDllname() << "callFunctionReturningString" << " not found\n"
797
    				<< std::endl;
798

  
799
    	} else {
800
    	    JParameters comboArrays;
801
    		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
802
            jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
803

  
804
    	jstring result = NULL;
805
    	jobject obj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, afsmID,
806
    								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
807
    								(stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL ),
808
    								(functionName != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(functionName) : NULL),
809
    								argumentJArray, comboArrays.stringArray, comboArrays.objectArray));
810
    		if(obj) {
811
    			result = (jstring)obj;
812
    		}
813
    		if (comboArrays.stringArray != NULL) {
814
    			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
815
    			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
816
    		}
817
    		if (result) {
818
    			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
819
    					NULL);
820
    			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
821
    			return str;
822
    		} else  {
823
    			proc->checkAndCreateException(cppClass);
824

  
825
         		}
826
    	}
827
    	return NULL;
828
    }
829

  
830

  
831

  
832
    XdmValue * Xslt30Processor::callFunctionReturningValue(const char * stylesheet, const char* functionName, XdmValue ** arguments, int argument_length){
833
         	if(exceptionOccurred()) {
834
          		//Possible error detected in the compile phase. Processor not in a clean state.
835
          		//Require clearing exception.
836
          		return NULL;
837
          	}
838
          	
839
          	if(stylesheet == NULL && !stylesheetObject){
840
          		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling callFunctionReturningValue or check exceptions"<<std::endl;
841
          		return NULL;
842
          	}
843
          	setProperty("resources", proc->getResourcesDirectory());
844
          	jmethodID cfvmID =
845
          			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
846
          					"callFunctionReturningValue",
847
          					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
848
          	if (!cfvmID) {
849
          		std::cerr << "Error: "<<getDllname() << "callFunctionReturningValue" << " not found\n"
850
          				<< std::endl;
851

  
852
          	} else {
853
          	    JParameters comboArrays;
854
          		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
855
                jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
856
          	   
857
          	    jobject result = (jobject)(SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cfvmID,
858
          								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
859
          								(stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL ),
860
                                        (functionName != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(functionName) : NULL),
861
          								argumentJArray, comboArrays.stringArray, comboArrays.objectArray));
862

  
863
          		if (comboArrays.stringArray != NULL) {
864
          			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
865
          			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
866
          		}
867
			if(argumentJArray != NULL) {
868
          			SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
869
			}
870
                  if (result) {
871
          		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
872
          		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
873
          		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
874
                 	XdmValue * value = NULL;
875
          		XdmItem * xdmItem = NULL;
876

  
877

  
878
          			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
879
					    xdmItem = new XdmAtomicValue(result);
880
					    xdmItem->setProcessor(proc);
881
					    SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
882
					    return xdmItem;
883
          			} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
884
	  				    xdmItem = new XdmNode(result);
885
					    xdmItem->setProcessor(proc);
886
					    SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
887
					    return xdmItem;
888

  
889
          			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
890
          				 xdmItem =  new XdmFunctionItem(result);
891
                         xdmItem->setProcessor(proc);
892
                         SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
893
                         return xdmItem;
894
          			} else {
895
					value = new XdmValue(result, true);
896
					value->setProcessor(proc);
897
					for(int z=0;z<value->size();z++) {
898
						value->itemAt(z)->setProcessor(proc);
899
					}
900
					SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
901
					return value;
902
			}
903
			value = new XdmValue();
904
			value->setProcessor(proc);
905
            value->addUnderlyingValue(result);
906
	        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
907
			return value;
908
          	} else  {
909
          		proc->checkAndCreateException(cppClass);
910

  
911
               	}
912
          }
913
          return NULL;
914

  
915
    }
916

  
917

  
918
    void Xslt30Processor::callTemplateReturningFile(const char * stylesheetfile, const char* templateName, const char* outfile){
919
	if(exceptionOccurred()) {
920
		//Possible error detected in the compile phase. Processor not in a clean state.
921
		//Require clearing exception.
922
		return;
923
	}
924

  
925

  
926
	if(stylesheetfile == NULL && !stylesheetObject){
927
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling callFunctionReturningFile or check exceptions"<<std::endl;
928
		return;
929
	}
930

  
931
	setProperty("resources", proc->getResourcesDirectory());
932
	static jmethodID ctmID =
933
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
934
					"callTemplateReturningFile",
935
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
936
	if (!ctmID) {
937
		std::cerr << "Error: "<< getDllname() << "callTemplateReturningFile" << " not found\n"
938
				<< std::endl;
939

  
940
	} else {
941
        JParameters comboArrays;
942
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
943
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, ctmID,
944
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
945
						(stylesheetfile != NULL ?
946
								SaxonProcessor::sxn_environ->env->NewStringUTF(
947
										stylesheetfile) :
948
								NULL),
949
						(templateName != NULL ?
950
								SaxonProcessor::sxn_environ->env->NewStringUTF(templateName) :
951
								NULL),
952
								(outfile != NULL ?
953
                                			SaxonProcessor::sxn_environ->env->NewStringUTF(outfile) :
954
                     					NULL),
955
								comboArrays.stringArray, comboArrays.objectArray);
956
		if (comboArrays.stringArray != NULL) {
957
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
958
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
959
		}
960
		proc->checkAndCreateException(cppClass);
961

  
962
	}
963
	return;
964

  
965

  
966
    }
967

  
968

  
969

  
970

  
971
    const char* Xslt30Processor::callTemplateReturningString(const char * stylesheet, const char* templateName){
972
	if(exceptionOccurred()) {
973
		//Possible error detected in the compile phase. Processor not in a clean state.
974
		//Require clearing exception.
975
		return NULL;
976
	}
977

  
978
	if(stylesheet == NULL && !stylesheetObject){
979
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling callTemplateReturningString or check exceptions"<<std::endl;
980
		return NULL;
981
	}
982
	setProperty("resources", proc->getResourcesDirectory());
983
	jmethodID ctsmID =
984
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
985
					"callTemplateReturningString",
986
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
987
	if (!ctsmID) {
988
		std::cerr << "Error: "<<getDllname() << "callTemplateReturningString" << " not found\n"
989
				<< std::endl;
990

  
991
	} else {
992
	    JParameters comboArrays;
993
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
994

  
995

  
996
	jstring result = NULL;
997
	jobject obj =(jobject)(SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, ctsmID,
998
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
999
								(stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL ),
1000
								(templateName != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(templateName) : NULL),
1001
								comboArrays.stringArray, comboArrays.objectArray));
1002
		if(obj) {
1003
			result = (jstring)obj;
1004
		}
1005
		if (comboArrays.stringArray != NULL) {
1006
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
1007
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
1008
		}
1009
		if (result) {
1010
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
1011
					NULL);
1012
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
1013
			return str;
1014
		} else  {
1015
			proc->checkAndCreateException(cppClass);
1016

  
1017
     		}
1018
	}
1019
	return NULL;
1020

  
1021

  
1022
    }
1023

  
1024
    XdmValue* Xslt30Processor::callTemplateReturningValue(const char * stylesheet, const char* templateName){
1025
          	if(exceptionOccurred()) {
1026
          		//Possible error detected in the compile phase. Processor not in a clean state.
1027
          		//Require clearing exception.
1028
          		return NULL;
1029
          	}
1030
          	if(stylesheet == NULL && !stylesheetObject){
1031
          		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling callTemplateReturningValue or check exceptions"<<std::endl;
1032
          		return NULL;
1033
          	}
1034
          	setProperty("resources", proc->getResourcesDirectory());
1035
          	jmethodID ctsmID =
1036
          			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
1037
          					"callTemplateReturningValue",
1038
          					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
1039
          	if (!ctsmID) {
1040
          		std::cerr << "Error: "<<getDllname() << "callTemplateReturningValue" << " not found\n"
1041
          				<< std::endl;
1042

  
1043
          	} else {
1044
          	    JParameters comboArrays;
1045
          		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1046

  
1047

  
1048
          	    jstring result = NULL;
1049
          	    jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, ctsmID,
1050
          								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
1051
          								(stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL ),
1052
                                        (templateName != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(templateName) : NULL),
1053
          								comboArrays.stringArray, comboArrays.objectArray));
1054
          		if(obj) {
1055
          			result = (jstring)obj;
1056
          		}
1057
          		if (comboArrays.stringArray != NULL) {
1058
          			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
1059
          			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
1060
          		}
1061
                  if (result) {
1062
          		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
1063
          		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
1064
          		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
1065
                  	XdmValue * value = NULL;
1066
          		
1067
          		XdmItem * xdmItem = NULL;
1068
          			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
1069
          				xdmItem =  new XdmAtomicValue(result);
1070
					    xdmItem->setProcessor(proc);
1071
					    SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
1072
					    return xdmItem;
1073

  
1074
          			} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
1075
          				xdmItem = new XdmNode(result);
1076
					    xdmItem->setProcessor(proc);
1077
					    SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
1078
					    return xdmItem;
1079

  
1080
          			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
1081
                        xdmItem =  new XdmFunctionItem(result);
1082
                        xdmItem->setProcessor(proc);
1083
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
1084
                        return xdmItem;
1085
          			} else {
1086
					value = new XdmValue(result, true);
1087
					value->setProcessor(proc);
1088
					for(int z=0;z<value->size();z++) {
1089
						value->itemAt(z)->setProcessor(proc);
1090
					}
1091
		          		SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
1092
					return value;
1093
				}
1094
			    value = new XdmValue();
1095
			    value->setProcessor(proc);
1096
          		value->addUnderlyingValue(result);
1097
          		SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
1098
          		return value;
1099
         	} else  {
1100
          		proc->checkAndCreateException(cppClass);
1101
               	}
1102
          }
1103
        return NULL;
1104
    }
1105

  
1106 452

  
1107 453

  
1108 454

  
......
1121 467
	}
1122 468

  
1123 469
	setProperty("resources", proc->getResourcesDirectory());
1124
	static jmethodID mID =
1125
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
470
	static jmethodID mtvID = NULL;
471

  
472
	if(mtvID == NULL) {
473
			mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1126 474
					"transformToValue",
1127
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
1128
	if (!mID) {
475
					"(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;)Lnet/sf/saxon/s9api/XdmValue;");
476
	}
477
	if (!mtvID) {
1129 478
		std::cerr << "Error: "<< getDllname() << ".transformtoValue" << " not found\n"
1130 479
				<< std::endl;
1131 480

  
......
1134 483
		comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1135 484

  
1136 485
		jobject result = (jobject)(
1137
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
1138
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
1139
						(sourcefile != NULL ?
1140
								SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) :
1141
								NULL),
486
				SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
487
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
488
						(sourcefile != NULL ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : NULL),
1142 489
						(stylesheetfile != NULL ?
1143 490
								SaxonProcessor::sxn_environ->env->NewStringUTF(
1144 491
										stylesheetfile) :
......
1210 557
		return;
1211 558
	}
1212 559
	setProperty("resources", proc->getResourcesDirectory());
1213
	jmethodID mID =
1214
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
560
	static jmethodID mtfID = NULL;
561

  
562
	if(mtfID == NULL) {
563
		mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1215 564
					"transformToFile",
1216
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
1217
	if (!mID) {
565
					"(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/String;[Ljava/lang/Object;)V");
566
	}
567
	if (!mtfID) {
1218 568
		std::cerr << "Error: "<<getDllname() << "transformToFile" << " not found\n"
1219 569
				<< std::endl;
1220 570

  
......
1222 572
	    JParameters comboArrays;
1223 573
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1224 574

  
1225
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
1226
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
1227
								(source != NULL ?
1228
										SaxonProcessor::sxn_environ->env->NewStringUTF(
1229
												source) : NULL),
1230
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),							(outputfile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :NULL),
575
		SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
576
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
577
								(source != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : NULL),
578
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),	(outputfile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :NULL),
1231 579
								comboArrays.stringArray, comboArrays.objectArray);
1232 580
		if (comboArrays.stringArray!= NULL) {
1233 581
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
......
1238 586
	}
1239 587

  
1240 588

  
1241

  
1242

  
1243

  
1244
void Xslt30Processor::setupXslMessage(bool show, const char *filename=NULL) {
1245
    if(show) {
1246
        if(filename == NULL) {
1247
            setProperty("m", "on");
1248
        } else {
1249
            setProperty("m", std::string(filename));
1250
        }
1251
    } else {
1252
        setProperty("m", "off");
1253
    }
1254
}
1255

  
1256

  
1257 589
const char * Xslt30Processor::transformFileToString(const char* source,
1258 590
		const char* stylesheet) {
1259 591

  
......
1267 599
		return NULL;
1268 600
	}
1269 601
	setProperty("resources", proc->getResourcesDirectory());
1270
	jmethodID mID =
1271
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
602
	static jmethodID mtsID =  NULL;
603

  
604
	if(mtsID == NULL) {
605
			mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1272 606
					"transformToString",
1273 607
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
1274
	if (!mID) {
608
	}
609
	if (!mtsID) {
1275 610
		std::cerr << "Error: "<<getDllname() << "transformFileToString" << " not found\n"
1276 611
				<< std::endl;
1277 612

  
1278 613
	} else {
1279
		jobjectArray stringArray = NULL;
1280
		jobjectArray objectArray = NULL;
1281
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
1282
				"java/lang/Object");
1283
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
1284
				"java/lang/String");
1285

  
1286
		int size = parameters.size() + properties.size();
1287
#ifdef DEBUG
1288
		std::cerr<<"Properties size: "<<properties.size()<<std::endl;
1289
		std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
1290
#endif
1291
		if (size > 0) {
1292
			objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
1293
					objectClass, 0);
1294
			stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
1295
					stringClass, 0);
1296
			int i = 0;
1297
			for (std::map<std::string, XdmValue*>::iterator iter =
1298
					parameters.begin(); iter != parameters.end(); ++iter, i++) {
1299

  
1300
#ifdef DEBUG
1301
				std::cerr<<"map 1"<<std::endl;
1302
				std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
1303
#endif
1304
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
1305
						SaxonProcessor::sxn_environ->env->NewStringUTF(
1306
								(iter->first).c_str()));
1307
#ifdef DEBUG
1308
				std::string s1 = typeid(iter->second).name();
1309
				std::cerr<<"Type of itr:"<<s1<<std::endl;
1310

  
1311

  
1312
				jobject xx = (iter->second)->getUnderlyingValue();
1313

  
1314
				if(xx == NULL) {
1315
					std::cerr<<"value failed"<<std::endl;
1316
				} else {
1317

  
1318
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
1319
				}
1320
				if((iter->second)->getUnderlyingValue() == NULL) {
1321
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
1322
				}
1323
#endif
1324

  
1325
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
1326
						(iter->second)->getUnderlyingValue());
1327

  
1328
			}
1329

  
1330
			for (std::map<std::string, std::string>::iterator iter =
1331
					properties.begin(); iter != properties.end(); ++iter, i++) {
1332
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
1333
						SaxonProcessor::sxn_environ->env->NewStringUTF(
1334
								(iter->first).c_str()));
1335
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
1336
						SaxonProcessor::sxn_environ->env->NewStringUTF(
1337
								(iter->second).c_str()));
1338
			}
1339
		}
614
    JParameters comboArrays;
615
    comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1340 616

  
1341 617
	jstring result = NULL;
1342
	jobject obj =
1343
				(
1344
						SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
1345
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
618
	jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
619
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
1346 620
						(source != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(
1347 621
												source) : NULL),
1348 622
								(stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL),
1349
								stringArray, objectArray));
1350
		if(obj) {
623
								comboArrays.stringArray, comboArrays.objectArray);
624
    if (comboArrays.stringArray!= NULL) {
625
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
626
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
627
    }
628
	if(obj) {
1351 629
			result = (jstring)obj;
1352
		}		
1353
		if (size > 0) {
1354
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
1355
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
1356
		}
1357
		if (result) {
630
	}
631

  
632
	if (result) {
1358 633
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
1359 634
					NULL);
1360 635
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
......
1368 643
}
1369 644

  
1370 645

  
1371
   const char * Xslt30Processor::transformToString(XdmNode * source){
1372
	if(!stylesheetObject){
1373
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling transformToString or check exceptions"<<std::endl;
1374
		return NULL;
1375
	}
1376
	if(source != NULL){
1377
      		source->incrementRefCount();
1378
      		parameters["node"] = source;
1379
    	}
1380
	return transformFileToString(NULL, NULL);
1381
   }
1382

  
1383

  
1384
    XdmValue * Xslt30Processor::transformToValue(XdmNode * source){
1385
	if(!stylesheetObject){
1386
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling transformToValue or check exceptions"<<std::endl;
1387
		return NULL;
1388
	}
1389
	if(source != NULL){
1390
      		source->incrementRefCount();
1391
      		parameters["node"] = source;
1392
    	}
1393
	return transformFileToValue(NULL, NULL);
1394
   }
1395

  
1396
    void Xslt30Processor::transformToFile(XdmNode * source){
1397
	if(!stylesheetObject){
1398
		std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling transformToFile or check exceptions"<<std::endl;
1399
		return;
1400
	}
1401
	if(source != NULL){
1402
      		source->incrementRefCount();
1403
      		parameters["node"] = source;
1404
    	}
1405
	transformFileToFile(NULL, NULL, NULL);
1406
   }
1407 646

  
1408 647
const char * Xslt30Processor::getErrorMessage(int i ){
1409 648
 	if(proc->exception == NULL) {return NULL;}

Also available in: Unified diff