Project

Profile

Help

Revision 0af164b2

Added by O'Neil Delpratt over 5 years ago

Saxon/C bug fix relating to issue 2772

View differences:

latest9.6/hec/Saxon.C.API/XQueryProcessor.cpp
13 13
    proc = p;
14 14

  
15 15
  
16
     cppClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XQueryEngine");
16
     cppClass = lookForClass(sxn_environ->env, "net/sf/saxon/option/cpp/XQueryEngine");
17 17

  
18 18

  
19
    cppXQ = createSaxonProcessor2 (environ->env, cppClass, "(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
19
    cppXQ = createSaxonProcessor2 (sxn_environ->env, cppClass, "(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
20 20
    
21 21
#ifdef DEBUG
22
	jmethodID debugMID = environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
23
	environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
22
	jmethodID debugMID = sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
23
	sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
24 24
#endif
25 25

  
26 26
    proc->exception = NULL;
......
61 61
		return;
62 62
        }
63 63
	jmethodID mID =
64
		(jmethodID) environ->env->GetMethodID(cppClass, "declareNamespace",
64
		(jmethodID) sxn_environ->env->GetMethodID(cppClass, "declareNamespace",
65 65
				"(Ljava/lang/String;Ljava/lang/String;)V");
66 66
	if (!mID) {
67 67
	cerr << "Error: MyClassInDll." << "declareNameSpace" << " not found\n"
......
69 69

  
70 70
	} else {
71 71
	
72
			environ->env->CallObjectMethod(cppXQ, mID,
73
					environ->env->NewStringUTF(prefix),
74
					environ->env->NewStringUTF(uri));
72
			sxn_environ->env->CallObjectMethod(cppXQ, mID,
73
					sxn_environ->env->NewStringUTF(prefix),
74
					sxn_environ->env->NewStringUTF(uri));
75 75
	}
76 76

  
77 77
}
......
164 164
    void XQueryProcessor::executeQueryToFile(const char * infilename, const char * ofilename, const char * query){
165 165
	setProperty("resources", proc->getResourcesDirectory());  
166 166

  
167
	jmethodID mID = (jmethodID)environ->env->GetMethodID (cppClass,"executeQueryToFile", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
167
	jmethodID mID = (jmethodID)sxn_environ->env->GetMethodID (cppClass,"executeQueryToFile", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
168 168
 	if (!mID) {
169 169
        cout<<"Error: MyClassInDll."<<"executeQueryToFile"<<" not found\n"<<endl;
170 170
    } else {
......
177 177
	if(size >0) {
178 178

  
179 179
	   int i=0;
180
           jclass objectClass = lookForClass(environ->env, "java/lang/Object");
181
	   jclass stringClass = lookForClass(environ->env, "java/lang/String");
182
	   objectArray = environ->env->NewObjectArray( (jint)size, objectClass, 0 );
183
	   stringArray = environ->env->NewObjectArray( (jint)size, stringClass, 0 );
180
           jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
181
	   jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
182
	   objectArray = sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
183
	   stringArray = sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
184 184
	   if(query!= NULL) {
185
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF("qs") );
186
     	     environ->env->SetObjectArrayElement( objectArray, i, environ->env->NewStringUTF(query));
185
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF("qs") );
186
     	     sxn_environ->env->SetObjectArrayElement( objectArray, i, sxn_environ->env->NewStringUTF(query));
187 187
	     i++;	
188 188
	   }
189 189
	   if(infilename!= NULL) {
190
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF("s") );
191
     	     environ->env->SetObjectArrayElement( objectArray, i, environ->env->NewStringUTF(infilename));
190
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF("s") );
191
     	     sxn_environ->env->SetObjectArrayElement( objectArray, i, sxn_environ->env->NewStringUTF(infilename));
192 192
	     i++;	
193 193
	   }
194 194
	   for(map<std::string, XdmValue* >::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter, i++) {
195
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF( (iter->first).c_str() ) );
196
		bool checkCast = environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(proc), lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
195
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF( (iter->first).c_str() ) );
196
		bool checkCast = sxn_environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(proc), lookForClass(sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
197 197
		if(( (bool)checkCast)==false ){
198 198
			failure = "FAILURE in  array of XdmValueForCpp";
199 199
		} 
200
	     environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue(proc)) );
