Project

Profile

Help

How to connect?
Download (21.4 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / XQueryProcessor.cpp @ 7728ae0b

1
#include "XQueryProcessor.h"
2
#include "XdmValue.h"
3
#include "XdmItem.h"
4
#include "XdmNode.h"
5
#include "XdmAtomicValue.h"
6
#include "XdmFunctionItem.h"
7
#include "XdmMap.h"
8
#include "XdmArray.h"
9

    
10

    
11
#ifdef MEM_DEBUG
12
#define new new(__FILE__, __LINE__)
13
#endif
14

    
15
    XQueryProcessor::XQueryProcessor() {
16
        SaxonProcessor *p = new SaxonProcessor(false);
17
        XQueryProcessor(p, "");
18
     }
19

    
20

    
21
    XQueryProcessor::~XQueryProcessor(){
22
        clearProperties();
23
        clearParameters();
24
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(cppXQ);
25
        cwdXQ.erase();
26
        exceptionClear();
27
    }
28

    
29
    XQueryProcessor::XQueryProcessor(SaxonProcessor *p, std::string curr) {
30
    proc = p;
31
        exception = nullptr;
32
     cppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XQueryEngine");
33

    
34

    
35
    jobject tempcppXQ = createSaxonProcessor2 (SaxonProcessor::sxn_environ->env, cppClass, "(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
36
    if(tempcppXQ) {
37
        cppXQ = SaxonProcessor::sxn_environ->env->NewGlobalRef(tempcppXQ);
38
    } else {
39
        createException("Error: Failed to create the Xslt30Processor internal object");
40
        std::cerr<<"Error in XQueryProcessor XXXXXXX"<<std::endl;
41
    }
42
    
43
#ifdef DEBUG
44
        jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
45
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
46
#endif
47

    
48

    
49
   // outputfile1 = "";
50
        if(!(proc->cwd.empty()) && curr.empty()){
51
                cwdXQ = proc->cwd;
52
        } else {
53
                cwdXQ = curr;
54
        }
55
}
56

    
57

    
58

    
59
XQueryProcessor::XQueryProcessor(const XQueryProcessor &other) {
60
    cwdXQ = other.cwdXQ;
61
        proc = other.proc; //TODO check thread safety
62
        jclass  cppClass;
63
        jobject cppXQ;
64
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
65
        std::map<std::string,std::string> properties;
66

    
67

    
68
}
69

    
70

    
71
XQueryProcessor * XQueryProcessor::clone() {
72
      XQueryProcessor * proc = new XQueryProcessor(*this);
73
      return proc;
74

    
75

    
76
}
77

    
78

    
79
std::map<std::string,XdmValue*>& XQueryProcessor::getParameters(){
80
        std::map<std::string,XdmValue*>& ptr = parameters;
81
        return ptr;
82
}
83

    
84
std::map<std::string,std::string>& XQueryProcessor::getProperties(){
85
        std::map<std::string,std::string> &ptr = properties;
86
        return ptr;
87
}
88

    
89

    
90
    /**
91
     * Set the source document for the query
92
    */
93
    void XQueryProcessor::setContextItem(XdmItem * value){
94
            if(value != nullptr){
95
         value->incrementRefCount();
96
              parameters["node"] = (XdmValue *)value;
97
            }
98
    }
99

    
100

    
101
     void XQueryProcessor::declareNamespace(const char *prefix, const char * uri){
102
        if (prefix == nullptr || uri == nullptr) {
103
                    return;
104
        }  else {
105
            //setProperty("ns-prefix", uri);
106
             int s = properties.size();
107
             std::string skey = std::string("ns-prefix:") + prefix;
108
             properties.insert(std::pair<std::string, std::string>(skey, std::string(uri)));
109

    
110
             if(s == properties.size()) {
111
                 std::map<std::string, std::string>::iterator it;
112
                 it = properties.find(skey);
113
                 if (it != properties.end()) {
114
                       properties.erase(skey);
115
                       properties[skey] = std::string(uri);
116
                 }
117
             }
118

    
119
        }
120
}
121

    
122

    
123
    /**
124
     * Set the source document for the query
125
    */
126
    void XQueryProcessor::setContextItemFromFile(const char * ifile){
127
        setProperty("s", ifile);
128
    }
129

    
130
    /**
131
     * Set the output file where the result is sent
132
    */
133
    void XQueryProcessor::setOutputFile(const char* ofile){
134
      // outputfile1 = std::string(ofile); 
135
       setProperty("o", ofile);
136
    }
137

    
138
    /**
139
     * Set a parameter value used in the query
140
     *
141
     * @param name  of the parameter, as a string
142
     * @param value of the query parameter, or nullptr to clear a previously set value
143
     */
144
    void XQueryProcessor::setParameter(const char * name, XdmValue*value){
145
        if(value != nullptr){
146
                value->incrementRefCount();
147
                int s = parameters.size();
148
                std::string skey = "param:"+std::string(name);
149
                parameters[skey] = value;
150
                if(s == parameters.size()) {
151
            std::map<std::string, XdmValue*>::iterator it;
152
            it = parameters.find(skey);
153
            if (it != parameters.end()) {
154
                XdmValue * valuei = it->second;
155
                if(valuei != nullptr) {
156
                    valuei->decrementRefCount();
157
                    if (valuei->getRefCount() < 1) {
158
                        delete value;
159
                    }
160
                    parameters.erase(skey);
161
                    parameters[skey] = value;
162
                }
163
            }
164
                }
165
        } 
166
    }
167

    
168

    
169
    /**
170
     * Remove a parameter (name, value) pair
171
     *
172
     * @param namespacei currently not used
173
     * @param name  of the parameter
174
     * @return bool - outcome of the romoval
175
     */
176
    bool XQueryProcessor::removeParameter(const char * name){
177
        return (bool)(parameters.erase("param:"+std::string(name)));
178
    }
179
    /**
180
     * Set a property.
181
     *
182
     * @param name of the property
183
     * @param value of the property
184
     */
185
    void XQueryProcessor::setProperty(const char * name, const char * value){
186
#ifdef DEBUG        
187
        if(value == nullptr) {
188
                std::cerr<<"XQueryProc setProperty is nullptr"<<std::endl;
189
        }
190
#endif
191
            if(name != nullptr) {
192
                int s = properties.size();
193
                    std::string skey = std::string(name);
194
                    properties.insert(std::pair<std::string, std::string>(skey, std::string((value == nullptr ? "" : value))));
195

    
196
                    if(s == properties.size()) {
197
                std::map<std::string, std::string>::iterator it;
198
                it = properties.find(skey);
199
                if (it != properties.end()) {
200
                    properties.erase(skey);
201
                    properties[skey] = std::string((value == nullptr ? "" : value));
202
                }
203
                    }
204
            }
205

    
206

    
207

    
208
    }
209

    
210
    void XQueryProcessor::clearParameters(bool delVal){
211
        if(delVal){
212
                       for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
213
                XdmValue *value = itr->second;
214
                if (value != nullptr) {
215
#ifdef DEBUG
216
                    std::cerr<<"XQueryProc.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
217
#endif
218
                        delete value;
219
                        value = nullptr;
220
                }
221
            }
222
        }
223
        parameters.clear();
224
    }
225

    
226
   void XQueryProcessor::clearProperties(){
227
        properties.clear();
228
        //outputfile1.clear();
229
   }
230

    
231

    
232
   void XQueryProcessor::setcwd(const char* dir){
233
    cwdXQ = std::string(dir);
234
   }
235

    
236
    void XQueryProcessor::setQueryBaseURI(const char * baseURI){
237
        setProperty("base", baseURI);
238
    }
239

    
240

    
241
    void XQueryProcessor::setUpdating(bool updating){
242
     
243
            jmethodID mID =
244
                    (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass, "setUpdating",
245
                                    "(Z)V");
246
            if (!mID) {
247
            std::cerr << "Error: Saxonc library." << "setUpdating" << " not found\n"
248
                            << std::endl;
249

    
250
            } else {
251

    
252
                            SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXQ, mID,
253
                                            (jboolean)updating);
254
            }
255

    
256
    }
