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/XdmNode.cpp
13 13
	XDM_NODE_KIND nodeKind;
14 14
*/
15 15

  
16
XdmNode::XdmNode(jobject obj): XdmItem(obj), baseURI(NULL), nodeName(NULL), children(NULL), childCount(-1), parent(NULL), typedValue(NULL), attrValues(NULL), attrCount(-1), nodeKind(UNKNOWN){
16
XdmNode::XdmNode(jobject obj): XdmItem(obj), baseURI(nullptr), nodeName(nullptr), children(nullptr), childCount(-1), parent(nullptr), typedValue(nullptr), attrValues(nullptr), attrCount(-1), nodeKind(UNKNOWN){
17 17

  
18 18
}
19 19

  
20
XdmNode::XdmNode(XdmNode * p, jobject obj, XDM_NODE_KIND kind): XdmItem(obj), baseURI(NULL), nodeName(NULL), children(NULL),  childCount(-1), parent(p), typedValue(NULL), attrValues(NULL),  attrCount(-1), nodeKind(kind){}
20
XdmNode::XdmNode(XdmNode * p, jobject obj, XDM_NODE_KIND kind): XdmItem(obj), baseURI(nullptr), nodeName(nullptr), children(nullptr),  childCount(-1), parent(p), typedValue(nullptr), attrValues(nullptr),  attrCount(-1), nodeKind(kind){}
21 21

  
22 22
bool XdmNode::isAtomic() {
23 23
	return false;
24 24
} 
25 25
    
26 26
    XDM_NODE_KIND XdmNode::getNodeKind(){
27
	if(nodeKind == UNKNOWN && proc != NULL) {
28
		nodeKind = static_cast<XDM_NODE_KIND>(proc->getNodeKind(value->xdmvalue));
27
	if(nodeKind == UNKNOWN) {
28
            jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmNode;");
29
            static jmethodID nodeKindMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
30
                                                                                                     "getNodeKind",
31
                                                                                                     "()Lnet/sf/saxon/s9api/XdmNodeKind;");
32
            if (!nodeKindMID) {
33
                std::cerr << "Error: MyClassInDll." << "getNodeKind" << " not found\n"
34
                          << std::endl;
35
                return UNKNOWN;
36
            }
37

  
38
            jobject nodeKindObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, nodeKindMID));
39
            if (!nodeKindObj) {
40

  
41
                return UNKNOWN;
42
            }
43
            jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/option/cpp/XdmUtils;");
44

  
45
            jmethodID mID2 = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,
46
                                                                                             "convertNodeKindType",
47
                                                                                             "(Lnet/sf/saxon/s9api/XdmNodeKind;)I");
48

  
49
            if (!mID2) {
50
                std::cerr << "Error: MyClassInDll." << "convertNodeKindType" << " not found\n"
51
                          << std::endl;
52
                return UNKNOWN;
53
            }
54

  
55
            int kvalue = (int) (SaxonProcessor::sxn_environ->env->CallStaticIntMethod(xdmUtilsClass, mID2, nodeKindObj));
56

  
57
		nodeKind = static_cast<XDM_NODE_KIND>(kvalue);
29 58
	} 
30 59
	return nodeKind;
31 60

  
......
33 62

  
34 63
    const char * XdmNode::getNodeName(){
35 64
	
36
	if(nodeName != NULL) {
65
	if(nodeName != nullptr) {
37 66
		return nodeName;
38 67
	}
39 68
	XDM_NODE_KIND kind = getNodeKind();
......
44 73
            case DOCUMENT:
45 74
            case TEXT:
46 75
            case COMMENT:
47
                return NULL;
76
                return nullptr;
48 77
            case PROCESSING_INSTRUCTION:
49 78
            case NAMESPACE:
50 79
            case ELEMENT:
......
52 81
               
53 82
		if (!xmID) {
54 83
			std::cerr << "Error: MyClassInDll." << "getNodeName"<< " not found\n" << std::endl;
55
			return NULL;
84
			return nullptr;
56 85
		} else {
57
			jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, value->xdmvalue));
86
			jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, value));
58 87
			if(!result) {
59
				return NULL;
88
				return nullptr;
60 89
			} else {
61
				nodeName = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
90
				nodeName = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
62 91
				return nodeName;
63 92
			} 
64 93
		}
65 94
            default:
66
                return NULL;
95
                return nullptr;
67 96
        }
