Project

Profile

Help

Revision 6304fb8b

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes and development work

View differences:

latest10/hec/Saxon.C.API/XQueryProcessor.cpp
23 23
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
24 24
#endif
25 25

  
26
    exception = NULL;
26
    exception = nullptr;
27 27
   // outputfile1 = "";
28 28
	if(!(proc->cwd.empty()) && curr.empty()){
29 29
		cwdXQ = proc->cwd;
......
46 46
}
47 47

  
48 48

  
49
XQueryProcessor::XQueryProcessor * clone() {
49
XQueryProcessor * XQueryProcessor::clone() {
50 50
      XQueryProcessor * proc = new XQueryProcessor(*this);
51 51
      return proc;
52 52

  
......
69 69
     * Set the source document for the query
70 70
    */
71 71
    void XQueryProcessor::setContextItem(XdmItem * value){
72
    	if(value != NULL){
72
    	if(value != nullptr){
73 73
	 value->incrementRefCount();
74 74
     	 parameters["node"] = (XdmValue *)value;
75 75
    	}
......
77 77

  
78 78

  
79 79
     void XQueryProcessor::declareNamespace(const char *prefix, const char * uri){
80
        if (prefix == NULL || uri == NULL) {
80
        if (prefix == nullptr || uri == nullptr) {
81 81
		    return;
82 82
        }  else {
83 83
            //setProperty("ns-prefix", uri);
84 84
             int s = properties.size();
85
             std:string skey = std::string("ns-prefix:"+prefix);
85
             std::string skey = std::string("ns-prefix:") + prefix;
86 86
             properties.insert(std::pair<std::string, std::string>(skey, std::string(uri)));
87 87

  
88 88
             if(s == properties.size()) {
......
117 117
     * Set a parameter value used in the query
118 118
     *
119 119
     * @param name  of the parameter, as a string
120
     * @param value of the query parameter, or null to clear a previously set value
120
     * @param value of the query parameter, or nullptr to clear a previously set value
121 121
     */
122 122
    void XQueryProcessor::setParameter(const char * name, XdmValue*value){
123
	if(value != NULL){
123
	if(value != nullptr){
124 124
		value->incrementRefCount();
125 125
		int s = parameters.size();
126
		std::String skey = "param:"+std::string(name);
126
		std::string skey = "param:"+std::string(name);
127 127
		parameters[skey] = value;
128 128
		if(s == parameters.size()) {
129 129
            std::map<std::string, XdmValue*>::iterator it;
......
131 131
            if (it != parameters.end()) {
132 132
                XdmValue * valuei = it->second;
133 133
                valuei->decrementRefCount();
134
                if(valuei != NULL && valuei->getRefCount() < 1){
134
                if(valuei != nullptr && valuei->getRefCount() < 1){
135 135
                    delete value;
136 136
                }
137 137
                parameters.erase(skey);
......
160 160
     */
161 161
    void XQueryProcessor::setProperty(const char * name, const char * value){
162 162
#ifdef DEBUG	
163
	if(value == NULL) {
164
		std::cerr<<"XQueryProc setProperty is NULL"<<std::endl;
163
	if(value == nullptr) {
164
		std::cerr<<"XQueryProc setProperty is nullptr"<<std::endl;
165 165
	}
166 166
#endif
167
    	if(name != NULL) {
167
    	if(name != nullptr) {
168 168
    	    int s = properties.size();
169 169
    		std:string skey = std::string(name);
170
    		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == NULL ? "" : value))));
170
    		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == nullptr ? "" : value))));
171 171

  
172 172
    		if(s == properties.size()) {
173 173
                std::map<std::string, std::string>::iterator it;
174 174
                it = properties.find(skey);
175 175
                if (it != properties.end()) {
176 176
                    properties.erase(skey);
177
                    properties[skey] = std::string((value == NULL ? "" : value));
177
                    properties[skey] = std::string((value == nullptr ? "" : value));
178 178
                }
179 179
    		}
180 180
    	}
......
191 191
#ifdef DEBUG
192 192
			std::cerr<<"XQueryProc.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
193 193
#endif
194
			if(value != NULL && value->getRefCount() < 1){		
194
			if(value != nullptr && value->getRefCount() < 1){
195 195
	        		delete value;
196 196
			}
197 197
        	}
......
241 241
    }
242 242

  
243 243
    void XQueryProcessor::executeQueryToFile(const char * infilename, const char * ofilename, const char * query){
244
	setProperty("resources", proc->getResourcesDirectory());  
244

  
245 245

  
246 246
	jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID (cppClass,"executeQueryToFile", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
247 247
 	if (!mID) {
248 248
        std::cerr<<"Error: MyClassInDll."<<"executeQueryToFile"<<" not found\n"<<std::endl;
249 249
    } else {
250
	jobjectArray stringArray = NULL;
251
	jobjectArray objectArray = NULL;
250
	jobjectArray stringArray = nullptr;
251
	jobjectArray objectArray = nullptr;
252 252

  
253 253
	int size = parameters.size() + properties.size();
254
	if(query!= NULL) size++;
255
	if(infilename!= NULL) size++;	
254
	if(query!= nullptr) size++;
255
	if(infilename!= nullptr) size++;
256 256
	if(size >0) {
257 257

  
258 258
	   int i=0;
......
260 260
	   jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
261 261
	   objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
262 262
	   stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
263
	   if(query!= NULL) {
263
	   if(query!= nullptr) {
264 264
	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("qs") );
265 265
     	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(query));
266 266
	     i++;	
267 267
	   }
268
	   if(infilename!= NULL) {
268
	   if(infilename!= nullptr) {
269 269
	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("s") );
270 270
     	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(infilename));
271 271
	     i++;	
......
295 295

  
296 296

  
297 297
    XdmValue * XQueryProcessor::executeQueryToValue(const char * infilename, const char * query){
298
	setProperty("resources", proc->getResourcesDirectory()); 
298

  
299 299
 jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID (cppClass,"executeQueryToValue", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
300 300
 if (!mID) {
301 301
        std::cerr<<"Error: MyClassInDll."<<"executeQueryToValue"<<" not found\n"<<std::endl;
302 302
    } else {
303
	jobjectArray stringArray = NULL;
304
	jobjectArray objectArray = NULL;
303
	jobjectArray stringArray = nullptr;
304
	jobjectArray objectArray = nullptr;
305 305

  
306 306
	int size = parameters.size() + properties.size();
307
	if(query!= NULL) size++;
308
	if(infilename!= NULL) size++;
307
	if(query!= nullptr) size++;
308
	if(infilename!= nullptr) size++;
309 309
	if(size >0) {
310 310
	   int i=0;
311 311
           jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
......
313 313
	   objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
314 314
	   stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
315 315

  
316
	   if(query!= NULL) {
316
	   if(query!= nullptr) {
317 317
	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("qs") );
318 318
     	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(query));
319 319
	     i++;	
320 320
	   }
321
	   if(infilename!= NULL) {
321
	   if(infilename!= nullptr) {
322 322
	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("s") );
323 323
     	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(infilename));
324 324
	     i++;	
......
342 342
		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
343 343
		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
344 344
		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
345
		XdmValue * value = NULL;
346
		XdmItem * xdmItem = NULL;
345
		XdmValue * value = nullptr;
346
		XdmItem * xdmItem = nullptr;
347 347

  
348 348
		if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
349 349
				xdmItem = new XdmAtomicValue(result);
......
361 361
                /*xdmItem =  new XdmFunctionItem(result);
362 362
                xdmItem->setProcessor(proc);
363 363
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);*/
364
                return NULL;// xdmItem;
364
                return nullptr;// xdmItem;
365 365
			} else {
366 366
				value = new XdmValue(result, true);
367 367
				value->setProcessor(proc);
......
380 380
	    exception = proc->checkAndCreateException(cppClass);
381 381
     	} 
382 382
  }
383
  return NULL;
383
  return nullptr;
384 384

  
385 385
}
386 386

  
387 387
    const char * XQueryProcessor::executeQueryToString(const char * infilename, const char * query){
388
	setProperty("resources", proc->getResourcesDirectory()); 
388

  
389 389
 jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID (cppClass,"executeQueryToString", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
390 390
 if (!mID) {
391 391
        std::cerr<<"Error: MyClassInDll."<<"executeQueryToString"<<" not found\n"<<std::endl;
392 392
    } else {
393
	jobjectArray stringArray = NULL;
394
	jobjectArray objectArray = NULL;
393
	jobjectArray stringArray = nullptr;
394
	jobjectArray objectArray = nullptr;
395 395

  
396 396
	int size = parameters.size() + properties.size();
397
	if(query!= NULL) size++;
398
	if(infilename!= NULL) size++;
397
	if(query!= nullptr) size++;
398
	if(infilename!= nullptr) size++;
399 399
	if(size >0) {
400 400
	   int i=0;
401 401
           jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
......
403 403
	   objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
404 404
	   stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
405 405

  
406
	   if(query!= NULL) {
406
	   if(query!= nullptr) {
407 407
	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("qs") );
408 408
     	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(query));
409 409
	     i++;	
410 410
	   }
411
	   if(infilename!= NULL) {
411
	   if(infilename!= nullptr) {
412 412
	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("s") );
413 413
     	     SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(infilename));
414 414
	     i++;	
......
429 429
	  SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
430 430

  
431 431
	  if(result) {
432
             const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
432
             const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
433 433
            //return "result should be ok";            
434 434
	    return str;
435 435
	   } else {
......
437 437
	   		
438 438
     		}
439 439
  }
440
  return NULL;
440
  return nullptr;
441 441

  
442 442

  
443 443
    }
444 444

  
445 445

  
446 446
    const char * XQueryProcessor::runQueryToString(){
447
	return executeQueryToString(NULL, NULL);	
447
	return executeQueryToString(nullptr, nullptr);
448 448

  
449 449
    }
450 450

  
451 451

  
452 452
    XdmValue * XQueryProcessor::runQueryToValue(){
453
	return executeQueryToValue(NULL, NULL);
453
	return executeQueryToValue(nullptr, nullptr);
454 454
   }
455 455

  
456 456
    void XQueryProcessor::runQueryToFile(){
457
	executeQueryToFile(NULL, NULL, NULL);
457
	executeQueryToFile(nullptr, nullptr, nullptr);
458 458
   }
459 459

  
460 460
    void XQueryProcessor::setQueryFile(const char * ofile){
......
470 470

  
471 471

  
472 472
void XQueryProcessor::exceptionClear(){
473
	if(exception != NULL) {
473
	if(exception != nullptr) {
474 474
		delete exception;
475
		exception = NULL;
475
		exception = nullptr;
476 476
		SaxonProcessor::sxn_environ->env->ExceptionClear();
477 477
	}
478 478

  
......
487 487

  
488 488

  
489 489
const char * XQueryProcessor::getErrorCode() {
490
	if(exception == NULL) {return NULL;}
490
	if(exception == nullptr) {return nullptr;}
491 491
	return exception->getErrorCode();
492 492
}
493 493

  
494 494
const char * XQueryProcessor::getErrorMessage(){
495
	if(exception == NULL) {return NULL;}
496
	return exception->getErrorMessage();
495
	if(exception == nullptr) {return nullptr;}
496
	return exception->getMessage();
497 497
}
498 498

  
499 499
const char* XQueryProcessor::checkException(){
500
	/*if(proc->exception == NULL) {
500
	/*if(proc->exception == nullptr) {
501 501
		proc->exception = proc->checkForException(SaxonProcessor::sxn_environ->env, cppClass, cppXQ);
502 502
	}
503 503
        return proc->exception;*/
......
507 507

  
508 508

  
509 509
/*int XQueryProcessor::exceptionCount(){
510
	if(proc->exception != NULL){
510
	if(proc->exception != nullptr){
511 511
		return proc->exception->count();
512 512
	}
513 513
	return 0;

Also available in: Unified diff