200
	     sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue(proc)) );
201 201
	   }
202 202
  	   for(map<std::string, std::string >::iterator iter=properties.begin(); iter!=properties.end(); ++iter, i++) {
203
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF( (iter->first).c_str()  ));
204
	     environ->env->SetObjectArrayElement( objectArray, i, (jobject)(environ->env->NewStringUTF((iter->second).c_str())) );
203
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
204
	     sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)(sxn_environ->env->NewStringUTF((iter->second).c_str())) );
205 205
	   }
206 206
	}
207 207

  
208
	 environ->env->CallObjectMethod(cppXQ, mID, environ->env->NewStringUTF(cwdXQ.c_str()), environ->env->NewStringUTF(ofilename), stringArray, objectArray );
209
	  environ->env->DeleteLocalRef(objectArray);
210
	  environ->env->DeleteLocalRef(stringArray);
208
	 sxn_environ->env->CallObjectMethod(cppXQ, mID, sxn_environ->env->NewStringUTF(cwdXQ.c_str()), sxn_environ->env->NewStringUTF(ofilename), stringArray, objectArray );
209
	  sxn_environ->env->DeleteLocalRef(objectArray);
210
	  sxn_environ->env->DeleteLocalRef(stringArray);
211 211

  
212 212
	if(exceptionOccurred()) {
213 213
			if(proc->exception != NULL) {
214 214
				delete proc->exception;
215 215
			}		
216
		proc->exception = proc->checkForExceptionCPP(environ->env, cppClass, NULL);	
216
		proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);	
217 217
		proc->exceptionClear();
218 218
	   		
219 219
     	}
......
226 226

  
227 227
    XdmValue * XQueryProcessor::executeQueryToValue(const char * infilename, const char * query){
228 228
	setProperty("resources", proc->getResourcesDirectory()); 
229
 jmethodID mID = (jmethodID)environ->env->GetMethodID (cppClass,"executeQueryToValue", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
229
 jmethodID mID = (jmethodID)sxn_environ->env->GetMethodID (cppClass,"executeQueryToValue", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
230 230
 if (!mID) {
231 231
        cout<<"Error: MyClassInDll."<<"executeQueryToValue"<<" not found\n"<<endl;
232 232
    } else {
......
238 238
	if(infilename!= NULL) size++;
239 239
	if(size >0) {
240 240
	   int i=0;
241
           jclass objectClass = lookForClass(environ->env, "java/lang/Object");
242
	   jclass stringClass = lookForClass(environ->env, "java/lang/String");
243
	   objectArray = environ->env->NewObjectArray( (jint)size, objectClass, 0 );
244
	   stringArray = environ->env->NewObjectArray( (jint)size, stringClass, 0 );
241
           jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
242
	   jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
243
	   objectArray = sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
244
	   stringArray = sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
245 245

  
246 246
	   if(query!= NULL) {
247
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF("qs") );
248
     	     environ->env->SetObjectArrayElement( objectArray, i, environ->env->NewStringUTF(query));
247
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF("qs") );
248
     	     sxn_environ->env->SetObjectArrayElement( objectArray, i, sxn_environ->env->NewStringUTF(query));
249 249
	     i++;	
250 250
	   }
251 251
	   if(infilename!= NULL) {
252
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF("s") );
253
     	     environ->env->SetObjectArrayElement( objectArray, i, environ->env->NewStringUTF(infilename));
252
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF("s") );
253
     	     sxn_environ->env->SetObjectArrayElement( objectArray, i, sxn_environ->env->NewStringUTF(infilename));
254 254
	     i++;	
255 255
	   }
256 256
	   for(map<std::string, XdmValue* >::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter, i++) {
257
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF( (iter->first).c_str() ) );
258
		bool checkCast = environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(proc), lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
257
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF( (iter->first).c_str() ) );
258
		bool checkCast = sxn_environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(proc), lookForClass(sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
259 259
		if(( (bool)checkCast)==false ){
260 260
			failure = "FAILURE in  array of XdmValueForCpp";
261 261
		} 
262
	     environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue(proc)) );