68 97
	
69 98

  
70 99
    }
71 100

  
72 101
    XdmValue * XdmNode::getTypedValue(){
73
    	if(typedValue == NULL) {
102
    	if(typedValue == nullptr) {
74 103
    		jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
75 104
    		jmethodID tbmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
76 105
    					"getTypedValue",
......
78 107
    		if (!tbmID) {
79 108
    			std::cerr << "Error: Saxonc." << "getTypedValue"
80 109
    				<< " not found\n" << std::endl;
81
    			return NULL;
110
    			return nullptr;
82 111
    		} else {
83
    			jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, tbmID));
112
    			jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, tbmID));
84 113
    			if(valueObj) {
85
    				typedValue = new XdmValue((proc == NULL ? NULL : proc));
114
    				typedValue = new XdmValue((proc == nullptr ? nullptr : proc));
86 115
    				typedValue->addUnderlyingValue(valueObj);
87 116
    				return typedValue;
88 117
    			}
89
    			return NULL;
118
    			return nullptr;
90 119
    		}
91 120
    	} else {
92 121
    		return typedValue;
......
108 137
        		if (!strbMID) {
109 138
        			std::cerr << "Error: Saxonc." << "toString"
110 139
        				<< " not found\n" << std::endl;
111
        			return NULL;
140
        			return nullptr;
112 141
        		} else {
113
        			jstring result = (jstring) (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, strbMID));
142
        			jstring result = (jstring) (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, strbMID));
114 143
        			if(result) {
115
                       const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
144
                       const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
116 145
                       stringValue = str;
117 146
                  		return str;
118 147
                }
119
                   return NULL;
148
                   return nullptr;
120 149
        		}
121 150
        	} else {
122 151
        		return stringValue.c_str();
......
126 155
    
127 156
    const char* XdmNode::getBaseUri(){
128 157

  
129
	if(baseURI != NULL) {
158
	if(baseURI != nullptr) {
130 159
		return baseURI;
131 160
	}
132 161

  
......
137 166
	if (!bmID) {
138 167
		std::cerr << "Error: MyClassInDll." << "getBaseURI"
139 168
				<< " not found\n" << std::endl;
140
		return NULL;
169
		return nullptr;
141 170
	} else {
142
		jobject nodeURIObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, bmID));
171
		jobject nodeURIObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, bmID));
143 172
		if(!nodeURIObj){
144
			return NULL;
173
			return nullptr;
145 174
		} else {
146 175
			jclass URIClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/net/URI");
147 176
			jmethodID strMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(URIClass,
......
151 180
				jstring result = (jstring)(
152 181
				SaxonProcessor::sxn_environ->env->CallObjectMethod(nodeURIObj, strMID));
153 182
				baseURI = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
154
					NULL);
183
					nullptr);
155 184
			
156 185
				return baseURI;
157 186
			}	
158 187
		}
159 188
	}
160
	return NULL;	
189
	return nullptr;
161 190
    }
162 191
    
163 192
    
......
166 195

  
167 196

  
168 197
    XdmNode* XdmNode::getParent(){
169
	if(parent == NULL && proc!= NULL) {
198
	if(parent == nullptr && proc!= nullptr) {
170 199
		jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
171 200
		jmethodID bmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
172 201
					"getParent",
......
174 203
		if (!bmID) {
175 204
			std::cerr << "Error: MyClassInDll." << "getParent"
176 205
				<< " not found\n" << std::endl;
177
			return NULL;
206
			return nullptr;
178 207
		} else {
179
			jobject nodeObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, bmID));
208
			jobject nodeObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, bmID));
180 209
			if(nodeObj) {
181
				parent = new XdmNode(NULL, nodeObj, UNKNOWN);
210
				parent = new XdmNode(nullptr, nodeObj, UNKNOWN);
182 211
				parent->setProcessor(proc);
183 212
				//parent->incrementRefCount();
184 213
				return parent;
185 214
			}
186
			return NULL;
215
			return nullptr;
187 216
		}
