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/SchemaValidator.cpp
17 17
	 */
18 18
	cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
19 19
			"net/sf/saxon/option/cpp/SchemaValidatorForCpp");
20
	if ((proc->proc) == NULL) {
21
		std::cerr << "Processor is NULL" << std::endl;
20
	if ((proc->proc) == nullptr) {
21
		std::cerr << "Processor is nullptr" << std::endl;
22 22
	}
23 23

  
24 24
	cppV = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
......
40 40
}
41 41

  
42 42
   void SchemaValidator::setcwd(const char* dir){
43
	if(dir==NULL) {
43
	if(dir==nullptr) {
44 44
    		cwdV = std::string(dir);
45 45
	}
46 46
   }
......
66 66
		}
67 67
		exception = proc->checkAndCreateException(cppClass);
68 68
	}
69
	return NULL;
69
	return nullptr;
70 70
}
71 71

  
72 72
  void SchemaValidator::registerSchemaFromFile(const char * sourceFile){
73
	if (sourceFile == NULL) {
74
		std::cerr << "Error:: sourceFile string cannot be empty or NULL" << std::endl;
73
	if (sourceFile == nullptr) {
74
		std::cerr << "Error:: sourceFile string cannot be empty or nullptr" << std::endl;
75 75
	     return;
76 76
        }
77 77
	
......
82 82
		std::cerr << "Error: libsaxon." << "validate" << " not found\n"
83 83
			<< std::endl;
84 84
	} else {
85
	jobjectArray stringArray = NULL;
86
	jobjectArray objectArray = NULL;
85
	jobjectArray stringArray = nullptr;
86
	jobjectArray objectArray = nullptr;
87 87
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
88 88
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
89 89

  
......
109 109
				std::string s1 = typeid(iter->second).name();
110 110
				std::cerr<<"Type of itr:"<<s1<<std::endl;
111 111
				jobject xx = (iter->second)->getUnderlyingValue();
112
				if(xx == NULL) {
112
				if(xx == nullptr) {
113 113
					std::cerr<<"value failed"<<std::endl;
114 114
				} else {
115 115

  
116 116
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
117 117
				}
118
				if((iter->second)->getUnderlyingValue() == NULL) {
119
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
118
				if((iter->second)->getUnderlyingValue() == nullptr) {
119
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
120 120
				}
121 121
#endif
122 122
		}
......
145 145
 }
146 146

  
147 147
 void SchemaValidator::exportSchema(const char * fileName) {
148
      if (fileName == NULL) {
149
      		std::cerr << "Error:: fileName string cannot be empty or NULL" << std::endl;
148
      if (fileName == nullptr) {
149
      		std::cerr << "Error:: fileName string cannot be empty or nullptr" << std::endl;
150 150
      	     return;
151 151
              }
152 152

  
......
171 171
 }
172 172

  
173 173
  void SchemaValidator::registerSchemaFromString(const char * sourceStr){
174
	setProperty("resources", proc->getResourcesDirectory());
174

  
175 175
	
176
	if (sourceStr == NULL) {
177
		std::cerr << "Error:: Schema string cannot be empty or NULL" << std::endl;
176
	if (sourceStr == nullptr) {
177
		std::cerr << "Error:: Schema string cannot be empty or nullptr" << std::endl;
178 178
	     return;
179 179
        }
180 180
	jmethodID mID =
......
185 185
		std::cerr << "Error: libsaxon." << "registerSchemaString" << " not found\n"
186 186
			<< std::endl;
187 187
	} else {
188
	jobjectArray stringArray = NULL;
189
	jobjectArray objectArray = NULL;
188
	jobjectArray stringArray = nullptr;
189
	jobjectArray objectArray = nullptr;
190 190
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
191 191
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
192 192

  
......
213 213
				std::string s1 = typeid(iter->second).name();
214 214
				std::cerr<<"Type of itr:"<<s1<<std::endl;
215 215
				jobject xx = (iter->second)->getUnderlyingValue();
216
				if(xx == NULL) {
216
				if(xx == nullptr) {
217 217
					std::cerr<<"value failed"<<std::endl;
218 218
				} else {
219 219

  
220 220
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
221 221
				}
222
				if((iter->second)->getUnderlyingValue() == NULL) {
223
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
222
				if((iter->second)->getUnderlyingValue() == nullptr) {
223
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
224 224
				}
225 225
#endif
226 226
		}
......
236 236
	
237 237
			SaxonProcessor::sxn_environ->env->CallVoidMethod(cppV, mID,
238 238
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()),
239
					(sourceStr != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceStr) : NULL), NULL, stringArray, objectArray);
239
					(sourceStr != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceStr) : nullptr), nullptr, stringArray, objectArray);
240 240

  
241 241
	if (size > 0) {
242 242
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
......
249 249
}
250 250

  
251 251
  void SchemaValidator::validate(const char * sourceFile){
252
	/*if (sourceFile == NULL) {
253
		std::cerr << "Error:: sourceFile string cannot be empty or NULL" << std::endl;
252
	/*if (sourceFile == nullptr) {
253
		std::cerr << "Error:: sourceFile string cannot be empty or nullptr" << std::endl;
254 254
	     return;
255 255
        }*/
256
setProperty("resources", proc->getResourcesDirectory());
256

  
257 257
jmethodID mID =
258 258
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "validate",
259 259
				"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
......
262 262
			<< std::endl;
263 263

  
264 264
} else {
265
	jobjectArray stringArray = NULL;
266
	jobjectArray objectArray = NULL;
265
	jobjectArray stringArray = nullptr;
266
	jobjectArray objectArray = nullptr;
267 267
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
268 268
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
269 269

  
......
300 300
				std::string s1 = typeid(iter->second).name();
301 301
				std::cerr<<"param-name:"<<(iter->first)<<",  "<<"Type of itr:"<<s1<<std::endl;
302 302
				jobject xx = (iter->second)->getUnderlyingValue();
303
				if(xx == NULL) {
303
				if(xx == nullptr) {
304 304
					std::cerr<<"value failed"<<std::endl;
305 305
				} else {
306 306

  
307 307
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
308 308
				}
309
				if((iter->second)->getUnderlyingValue() == NULL) {
310
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
309
				if((iter->second)->getUnderlyingValue() == nullptr) {
310
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
311 311
				}
312 312
#endif
313 313
		}
......
323 323
	
324 324
			SaxonProcessor::sxn_environ->env->CallVoidMethod(cppV, mID,
325 325
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()), 
326
					(sourceFile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile) : NULL), (outputFile.empty() ? NULL : outputFile.c_str() ), stringArray, objectArray);
326
					(sourceFile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile) : nullptr), (outputFile.empty() ? nullptr : outputFile.c_str() ), stringArray, objectArray);
