Project

Profile

Help

Revision 4e3fba42

Added by O'Neil Delpratt over 5 years ago

Saxon/C bug fix relating to static sxn_environ

View differences:

latest9.6/hec/Saxon.C.API/XPathProcessor.cpp
15 15
	/*
16 16
	 * Look for class.
17 17
	 */
18
	cppClass = lookForClass(sxn_environ->env,
18
	cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
19 19
			"net/sf/saxon/option/cpp/XPathProcessor");
20 20
	if ((proc->proc) == NULL) {
21 21
		cerr << "Processor is NULL" << endl;
22 22
	}
23 23

  
24
	cppXP = createSaxonProcessor2(sxn_environ->env, cppClass,
24
	cppXP = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
25 25
			"(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
26 26

  
27 27

  
28 28

  
29 29
#ifdef DEBUG
30
	jmethodID debugMID = sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
31
	sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
30
	jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
31
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
32 32
#endif    
33 33

  
34 34
	proc->exception = NULL;
......
47 47
}
48 48
setProperty("resources", proc->getResourcesDirectory());
49 49
jmethodID mID =
50
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "evaluate",
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;");
52 52
if (!mID) {
53 53
	cerr << "Error: MyClassInDll." << "evaluate" << " not found\n"
......
56 56
} else {
57 57
	jobjectArray stringArray = NULL;
58 58
	jobjectArray objectArray = NULL;
59
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
60
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
59
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
60
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
61 61

  
62 62
	int size = parameters.size() + properties.size();
63 63
	if (size > 0) {
64
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
64
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
65 65
				objectClass, 0);
66
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
66
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
67 67
				stringClass, 0);
68 68
		int i = 0;
69 69
		for (map<std::string, XdmValue*>::iterator iter = parameters.begin();
70 70
				iter != parameters.end(); ++iter, i++) {
71
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
72
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
73
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
71
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
72
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
73
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
74 74
					(iter->second)->getUnderlyingValue(proc));
75 75
		}
76 76
		for (map<std::string, std::string>::iterator iter = properties.begin();
77 77
				iter != properties.end(); ++iter, i++) {
78
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
79
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
80
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
81
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
78
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
79
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
80
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
81
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
82 82
		}
83 83
	}
84 84
	jobjectArray results = (jobjectArray)(
85
			sxn_environ->env->CallObjectMethod(cppXP, mID,
86
					sxn_environ->env->NewStringUTF(cwdXP.c_str()),
87
					sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
85
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXP, mID,
86
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXP.c_str()),
87
					SaxonProcessor::sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
88 88
	if(!results) {
89 89
		if(exceptionOccurred()) {
90 90
			if(proc->exception != NULL) {
91 91
				delete proc->exception;
92 92
			}
93
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
93
			proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
94 94
			proc->exceptionClear();
95 95
			return NULL;
96 96
	   		
97 97
     		}
98 98
	}
99 99
	
100
	int sizex = sxn_environ->env->GetArrayLength(results);
100
	int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
101 101
	if (size > 0) {
102
		sxn_environ->env->DeleteLocalRef(stringArray);
103
		sxn_environ->env->DeleteLocalRef(objectArray);
102
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
103
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
104 104
	}
105 105
	if (sizex>0) {
106
		jclass atomicValueClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
107
		jclass nodeClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
108
		jclass functionItemClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
106
		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
107
		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
108
		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
109 109

  
110 110
		XdmValue * value = new XdmValue();
111 111
		value->setProcessor(proc);
112 112
		XdmItem * xdmItem = NULL;
113 113
		for (int p=0; p < sizex; ++p) 
114 114
		{
115
			jobject resulti = sxn_environ->env->GetObjectArrayElement(results, p);
115
			jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
116 116
			//value->addUnderlyingValue(resulti);
117 117

  
118
			if(sxn_environ->env->IsInstanceOf(resulti, atomicValueClass)           == JNI_TRUE) {
118
			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(resulti, atomicValueClass)           == JNI_TRUE) {
119 119
				xdmItem = new XdmAtomicValue(resulti);
120 120
				
121 121

  
122
			} else if(sxn_environ->env->IsInstanceOf(resulti, nodeClass)           == JNI_TRUE) {
122
			} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(resulti, nodeClass)           == JNI_TRUE) {
123 123
				xdmItem = new XdmNode(resulti);
124 124

  
125 125

  
126
			} else if (sxn_environ->env->IsInstanceOf(resulti, functionItemClass)           == JNI_TRUE) {
126
			} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(resulti, functionItemClass)           == JNI_TRUE) {
127 127
				continue;
128 128
			}
129 129
			xdmItem->setProcessor(proc);
130 130
			value->addXdmItem(xdmItem);
131 131
		}