257

    
258
    void XQueryProcessor::executeQueryToFile(const char * infilename, const char * ofilename, const char * query){
259

    
260

    
261
        jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID (cppClass,"executeQueryToFile", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
262
         if (!mID) {
263
        std::cerr<<"Error: "<<getDllname()<<".executeQueryToFile"<<" not found\n"<<std::endl;
264
    } else {
265
        if(cppXQ == nullptr) {
266
#if defined(DEBUG)
267
            std::cerr << "The Java XQueryEngine object (i.e. cppXQ) is NULL - Possible exception thrown" << std::endl;
268
#endif
269
            createException("The Java XQueryEngine object (i.e. cppXQ) is NULL - Possible exception thrown");
270
            return;
271
        }
272
        jobjectArray stringArray = nullptr;
273
        jobjectArray objectArray = nullptr;
274

    
275
        int size = parameters.size() + properties.size();
276
        if(query!= nullptr) size++;
277
        if(infilename!= nullptr) size++;
278
        if(size >0) {
279

    
280
           int i=0;
281
           jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
282
           jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
283
           objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
284
           stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
285
           if(query!= nullptr) {
286
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("qs") );
287
                  SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(query));
288
             i++;        
289
           }
290
           if(infilename!= nullptr) {
291
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("s") );
292
                  SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(infilename));
293
             i++;        
294
           }
