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/XPathProcessor.cpp
17 17
	 */
18 18
	cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
19 19
			"net/sf/saxon/option/cpp/XPathProcessor");
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
	cppXP = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
......
31 31
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
32 32
#endif    
33 33

  
34
	exception = NULL;
34
	exception = nullptr;
35 35
	if(!(proc->cwd.empty()) && curr.empty()){
36 36
		cwdXP = proc->cwd;
37 37
	} else {
......
41 41
}
42 42

  
43 43
XdmValue * XPathProcessor::evaluate(const char * xpathStr) {
44
	if (xpathStr == NULL) {
45
		std::cerr << "Error:: XPath string cannot be empty or NULL" << std::endl;
46
	return NULL;
44
	if (xpathStr == nullptr) {
45
		std::cerr << "Error:: XPath string cannot be empty or nullptr" << std::endl;
46
	return nullptr;
47 47
}
48
setProperty("resources", proc->getResourcesDirectory());
48

  
49 49
jmethodID mID =
50 50
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "evaluate",
51 51
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[Lnet/sf/saxon/s9api/XdmValue;");
......
54 54
			<< std::endl;
55 55

  
56 56
} else {
57
	jobjectArray stringArray = NULL;
58
	jobjectArray objectArray = NULL;
57
	jobjectArray stringArray = nullptr;
58
	jobjectArray objectArray = nullptr;
59 59
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
60 60
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
61 61

  
......
88 88
					SaxonProcessor::sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
89 89
	if(!results) {
90 90
		exception = proc->checkAndCreateException(cppClass);
91
		return NULL;
91
		return nullptr;
92 92
	}
93 93
	
94 94
	int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
......
102 102
		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
103 103

  
104 104
		XdmValue * value = new XdmValue();
105
		XdmItem * xdmItem = NULL;
105
		XdmItem * xdmItem = nullptr;
106 106
		for (int p=0; p < sizex; ++p) 
107 107
		{
108 108
			jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
......
132 132
		return value;
133 133
	}
134 134
}
135
return NULL;
135
return nullptr;
136 136

  
137 137
}
138 138

  
139 139
XdmItem * XPathProcessor::evaluateSingle(const char * xpathStr) {
140
	if (xpathStr == NULL) {
141
		std::cerr << "Error:: XPath string cannot be empty or NULL" << std::endl;
142
	     return NULL;
140
	if (xpathStr == nullptr) {
141
		std::cerr << "Error:: XPath string cannot be empty or nullptr" << std::endl;
142
	     return nullptr;
143 143
        }
144
setProperty("resources", proc->getResourcesDirectory());
144

  
145 145
jmethodID mID =
146 146
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "evaluateSingle",
147 147
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmItem;");
......
150 150
			<< std::endl;
151 151

  
152 152
} else {
153
	jobjectArray stringArray = NULL;
154
	jobjectArray objectArray = NULL;
153
	jobjectArray stringArray = nullptr;
154
	jobjectArray objectArray = nullptr;
155 155
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
156 156
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
157 157

  
......
177 177
				std::string s1 = typeid(iter->second).name();
178 178
				std::cerr<<"Type of itr:"<<s1<<std::endl;
179 179
				jobject xx = (iter->second)->getUnderlyingValue();
180
				if(xx == NULL) {
180
				if(xx == nullptr) {
181 181
					std::cerr<<"value failed"<<std::endl;
182 182
				} else {
183 183

  
184 184
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
185 185
				}
186
				if((iter->second)->getUnderlyingValue() == NULL) {
187
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
186
				if((iter->second)->getUnderlyingValue() == nullptr) {
187
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
188 188
				}
189 189
#endif
190 190
		}
......
208 208
		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
209 209
		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
210 210
		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
211
		XdmItem * xdmItem = NULL;
211
		XdmItem * xdmItem = nullptr;
212 212
		if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
213 213
			xdmItem = new XdmAtomicValue(result);
214 214

  
......
217 217
			xdmItem = new XdmNode(result);
218 218

  
219 219
		} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
220
			return NULL;
220
			return nullptr;
221 221
		}
222 222
		xdmItem->setProcessor(proc);
223 223
		//SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
......
228 228
     		}
229 229
}
230 230

  
231
return NULL;
231
return nullptr;
232 232

  
233 233
}
234 234

  
235 235
void XPathProcessor::setContextItem(XdmItem * item) {
236 236
	contextItem = item;
237
    	if(item != NULL){
237
    	if(item != nullptr){
238 238
     	 parameters["node"] = (XdmValue *)item;
239 239
    	}
240 240
}
241 241

  
242 242
void XPathProcessor::setContextFile(const char * filename) {
243
	if (filename != NULL) {
243
	if (filename != nullptr) {
244 244
		setProperty("s", filename);
245 245
	}
246 246
}
247 247

  
248 248

  
249 249
void XPathProcessor::declareNamespace(const char *prefix, const char * uri){
250
        if (prefix == NULL || uri == NULL) {
250
        if (prefix == nullptr || uri == nullptr) {
251 251
		return;
252 252
        }
253 253
	jmethodID mID =
......
287 287
}
288 288

  
289 289
void XPathProcessor::importSchemaNamespace(const char* uri){
290
      if (uri != NULL) {
290
      if (uri != nullptr) {
291 291
       		setProperty("importSN", uri);
292 292
      }
293 293
}
......
297 297

  
298 298

  
299 299
void XPathProcessor::setBaseURI(const char * uriStr) {
300
	if (uriStr == NULL) {
301
		std::cerr << "Error:: XPath string cannot be empty or NULL" << std::endl;
300
	if (uriStr == nullptr) {
301
		std::cerr << "Error:: XPath string cannot be empty or nullptr" << std::endl;
302 302
	     return;
303 303
        }
304
setProperty("resources", proc->getResourcesDirectory());
304

  
305 305
jmethodID mID =
306 306
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "setBaseURI",
307 307
				"(Ljava/lang/String;)V");
......
318 318
}
319 319

  
320 320
bool XPathProcessor::effectiveBooleanValue(const char * xpathStr) {
321
	if (xpathStr == NULL) {
322
		std::cerr << "Error:: XPath string cannot be empty or NULL" << std::endl;
321
	if (xpathStr == nullptr) {
322
		std::cerr << "Error:: XPath string cannot be empty or nullptr" << std::endl;
323 323
	     return false;
324 324
        }
325
setProperty("resources", proc->getResourcesDirectory());
325

  
326 326
jmethodID mID =
327 327
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "effectiveBooleanValue",
328 328
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Z");
......
330 330
	std::cerr << "Error: MyClassInDll." << "effectiveBooleanValue" << " not found\n"<< std::endl;
331 331

  
332 332
} else {
333
	jobjectArray stringArray = NULL;
334
	jobjectArray objectArray = NULL;
333
	jobjectArray stringArray = nullptr;
334
	jobjectArray objectArray = nullptr;
335 335
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
336 336
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
337 337

  
......
372 372
}
373 373

  
374 374
void XPathProcessor::setParameter(const char * name, XdmValue* value) {
375
	if(value != NULL){
375
	if(value != nullptr){
376 376
		value->incrementRefCount();
377 377
		int s = parameters.size();
378 378
		std::string skey = "param:"+std::string(name);
......
383 383
            if (it != parameters.end()) {
384 384
                XdmValue * valuei = it->second;
385 385
                valuei->decrementRefCount();
386
                if(valuei != NULL && valuei->getRefCount() < 1){
386
                if(valuei != nullptr && valuei->getRefCount() < 1){
387 387
                    delete value;
388 388
                }
389 389
                parameters.erase(skey);
......
398 398
}
399 399

  
400 400
void XPathProcessor::setProperty(const char * name, const char * value) {
401
	if(name != NULL) {
401
	if(name != nullptr) {
402 402
	    int s = properties.size();
403 403
		std::string skey = std::string(name);
404
		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == NULL ? "" : value))));
404
		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == nullptr ? "" : value))));
405 405

  
406 406
		if(s == properties.size()) {
407 407
            std::map<std::string, std::string>::iterator it;
408 408
            it = properties.find(skey);
409 409
            if (it != properties.end()) {
410 410
                properties.erase(skey);
411
                properties[skey] = std::string((value == NULL ? "" : value));
411
                properties[skey] = std::string((value == nullptr ? "" : value));
412 412
            }
413 413
		}
414 414
	}
......
422 422
#ifdef DEBUG
423 423
			std::cerr<<"XPathProc.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
424 424
#endif
425
			if(value != NULL && value->getRefCount() < 1){		
425
			if(value != nullptr && value->getRefCount() < 1){
426 426
	        		delete value;
427 427
			}
428 428
        	}
......
450 450
}
451 451

  
452 452
void XPathProcessor::exceptionClear(){
453
	if(exception != NULL) {
453
	if(exception != nullptr) {
454 454
		delete proc->exception;
455
		exception = NULL;
455
		exception = nullptr;
456 456
	}
457 457

  
458 458
   SaxonProcessor::sxn_environ->env->ExceptionClear();
......
460 460
}
461 461

  
462 462
const char * XPathProcessor::getErrorCode() {
463
	if(exception == NULL) {return NULL;}
463
	if(exception == nullptr) {return nullptr;}
464 464
	return exception->getErrorCode();
465 465
}
466 466

  
467 467
const char * XPathProcessor::getErrorMessage(){
468
	if(exception == NULL) {return NULL;}
468
	if(exception == nullptr) {return nullptr;}
469 469
	return exception->getErrorMessage();
470 470
}
471 471

  

Also available in: Unified diff