327 327

  
328 328
	if (size > 0) {
329 329
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
......
335 335
}
336 336
   
337 337
XdmNode * SchemaValidator::validateToNode(const char * sourceFile){
338
	/*if (sourceFile == NULL) {
339
		std::cerr << "Error:: source file string cannot be empty or NULL" << std::endl;
340
	     return NULL;
338
	/*if (sourceFile == nullptr) {
339
		std::cerr << "Error:: source file string cannot be empty or nullptr" << std::endl;
340
	     return nullptr;
341 341
        }*/
342
setProperty("resources", proc->getResourcesDirectory());
342

  
343 343
jmethodID mID =
344 344
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "validateToNode",
345 345
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmNode;");
......
348 348
			<< std::endl;
349 349

  
350 350
} else {
351
	jobjectArray stringArray = NULL;
352
	jobjectArray objectArray = NULL;
351
	jobjectArray stringArray = nullptr;
352
	jobjectArray objectArray = nullptr;
353 353
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
354 354
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
355 355

  
......
375 375
				std::string s1 = typeid(iter->second).name();
376 376
				std::cerr<<"Type of itr:"<<s1<<std::endl;
377 377
				jobject xx = (iter->second)->getUnderlyingValue();
378
				if(xx == NULL) {
378
				if(xx == nullptr) {
379 379
					std::cerr<<"value failed"<<std::endl;
380 380
				} else {
381 381

  
382 382
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
383 383
				}
384
				if((iter->second)->getUnderlyingValue() == NULL) {
385
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
384
				if((iter->second)->getUnderlyingValue() == nullptr) {
385
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
386 386
				}
387 387
#endif
388 388
		}
......
397 397
	jobject result = (jobject)(
398 398
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppV, mID,
399 399
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdV.c_str()),
400
					(sourceFile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile) : NULL), stringArray, objectArray));
