Project

Profile

Help

Revision 5d25f10d

Added by O'Neil Delpratt 5 months ago

Saxon/C development - XPath tests

View differences:

src/main/c/Saxon.C.API/XPathProcessor.cpp
28 28
		std::cerr << "Processor is nullptr" << std::endl;
29 29
	}
30 30

  
31
	cppXP = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
31
    jobject tempcppXP = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
32 32
			"(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
33 33

  
34 34

  
35
    if(tempcppXP) {
36
        cppXP = SaxonProcessor::sxn_environ->env->NewGlobalRef(tempcppXP);
37
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(tempcppXP);
38

  
39
    } else {
40
        createException("Error: Failed to create the XPathProcessor internal object");
41

  
42
    }
43

  
44

  
35 45

  
36 46
#ifdef DEBUG
37 47
	jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
......
47 57

  
48 58
}
49 59

  
60

  
61
XPathProcessor::~XPathProcessor(){
62
    clearProperties();
63
    clearParameters();
64

  
65
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(cppXP);
66
    exceptionClear();
67
    //delete contextItem;
68
}
69

  
50 70
XdmValue * XPathProcessor::evaluate(const char * xpathStr) {
51 71
	if (xpathStr == nullptr) {
52 72
		std::cerr << "Error:: XPath string cannot be empty or nullptr" << std::endl;
......
241 261
}
242 262

  
243 263
void XPathProcessor::setContextItem(XdmItem * item) {
244
	contextItem = item;
245 264
    	if(item != nullptr){
246 265
     	 parameters["node"] = (XdmValue *)item;
247 266
    	}
......
429 448
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
430 449
            XdmValue *value = itr->second;
431 450
            if (value != nullptr) {
432
                value->decrementRefCount();
433 451
#ifdef DEBUG
434 452
                std::cerr<<"XPathProc.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
435 453
#endif
436
                if (value->getRefCount() < 1) {
437 454
                    delete value;
438
                }
439 455
            }
440 456
        }
441 457
    }
......
463 479
}
464 480

  
465 481
void XPathProcessor::exceptionClear(){
466
	if(exception != nullptr) {
467
		delete proc->exception;
468
		exception = nullptr;
469
	}
482
    if(exception != nullptr) {
483
        delete exception;
484
        exception = nullptr;
485
        SaxonProcessor::sxn_environ->env->ExceptionClear();
486
    }
470 487

  
471
   SaxonProcessor::sxn_environ->env->ExceptionClear();
472
 
473 488
}
474 489

  
475 490
const char * XPathProcessor::getErrorCode() {
......
487 502

  
488 503
}
489 504

  
490
    bool XPathProcessor::exceptionOccurred(){
491
	return proc->exceptionOccurred();
492
    }
505
bool XPathProcessor::exceptionOccurred() {
506
    return proc->exceptionOccurred() || exception != nullptr;
507
}
493 508

  
494 509

  
495 510

  
496
    const char* XPathProcessor::checkException(){
497
	return proc->checkException();
511
void XPathProcessor::createException(const char * message) {
512
    if(exception != nullptr) {
513
        delete exception;
514
        exception = nullptr;
498 515
    }
516
    if(message == nullptr) {
517
        exception = proc->checkAndCreateException(cppClass);
518
    } else {
519
        exception = new SaxonApiException(message);
520
    }
521

  
522
}
499 523

  

Also available in: Unified diff