295
           for(std::map<std::string, XdmValue* >::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter, i++) {
296
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str() ) );
297
                bool checkCast = SaxonProcessor::sxn_environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(), lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
298

    
299
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue()) );
300
           }
301
             for(std::map<std::string, std::string >::iterator iter=properties.begin(); iter!=properties.end(); ++iter, i++) {
302
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
303
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)(SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str())) );
304
           }
305
        }
306

    
307
         SaxonProcessor::sxn_environ->env->CallVoidMethod(cppXQ, mID, SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXQ.c_str()), SaxonProcessor::sxn_environ->env->NewStringUTF(ofilename), stringArray, objectArray );
308
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
309
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
310

    
311
          if(proc->exceptionOccurred()) {
312
          createException();
313
      }
314
         
315
  }
316

    
317

    
318
   }
319

    
320

    
321
    XdmValue * XQueryProcessor::executeQueryToValue(const char * infilename, const char * query){
322

    
323
 jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID (cppClass,"executeQueryToValue", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
324
 if (!mID) {
325
        std::cerr<<"Error: MyClassInDll."<<"executeQueryToValue"<<" not found\n"<<std::endl;
326
    } else {
327
     if(cppXQ == nullptr) {
328
#if defined(DEBUG)
329
         std::cerr << "The Java XQueryEngine object (i.e. cppXQ) is NULL - Possible exception thrown" << std::endl;
330
#endif
331
         createException("The Java XQueryEngine object (i.e. cppXQ) is NULL - Possible exception thrown");
332
         return nullptr;
333
     }
334
        jobjectArray stringArray = nullptr;
335
        jobjectArray objectArray = nullptr;
336

    
337
        int size = parameters.size() + properties.size();
338
        if(query!= nullptr) size++;
339
        if(infilename!= nullptr) size++;
340
        if(size >0) {
341
           int i=0;
342
           jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
343
           jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
344
           objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
345
           stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
346

    
347
           if(query!= nullptr) {
348
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("qs") );
349
                  SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(query));
350
             i++;        
351
           }
352
           if(infilename!= nullptr) {
353
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("s") );
354
                  SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(infilename));
355
             i++;        
356
           }
357
           for(std::map<std::string, XdmValue* >::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter, i++) {
358
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str() ) );
359
                bool checkCast = SaxonProcessor::sxn_environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(), lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
360

    
361
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue()) );
362
           }
363
             for(std::map<std::string, std::string >::iterator iter=properties.begin(); iter!=properties.end(); ++iter, i++) {
364
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
365
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)(SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str())) );
366
           }
367
        }
368

    
369
          jobject result = (jobject)(SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXQ, mID, SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXQ.c_str()), stringArray, objectArray ));
370
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
371
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
372
    if(result) {
373
                jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
374
                jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
375
                jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
376
        jclass mapItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
377
                                           "net/sf/saxon/s9api/XdmMap");
378
        jclass arrayItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
379
                                             "net/sf/saxon/s9api/XdmArray");
380
                XdmValue * value = nullptr;
381
                XdmItem * xdmItem = nullptr;
382

    
383
                if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
384
                                xdmItem = new XdmAtomicValue(result);
385
                                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
386
                                return xdmItem;
387

    
388
                        } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
389
                                xdmItem = new XdmNode(result);
390
                                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
391
                                return xdmItem;
392
                        
393
                        } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
394
                xdmItem = new XdmFunctionItem(result);
395
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
396
                return xdmItem;
397
                         } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, mapItemClass) == JNI_TRUE) {
398
            xdmItem = new XdmMap(result);
399
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
400
        return xdmItem;
401
        } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, arrayItemClass) == JNI_TRUE) {
402
        xdmItem = new XdmArray(result);
403
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
404
            return xdmItem;
405
        } else {
406
                                value = new XdmValue(result, true);
407
                                return value;
408
                        }
409
                        value = new XdmValue();
410
                        value->addXdmItem(xdmItem);
411
                        return value;
412
     } else {
413
           
414
            exception = proc->checkAndCreateException(cppClass);
415
             } 
416
  }
417
  return nullptr;