400
					(sourceFile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(sourceFile) : nullptr), stringArray, objectArray));
401 401
	if (size > 0) {
402 402
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
403 403
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
......
411 411
	exception = proc->checkAndCreateException(cppClass);
412 412

  
413 413
}
414
	return NULL;
414
	return nullptr;
415 415
}
416 416

  
417 417
void SchemaValidator::exceptionClear(){
418
 if(exception != NULL) {
418
 if(exception != nullptr) {
419 419
 	delete exception;
420
 	exception = NULL;
420
 	exception = nullptr;
421 421
 }
422 422
   SaxonProcessor::sxn_environ->env->ExceptionClear();
423 423
 }
424 424

  
425 425
/*const char * SchemaValidator::getErrorCode(int i) {
426
	if(proc->exception == NULL) {return NULL;}
426
	if(proc->exception == nullptr) {return nullptr;}
427 427
	return proc->exception->getErrorCode(i);
428 428
}
429 429

  
430 430
const char * SchemaValidator::getErrorMessage(int i ){
431
 if(proc->exception == NULL) {return NULL;}
431
 if(proc->exception == nullptr) {return nullptr;}
432 432
 return proc->exception->getErrorMessage(i);
433 433
 } */
434 434

  
435 435
bool SchemaValidator::exceptionOccurred() {
436
	return proc->exceptionOccurred() || exception != NULL;
436
	return proc->exceptionOccurred() || exception != nullptr;
437 437
}
438 438

  
439 439
const char* SchemaValidator::checkException() {
......
441 441
}
442 442

  
443 443
/*int SchemaValidator::exceptionCount(){
444
 if(proc->exception != NULL){
444
 if(proc->exception != nullptr){
445 445
 return proc->exception->count();
446 446
 }
447 447
 return 0;
448 448
 }   */
449 449

  
450 450
void SchemaValidator::setSourceNode(XdmNode * value) {
451
    if(value != NULL){
451
    if(value != nullptr){
452 452
      value->incrementRefCount();
453 453
      parameters["node"] = (XdmValue *)value;
454 454
    }
......
457 457
}
458 458

  
459 459
void SchemaValidator::setParameter(const char * name, XdmValue*value) {
460
	if(value != NULL){
460
	if(value != nullptr){
461 461
		value->incrementRefCount();
462 462
		parameters["param:"+std::string(name)] = value;
463 463
	}
......
469 469

  
470 470
void SchemaValidator::setProperty(const char * name, const char * value) {
471 471
#ifdef DEBUG	
472
	if(value == NULL) {
473
		std::cerr<<"Validator setProperty is NULL"<<std::endl;
472
	if(value == nullptr) {
473
		std::cerr<<"Validator setProperty is nullptr"<<std::endl;
474 474
	}
475 475
#endif
476
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value== NULL ? "" : value))));
476
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value== nullptr ? "" : value))));
477 477
}
478 478

  
479 479
void SchemaValidator::clearParameters(bool delVal) {
......
484 484
#ifdef DEBUG
485 485
			std::cout<<"SchemaValidator.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
486 486
#endif
487
			if(value != NULL && value->getRefCount() < 1){		
487
			if(value != nullptr && value->getRefCount() < 1){
488 488
	        		delete value;
489 489
			}
490 490
        	}

Also available in: Unified diff