188 217
	} else {
189 218
		return parent;
......
193 222
    
194 223
    const char* XdmNode::getAttributeValue(const char *str){
195 224

  
196
	if(str == NULL) { return NULL;}
225
	if(str == nullptr) { return nullptr;}
197 226
	jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
198 227
	jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeValue",
199 228
					"(Lnet/sf/saxon/s9api/XdmNode;Ljava/lang/String;)Ljava/lang/String;");
200 229
	if (!xmID) {
201 230
			std::cerr << "Error: SaxonDll." << "getAttributeValue"
202 231
				<< " not found\n" << std::endl;
203
			return NULL;
232
			return nullptr;
204 233
		}
205
	if(str == NULL) {
206
		return NULL;
234
	if(str == nullptr) {
235
		return nullptr;
207 236
	}
208 237
	jstring eqname = SaxonProcessor::sxn_environ->env->NewStringUTF(str);
209 238

  
210
	jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value->xdmvalue, eqname));
239
	jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value, eqname));
211 240
	SaxonProcessor::sxn_environ->env->DeleteLocalRef(eqname);
212 241
	//failure = checkForException(sxn_environ,  (jobject)result);//Remove code
213 242
	if(result) {
214 243
		const char * stri = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
215
					NULL);
244
					nullptr);
216 245
		
217 246
		//SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
218 247

  
219 248
		return stri;
220 249
	} else {
221 250

  
222
		return NULL;
251
		return nullptr;
223 252
	}
224 253

  
225 254
    }
226 255

  
227 256
    XdmNode** XdmNode::getAttributeNodes(){
228
	if(attrValues == NULL) {
257
	if(attrValues == nullptr) {
229 258
		jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
230 259
		jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeNodes",
231 260
					"(Lnet/sf/saxon/s9api/XdmNode;)[Lnet/sf/saxon/s9api/XdmNode;");
232 261
		jobjectArray results = (jobjectArray)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
233
		value->xdmvalue));
234
		if(results == NULL) {
235
			return NULL;	
262
		value));
263
		if(results == nullptr) {
264
			return nullptr;
236 265
		}
237 266
		int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
238 267
		attrCount = sizex;
239 268
		if(sizex>0) {	
240 269
			attrValues =  new XdmNode*[sizex];
241
			XdmNode * tempNode =NULL;
270
			XdmNode * tempNode =nullptr;
242 271
			for (int p=0; p < sizex; ++p){
243 272
				jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
244 273
				tempNode = new XdmNode(this, resulti, ATTRIBUTE);
......
252 281
    }
253 282

  
254 283
    int XdmNode::getAttributeCount(){
255
	if(attrCount == -1 && proc!= NULL) {
284
	if(attrCount == -1 && proc!= nullptr) {
256 285
		jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
257 286
		jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeCount",
258 287
					"(Lnet/sf/saxon/s9api/XdmNode;)I");
......
263 292
			return 0;
264 293
		}
265 294
		jint result = (jlong)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
266
		value->xdmvalue));
295
		value));
267 296

  
268 297
		attrCount =(int)result;
269 298
	}
......
271 300
    }
272 301

  
273 302
    int XdmNode::getChildCount(){
274
	if(childCount == -1 && proc!= NULL) {
303
	if(childCount == -1 && proc!= nullptr) {
275 304
		jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
276 305
		jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getChildCount",
277 306
					"(Lnet/sf/saxon/s9api/XdmNode;)I");
......
282 311
			return 0;
283 312
		}
284 313
		jint result = (jlong)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
285
		value->xdmvalue));
314
		value));
286 315

  
287 316
		childCount =(int)result;
288 317
	}
......
291 320
    
292 321
    XdmNode** XdmNode::getChildren(){
293 322

  
294
	if(children == NULL && proc!= NULL) {
323
	if(children == nullptr && proc!= nullptr) {
295 324
		jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
296 325
		jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getChildren",
297 326
					"(Lnet/sf/saxon/s9api/XdmNode;)[Lnet/sf/saxon/s9api/XdmNode;");
......
299 328
		if (!xmID) {
300 329
			std::cerr << "Error: SaxonDll." << "getchildren"
301 330
				<< " not found\n" << std::endl;
302
			return NULL;
331
			return nullptr;
303 332
		}
304 333
		jobjectArray results = (jobjectArray)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
305
		value->xdmvalue));
334
		value));
306 335
		int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
307 336
		childCount = sizex;	
308 337
		children =  new XdmNode*[sizex];
309
		XdmNode * tempNode = NULL;
338
		XdmNode * tempNode = nullptr;
310 339
		for (int p=0; p < sizex; ++p){
311 340
			jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
312 341
			tempNode = new XdmNode(this, resulti, UNKNOWN);

Also available in: Unified diff