132
		sxn_environ->env->DeleteLocalRef(results);
132
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(results);
133 133
		return value;
134 134
	}
135 135
}
......
144 144
        }
145 145
setProperty("resources", proc->getResourcesDirectory());
146 146
jmethodID mID =
147
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "evaluateSingle",
147
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "evaluateSingle",
148 148
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmItem;");
149 149
if (!mID) {
150 150
	cerr << "Error: MyClassInDll." << "evaluateSingle" << " not found\n"
......
153 153
} else {
154 154
	jobjectArray stringArray = NULL;
155 155
	jobjectArray objectArray = NULL;
156
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
157
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
156
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
157
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
158 158

  
159 159
	int size = parameters.size() + properties.size();
160 160
#ifdef DEBUG
......
163 163
		cerr<<"size:"<<size<<endl;
164 164
#endif
165 165
	if (size > 0) {
166
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
166
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
167 167
				objectClass, 0);
168
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
168
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
169 169
				stringClass, 0);
170 170
		int i = 0;
171 171
		for (map<std::string, XdmValue*>::iterator iter = parameters.begin();
172 172
				iter != parameters.end(); ++iter, i++) {
173
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
174
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
175
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
173
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
174
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
175
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
176 176
					(iter->second)->getUnderlyingValue(proc));
177 177
#ifdef DEBUG
178 178
				string s1 = typeid(iter->second).name();
......
191 191
		}
192 192
		for (map<std::string, std::string>::iterator iter = properties.begin();
193 193
				iter != properties.end(); ++iter, i++) {
194
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
195
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
196
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
197
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
194
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
195
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
196
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
197
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
198 198
		}
199 199
	}
200 200
	jobject result = (jobject)(
201
			sxn_environ->env->CallObjectMethod(cppXP, mID,
202
					sxn_environ->env->NewStringUTF(cwdXP.c_str()),
203
					sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
201
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXP, mID,
202
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXP.c_str()),
203
					SaxonProcessor::sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
204 204
	if (size > 0) {
205
		sxn_environ->env->DeleteLocalRef(stringArray);
206
		sxn_environ->env->DeleteLocalRef(objectArray);
205
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
206
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
207 207
	}
208 208
	if (result) {
209
		jclass atomicValueClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
210
		jclass nodeClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
211
		jclass functionItemClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
209
		jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
210
		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
211
		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
212 212
		XdmItem * xdmItem = NULL;
213
		if(sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
213
		if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
214 214
			xdmItem = new XdmAtomicValue(result);
215 215

  
216
		} else if(sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
216
		} else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
217 217
			
218 218
			xdmItem = new XdmNode(result);
219 219

  
220
		} else if (sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
220
		} else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
221 221
			return NULL;
222 222
		}
223 223
		xdmItem->setProcessor(proc);
......
226 226
			if(proc->exception != NULL) {
227 227
				delete proc->exception;
228 228
			}
229
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
229
			proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
230 230
			proc->exceptionClear();
231 231
	   		
232 232
     		}
......
256 256
		return;
257 257
        }
258 258
	jmethodID mID =
259
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "declareNamespace",
259
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "declareNamespace",
260 260
				"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
261 261
	if (!mID) {
262 262
	cerr << "Error: MyClassInDll." << "declareNameSpace" << " not found\n"
263 263
			<< endl;
264 264

  
265 265
	} else {
266
			sxn_environ->env->CallObjectMethod(cppXP, mID,
267
					sxn_environ->env->NewStringUTF(prefix),
268
					sxn_environ->env->NewStringUTF(uri));
266
			SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXP, mID,
267
					SaxonProcessor::sxn_environ->env->NewStringUTF(prefix),
268
					SaxonProcessor::sxn_environ->env->NewStringUTF(uri));