262
	     sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue(proc)) );
263 263
	   }
264 264
  	   for(map<std::string, std::string >::iterator iter=properties.begin(); iter!=properties.end(); ++iter, i++) {
265
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF( (iter->first).c_str()  ));
266
	     environ->env->SetObjectArrayElement( objectArray, i, (jobject)(environ->env->NewStringUTF((iter->second).c_str())) );
265
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
266
	     sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)(sxn_environ->env->NewStringUTF((iter->second).c_str())) );
267 267
	   }
268 268
	}
269 269

  
270
	  jobject result = (jobject)(environ->env->CallObjectMethod(cppXQ, mID, environ->env->NewStringUTF(cwdXQ.c_str()), stringArray, objectArray ));
271
	  environ->env->DeleteLocalRef(objectArray);
272
	  environ->env->DeleteLocalRef(stringArray);
270
	  jobject result = (jobject)(sxn_environ->env->CallObjectMethod(cppXQ, mID, sxn_environ->env->NewStringUTF(cwdXQ.c_str()), stringArray, objectArray ));
271
	  sxn_environ->env->DeleteLocalRef(objectArray);
272
	  sxn_environ->env->DeleteLocalRef(stringArray);
273 273
    if(result) {
274
		jclass atomicValueClass = lookForClass(environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
275
		jclass nodeClass = lookForClass(environ->env, "net/sf/saxon/s9api/XdmNode");
276
		jclass functionItemClass = lookForClass(environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
274
		jclass atomicValueClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
275
		jclass nodeClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
276
		jclass functionItemClass = lookForClass(sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
277 277
		XdmValue * xdmValue = NULL;
278
		if(environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
278
		if(sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
279 279
				xdmValue = new XdmAtomicValue(result);
280 280
				
281 281

  
282
			} else if(environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
282
			} else if(sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
283 283
				xdmValue = new XdmNode(result);
284 284

  
285
			} else if (environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
285
			} else if (sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
286 286
				return NULL;
287 287
			} else {
288 288
				xdmValue = new XdmValue(result);
......
294 294
			if(proc->exception != NULL) {
295 295
				delete proc->exception;
296 296
			}
297
			proc->exception = proc->checkForExceptionCPP(environ->env, cppClass, NULL);
297
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
298 298
			proc->exceptionClear();
299 299
	   		
300 300
     		} 
......
305 305

  
306 306
    const char * XQueryProcessor::executeQueryToString(const char * infilename, const char * query){
307 307
	setProperty("resources", proc->getResourcesDirectory()); 
308
 jmethodID mID = (jmethodID)environ->env->GetMethodID (cppClass,"executeQueryToString", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
308
 jmethodID mID = (jmethodID)sxn_environ->env->GetMethodID (cppClass,"executeQueryToString", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
309 309
 if (!mID) {
310 310
        cout<<"Error: MyClassInDll."<<"executeQueryToString"<<" not found\n"<<endl;
311 311
    } else {
......
317 317
	if(infilename!= NULL) size++;
318 318
	if(size >0) {
319 319
	   int i=0;
320
           jclass objectClass = lookForClass(environ->env, "java/lang/Object");
321
	   jclass stringClass = lookForClass(environ->env, "java/lang/String");
322
	   objectArray = environ->env->NewObjectArray( (jint)size, objectClass, 0 );
323
	   stringArray = environ->env->NewObjectArray( (jint)size, stringClass, 0 );
320
           jclass objectClass = lookForClass(sxn_environ->env, "java/lang/Object");
321
	   jclass stringClass = lookForClass(sxn_environ->env, "java/lang/String");
322
	   objectArray = sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
323
	   stringArray = sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
324 324

  
325 325
	   if(query!= NULL) {
326
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF("qs") );
327
     	     environ->env->SetObjectArrayElement( objectArray, i, environ->env->NewStringUTF(query));
326
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF("qs") );
327
     	     sxn_environ->env->SetObjectArrayElement( objectArray, i, sxn_environ->env->NewStringUTF(query));
328 328
	     i++;	
329 329
	   }
330 330
	   if(infilename!= NULL) {
331
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF("s") );
332
     	     environ->env->SetObjectArrayElement( objectArray, i, environ->env->NewStringUTF(infilename));
331
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF("s") );
332
     	     sxn_environ->env->SetObjectArrayElement( objectArray, i, sxn_environ->env->NewStringUTF(infilename));
333 333
	     i++;	
334 334
	   }
335 335
	   for(map<std::string, XdmValue* >::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter, i++) {
336
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF( (iter->first).c_str() ) );
337
		bool checkCast = environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(proc), lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
336
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF( (iter->first).c_str() ) );
337
		bool checkCast = sxn_environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(proc), lookForClass(sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
338 338
		if(( (bool)checkCast)==false ){
339 339
			failure = "FAILURE in  array of XdmValueForCpp";
340 340
		} 
341
	     environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue(proc)) );
341
	     sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue(proc)) );
342 342
	   }
343 343
  	   for(map<std::string, std::string >::iterator iter=properties.begin(); iter!=properties.end(); ++iter, i++) {
344
	     environ->env->SetObjectArrayElement( stringArray, i, environ->env->NewStringUTF( (iter->first).c_str()  ));
345
	     environ->env->SetObjectArrayElement( objectArray, i, (jobject)(environ->env->NewStringUTF((iter->second).c_str())) );
344
	     sxn_environ->env->SetObjectArrayElement( stringArray, i, sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
345
	     sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)(sxn_environ->env->NewStringUTF((iter->second).c_str())) );
346 346
	   }