418

    
419
}
420

    
421
    const char * XQueryProcessor::executeQueryToString(const char * infilename, const char * query){
422

    
423
 jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID (cppClass,"executeQueryToString", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
424
 if (!mID) {
425
        std::cerr<<"Error: MyClassInDll."<<"executeQueryToString"<<" not found\n"<<std::endl;
426
    } else {
427
     if(cppXQ == nullptr) {
428
#if defined(DEBUG)
429
         std::cerr << "The Java XQueryEngine object (i.e. cppXQ) is NULL - Possible exception thrown" << std::endl;
430
#endif
431
         createException("The Java XQueryEngine object (i.e. cppXQ) is NULL - Possible exception thrown");
432
         return nullptr;
433
     }
434
        jobjectArray stringArray = nullptr;
435
        jobjectArray objectArray = nullptr;
436

    
437
        int size = parameters.size() + properties.size();
438
        if(query!= nullptr) size++;
439
        if(infilename!= nullptr) size++;
440
        if(size >0) {
441
           int i=0;
442
           jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/Object");
443
           jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
444
           objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, objectClass, 0 );
445
           stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
446

    
447
           if(query!= nullptr) {
448
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("qs") );
449
                  SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(query));
450
             i++;        
451
           }
452
           if(infilename!= nullptr) {
453
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF("s") );
454
                  SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF(infilename));
455
             i++;        
456
           }
457
           for(std::map<std::string, XdmValue* >::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter, i++) {
458
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str() ) );
459
                bool checkCast = SaxonProcessor::sxn_environ->env->IsInstanceOf((iter->second)->getUnderlyingValue(), lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp") );
460
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)((iter->second)->getUnderlyingValue()) );
461
           }
462
             for(std::map<std::string, std::string >::iterator iter=properties.begin(); iter!=properties.end(); ++iter, i++) {
463
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
464
             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( objectArray, i, (jobject)(SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str())) );
465
           }
466
        }
467

    
468
     jbyteArray result = nullptr;
469
     jobject obj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXQ, mID, SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXQ.c_str()), stringArray, objectArray ));
470
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
471
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
472

    
473
     if (obj) {
474
         result = (jbyteArray) obj;
475
     }
476
     if (result) {
477
         jboolean isCopy = false;
478
         jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
479
         jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
480

    
481
         const char *str = new char[num_bytes];
482
         memcpy ((void *) str, b , num_bytes );
483

    
484
         SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
485
         return str;
486
     } else {
487
                    createException();
488
                           
489
                     }
490
  }
491
  return nullptr;
492

    
493

    
494
    }
495

    
496

    
497
    const char * XQueryProcessor::runQueryToString(){
498
        return executeQueryToString(nullptr, nullptr);
499

    
500
    }
501

    
502

    
503
    XdmValue * XQueryProcessor::runQueryToValue(){
504
        return executeQueryToValue(nullptr, nullptr);
505
   }
506

    
507
    void XQueryProcessor::runQueryToFile(){
508
        executeQueryToFile(nullptr, nullptr, nullptr);
509
   }
510

    
511
    void XQueryProcessor::setQueryFile(const char * ofile){
512
           //outputfile1 = std::string(ofile); 
513
           setProperty("q", ofile);
514
    }
515

    
516
   void XQueryProcessor::setQueryContent(const char* content){
517
          // outputfile1 = std::string(content); 
518
           setProperty("qs", content);
519
  }
520

    
521

    
522

    
523
void XQueryProcessor::exceptionClear(){
524
    SaxonProcessor::sxn_environ->env->ExceptionClear();
525
        if(exception != nullptr) {
526
                delete exception;
527
                exception = nullptr;
528

    
529
        }
530

    
531

    
532
   
533
 
534
}
535

    
536
bool XQueryProcessor::exceptionOccurred(){
537
    return proc->exceptionOccurred() || exception != nullptr;
538
}
539

    
540

    
541
const char * XQueryProcessor::getErrorCode() {
542
        if(exception == nullptr) {return nullptr;}
543
        return exception->getErrorCode();
544
}
545

    
546
const char * XQueryProcessor::getErrorMessage(){
547
        if(exception == nullptr) {return nullptr;}
548
        return exception->getMessage();
549
}
550

    
551
const char* XQueryProcessor::checkException(){
552
        /*if(proc->exception == nullptr) {
553
                proc->exception = proc->checkForException(SaxonProcessor::sxn_environ->env, cppClass, cppXQ);
554
        }
555
        return proc->exception;*/
556
        return proc->checkException();
557
}
558

    
559

    
560

    
561
SaxonApiException* XQueryProcessor::getException() {
562
    return exception;
563
}
564

    
565
void XQueryProcessor::createException(const char * message) {
566
    if(exception != nullptr) {
567
        delete exception;
568
        exception = nullptr;
569
    }
570
    if(message == nullptr) {
571
        exception = proc->checkAndCreateException(cppClass);
572
    } else {
573
        exception = new SaxonApiException(message);
574
    }
575

    
576
}
(22-22/56)