269 269
	}
270 270

  
271 271
}
......
277 277
        }
278 278
setProperty("resources", proc->getResourcesDirectory());
279 279
jmethodID mID =
280
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "setBaseURI",
280
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "setBaseURI",
281 281
				"(Ljava/lang/String;)Z");
282 282
if (!mID) {
283 283
	cerr << "Error: MyClassInDll." << "setBaseURI" << " not found\n"
......
285 285

  
286 286
} else {
287 287

  
288
	sxn_environ->env->CallObjectMethod(cppXP, mID,
289
					sxn_environ->env->NewStringUTF(uriStr));
288
	SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXP, mID,
289
					SaxonProcessor::sxn_environ->env->NewStringUTF(uriStr));
290 290
}
291 291

  
292 292
}
......
298 298
        }
299 299
setProperty("resources", proc->getResourcesDirectory());
300 300
jmethodID mID =
301
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "effectiveBooleanValue",
301
		(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "effectiveBooleanValue",
302 302
				"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Z");
303 303
if (!mID) {
304 304
	cerr << "Error: MyClassInDll." << "effectiveBooleanValue" << " not found\n"
......
307 307
} else {
308 308
	jobjectArray stringArray = NULL;
309 309
	jobjectArray objectArray = NULL;
310
	jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
311
	jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
310
	jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
311
	jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
312 312

  
313 313
	int size = parameters.size() + properties.size();
314 314
	if (size > 0) {
315
		objectArray = sxn_environ->env->NewObjectArray((jint) size,
315
		objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
316 316
				objectClass, 0);
317
		stringArray = sxn_environ->env->NewObjectArray((jint) size,
317
		stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
318 318
				stringClass, 0);
319 319
		int i = 0;
320 320
		for (map<std::string, XdmValue*>::iterator iter = parameters.begin();
321 321
				iter != parameters.end(); ++iter, i++) {
322
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
323
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
324
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
322
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
323
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
324
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
325 325
					(iter->second)->getUnderlyingValue(proc));
326 326
		}
327 327
		for (map<std::string, std::string>::iterator iter = properties.begin();
328 328
				iter != properties.end(); ++iter, i++) {
329
			sxn_environ->env->SetObjectArrayElement(stringArray, i,
330
					sxn_environ->env->NewStringUTF((iter->first).c_str()));
331
			sxn_environ->env->SetObjectArrayElement(objectArray, i,
332
					sxn_environ->env->NewStringUTF((iter->second).c_str()));
329
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(stringArray, i,
330
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->first).c_str()));
331
			SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
332
					SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()));
333 333
		}
334 334
	}
335 335
	jboolean result = (jboolean)(
336
			sxn_environ->env->CallBooleanMethod(cppXP, mID,
337
					sxn_environ->env->NewStringUTF(cwdXP.c_str()),
338
					sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
336
			SaxonProcessor::sxn_environ->env->CallBooleanMethod(cppXP, mID,
337
					SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXP.c_str()),
338
					SaxonProcessor::sxn_environ->env->NewStringUTF(xpathStr), stringArray, objectArray));
339 339
	if (size > 0) {
340
		sxn_environ->env->DeleteLocalRef(stringArray);
341
		sxn_environ->env->DeleteLocalRef(objectArray);
340
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
341
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
342 342
	}
343 343
	if(exceptionOccurred()) {
344 344
			if(proc->exception != NULL) {
345 345
				delete proc->exception;
346 346
			}
347
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
347
			proc->exception = proc->checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
348 348
			proc->exceptionClear();
349 349
	   		
350 350
     	}
......
414 414
		proc->exception = NULL;	
415 415
	}
416 416

  
417
   sxn_environ->env->ExceptionClear();
417
   SaxonProcessor::sxn_environ->env->ExceptionClear();
418 418
 
419 419
}
420 420

  
......
442 442

  
443 443

  
444 444
    const char* XPathProcessor::checkException(){
445
	return checkForException(*(sxn_environ), cppClass, cppXP);
445
	return checkForException(*(SaxonProcessor::sxn_environ), cppClass, cppXP);
446 446
    }
447 447

  

Also available in: Unified diff