347 347
	}
348 348

  
349
	  jstring result = (jstring)(environ->env->CallObjectMethod(cppXQ, mID, environ->env->NewStringUTF(cwdXQ.c_str()), stringArray, objectArray ));
350
	  environ->env->DeleteLocalRef(objectArray);
351
	  environ->env->DeleteLocalRef(stringArray);
349
	  jstring result = (jstring)(sxn_environ->env->CallObjectMethod(cppXQ, mID, sxn_environ->env->NewStringUTF(cwdXQ.c_str()), stringArray, objectArray ));
350
	  sxn_environ->env->DeleteLocalRef(objectArray);
351
	  sxn_environ->env->DeleteLocalRef(stringArray);
352 352

  
353 353
	  if(result) {
354
             const char * str = environ->env->GetStringUTFChars(result, NULL);
354
             const char * str = sxn_environ->env->GetStringUTFChars(result, NULL);
355 355
            //return "result should be ok";            
356 356
	    return str;
357 357
	   } else if(exceptionOccurred()) {
358 358
			if(proc->exception != NULL) {
359 359
				delete proc->exception;
360 360
			}
361
			proc->exception = proc->checkForExceptionCPP(environ->env, cppClass, NULL);
361
			proc->exception = proc->checkForExceptionCPP(sxn_environ->env, cppClass, NULL);
362 362
			proc->exceptionClear();
363 363
	   		
364 364
     		}
......
401 401
	if(proc->exception != NULL) {
402 402
		delete proc->exception;
403 403
		proc->exception = NULL;	
404
		environ->env->ExceptionClear();
404
		sxn_environ->env->ExceptionClear();
405 405
	}
406 406

  
407 407
   
......
426 426

  
427 427
const char* XQueryProcessor::checkException(){
428 428
	/*if(proc->exception == NULL) {
429
		proc->exception = proc->checkForException(environ->env, cppClass, cppXQ);
429
		proc->exception = proc->checkForException(sxn_environ->env, cppClass, cppXQ);
430 430
	}
431 431
        return proc->exception;*/
432
	return checkForException(*(environ), cppClass, cppXQ);
432
	return checkForException(*(sxn_environ), cppClass, cppXQ);
433 433
}
434 434

  
435 435

  

Also available in: Unified diff