Project

Profile

Help

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

he / latest9.9 / hec / Saxon.C.API / SaxonProcessor.cpp @ 5401a5ae

1
#ifndef __linux__ 
2
#ifndef __APPLE__
3
        //#include "stdafx.h"
4
        #include <Tchar.h>
5
#endif
6
#endif
7

    
8

    
9
//#include "stdafx.h"
10
#include "SaxonProcessor.h"
11
#include "XdmValue.h"
12
#include "XdmItem.h"
13
#include "XdmNode.h"
14
#include "XdmAtomicValue.h"
15
#if CVERSION_API_NO >= 123
16
    #include "XdmFunctionItem.h"
17
    #include "XdmMap.h"
18
    #include "XdmArray.h"
19
#endif
20

    
21
//#define DEBUG
22
#ifdef DEBUG
23
#include <signal.h>
24
#endif
25
#include <stdio.h>
26

    
27

    
28
//jobject cpp;
29
const char * failure;
30
sxnc_environment * SaxonProcessor::sxn_environ = 0;
31
int SaxonProcessor::refCount = 0;
32
int SaxonProcessor::jvmCreatedCPP=0;
33

    
34
bool SaxonProcessor::exceptionOccurred(){
35
        bool found = SaxonProcessor::sxn_environ->env->ExceptionCheck();
36
        return found;
37
}
38

    
39
const char* SaxonProcessor::checkException(jobject cpp) {
40
                const char * message = NULL;
41
                message = checkForException(sxn_environ, cpp);
42
                return message;
43
        }
44

    
45
SaxonApiException * SaxonProcessor::checkAndCreateException(jclass cppClass){
46
                if(exceptionOccurred()) {
47
                    SaxonApiException * exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
48
#ifdef DEBUG
49
                    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
50
#endif
51
                    return exception;
52
                }
53
                return NULL;
54
        }
55

    
56
void SaxonProcessor::exceptionClear(){
57
        SaxonProcessor::sxn_environ->env->ExceptionClear();
58
        /* if(exception != NULL && clearCPPException) {
59
                delete exception;
60
        } */
61
}
62

    
63

    
64

    
65
SaxonProcessor::SaxonProcessor() {
66
    licensei = false;
67
    SaxonProcessor(false);
68
}
69

    
70

    
71

    
72
SaxonApiException * SaxonProcessor::checkForExceptionCPP(JNIEnv* env, jclass callingClass,  jobject callingObject){
73

    
74
    if (env->ExceptionCheck()) {
75
        std::string result1 = "";
76
        std::string errorCode = "";
77
        jthrowable exc = env->ExceptionOccurred();
78

    
79
#ifdef DEBUG        
80
        env->ExceptionDescribe();
81
#endif
82
         jclass exccls(env->GetObjectClass(exc));
83
        jclass clscls(env->FindClass("java/lang/Class"));
84

    
85
        jmethodID getName(env->GetMethodID(clscls, "getName", "()Ljava/lang/String;"));
86
        jstring name(static_cast<jstring>(env->CallObjectMethod(exccls, getName)));
87
        char const* utfName(env->GetStringUTFChars(name, 0));
88
            result1 = (std::string(utfName));
89
            env->ReleaseStringUTFChars(name, utfName);
90

    
91
         jmethodID  getMessage(env->GetMethodID(exccls, "getMessage", "()Ljava/lang/String;"));
92
        if(getMessage) {
93

    
94
                jstring message((jstring)(env->CallObjectMethod(exc, getMessage)));
95
                char const* utfMessage = NULL;                
96
                if(!message) {
97
                        utfMessage = "";
98
                        return NULL;
99
                } else {
100
                        utfMessage = (env->GetStringUTFChars(message, 0));
101
                }
102
                if(utfMessage != NULL) {
103
                        result1 = (result1 + " : ") + utfMessage;
104
                } 
105
                
106
                env->ReleaseStringUTFChars(message,utfMessage);
107

    
108
                if(callingObject != NULL && result1.compare(0,43, "net.sf.saxon.s9api.SaxonApiException", 43) == 0){
109

    
110
                        jclass saxonApiExceptionClass(env->FindClass("net/sf/saxon/s9api/SaxonApiException"));
111
                        static jmethodID lineNumID = NULL;
112
                        if(lineNumID == NULL) {
113
                            lineNumID = env->GetMethodID(saxonApiExceptionClass, "getLinenumber", "()I");
114
                        }
115
                        static jmethodID ecID = NULL;
116
                        if(ecID == NULL) {
117
                            ecID = env->GetMethodID(saxonApiExceptionClass, "getErrorCode", "()Ljnet/sf/saxon/s9api/QName;");
118
                        }
119
                        static jmethodID esysID = NULL;
120
                        if(esysID == NULL) {
121
                            esysID = env->GetMethodID(saxonApiExceptionClass, "getSystemId", "()Ljava/lang/String;");
122
                        }
123

    
124

    
125
                        jobject errCodeQName = (jobject)(env->CallObjectMethod(exc, ecID));
126
                        jstring errSystemID = (jstring)(env->CallObjectMethod(exc, esysID));
127
                        int linenum = env->CallIntMethod(exc, lineNumID);
128

    
129
                        jclass qnameClass(env->FindClass("net/sf/saxon/s9api/QName"));
130
            static jmethodID qnameStrID = NULL;
131
            if(qnameStrID == NULL) {
132
                qnameStrID = env->GetMethodID(qnameClass, "toString", "()Ljava/lang/String;");
133
            }
134

    
135
            jstring qnameStr = (jstring)(env->CallObjectMethod(errCodeQName, qnameStrID));
136

    
137

    
138
                        SaxonApiException * saxonExceptions = new SaxonApiException(result1.c_str(), (qnameStr ? env->GetStringUTFChars(qnameStr,0) : NULL)  ,(errSystemID ? env->GetStringUTFChars(errSystemID,0) : NULL),linenum);
139

    
140
            if(errCodeQName) {
141
                            env->DeleteLocalRef(errCodeQName);
142
                        }
143
                        if(errSystemID) {
144
                            env->DeleteLocalRef(errSystemID);
145
                        }
146
                        if(qnameStr) {
147
                            env->DeleteLocalRef(qnameStr);
148
                        }
149

    
150
                        if(message) {
151
                       env->DeleteLocalRef(message);
152
                           }
153
                        env->ExceptionClear();
154
                        return saxonExceptions;
155
                }
156
        }
157
        SaxonApiException * saxonExceptions = new SaxonApiException(result1.c_str());
158
        //env->ExceptionDescribe();
159
        env->ExceptionClear();
160
        return saxonExceptions;
161
     }
162
        return NULL;
163

    
164
}
165

    
166

    
167

    
168
SaxonProcessor::SaxonProcessor(bool l){
169

    
170
    cwd="";
171
    licensei = l;
172
    versionStr = NULL;
173
    SaxonProcessor::refCount++;
174

    
175
     if(SaxonProcessor::jvmCreatedCPP == 0){
176
        SaxonProcessor::jvmCreatedCPP=1;
177
    SaxonProcessor::sxn_environ= new sxnc_environment;//(sxnc_environment *)malloc(sizeof(sxnc_environment));
178

    
179

    
180
    /*
181
     * First of all, load required component.
182
     * By the time of JET initialization, all components should be loaded.
183
     */
184

    
185
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
186
        
187
    /*
188
     * Initialize JET run-time.
189
     * The handle of loaded component is used to retrieve Invocation API.
190
     */
191
    initDefaultJavaRT (SaxonProcessor::sxn_environ);
192
    } else {
193
#ifdef DEBUG
194
     std::cerr<<"SaxonProc constructor: jvm exists! jvmCreatedCPP="<<jvmCreatedCPP<<std::endl;
195
#endif
196

    
197
}
198

    
199
 
200
    versionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/Version");
201
    procClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/Processor");
202
    saxonCAPIClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/SaxonCAPI");
203
    
204
    proc = createSaxonProcessor (SaxonProcessor::sxn_environ->env, procClass, "(Z)V", NULL, licensei);
205
        if(!proc) {
206
                std::cout<<"proc is NULL in SaxonProcessor constructor"<<std::endl;
207
        }
208

    
209
    xdmAtomicClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
210
#ifdef DEBUG
211
        jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "setDebugMode", "(Z)V");
212
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(saxonCAPIClass, debugMID, (jboolean)true);
213
#endif
214
}
215

    
216
SaxonProcessor::SaxonProcessor(const char * configFile){
217
    cwd="";
218
    versionStr = NULL;
219
    SaxonProcessor::refCount++;
220

    
221
    if(SaxonProcessor::jvmCreatedCPP == 0){
222
        SaxonProcessor::jvmCreatedCPP=1;
223
    //SaxonProcessor::sxn_environ= new sxnc_environment;
224
        SaxonProcessor::sxn_environ= (sxnc_environment *)malloc(sizeof(sxnc_environment));
225

    
226
    /*
227
     * First of all, load required component.
228
     * By the time of JET initialization, all components should be loaded.
229
     */
230

    
231
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
232

    
233
    /*
234
     * Initialize JET run-time.
235
     * The handle of loaded component is used to retrieve Invocation API.
236
     */
237
    initDefaultJavaRT (SaxonProcessor::sxn_environ); 
238
    }
239
 
240
    versionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/Version");
241

    
242
    procClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/Processor");
243
    saxonCAPIClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/SaxonCAPI");
244

    
245
     static jmethodID mIDcreateProc = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,"createSaxonProcessor",
246
                                        "(Ljava/lang/String;)Lnet/sf/saxon/s9api/Processor;");
247
                if (!mIDcreateProc) {
248
                        std::cerr << "Error: SaxonDll." << "getPrimitiveTypeName"
249
                                << " not found\n" << std::endl;
250
                        return ;
251
                }
252
        proc = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDcreateProc,SaxonProcessor::sxn_environ->env->NewStringUTF(configFile));
253
                
254
        if(!proc) {
255
                checkAndCreateException(saxonCAPIClass);
256
                std::cerr << "Error: "<<getDllname() << ". processor is NULL in constructor(configFile)"<< std::endl;
257
                return ;        
258
        }
259
        
260
     licensei = true;
261
#ifdef DEBUG
262

    
263
     std::cerr<<"SaxonProc constructor(configFile)"<<std::endl;
264
#endif
265
    xdmAtomicClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
266
}
267

    
268
    SaxonProcessor::~SaxonProcessor(){
269
        clearConfigurationProperties();
270
        if(versionStr != NULL) {
271
                delete versionStr;
272
        }
273
        SaxonProcessor::refCount--;        //This might be redundant due to the bug fix 2670
274
   }
275

    
276

    
277
bool SaxonProcessor::isSchemaAwareProcessor(){
278
        if(!licensei) {
279
                return false;
280
        } else {
281
                static jmethodID MID_schema = (jmethodID)SaxonProcessor::sxn_environ->env->GetMethodID(procClass, "isSchemaAware", "()Z");
282
                    if (!MID_schema) {
283
                        std::cerr<<"\nError: Saxonc "<<"SaxonProcessor.isSchemaAware()"<<" not found"<<std::endl;
284
                        return false;
285
                    }
286

    
287
                    licensei = (jboolean)(SaxonProcessor::sxn_environ->env->CallBooleanMethod(proc, MID_schema));
288
                return licensei;
289

    
290
        }
291

    
292
}
293

    
294
void SaxonProcessor::applyConfigurationProperties(){
295
        if(configProperties.size()>0) {
296
                int size = configProperties.size();
297
                jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env, "java/lang/String");
298
                jobjectArray stringArray1 = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
299
                jobjectArray stringArray2 = SaxonProcessor::sxn_environ->env->NewObjectArray( (jint)size, stringClass, 0 );
300
                static jmethodID mIDappConfig = NULL;
301
                if(mIDappConfig == NULL) {
302
                        mIDappConfig = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass,"applyToConfiguration",
303
                                        "(Lnet/sf/saxon/s9api/Processor;[Ljava/lang/String;[Ljava/lang/String;)V");
304
                        if (!mIDappConfig) {
305
                                std::cerr << "Error: SaxonDll." << "applyToConfiguration"
306
                                << " not found\n" << std::endl;
307
                                return;
308
                        }
309
                }
310
                int i=0;
311
                std::map<std::string, std::string >::iterator iter =configProperties.begin();
312
                for(iter=configProperties.begin(); iter!=configProperties.end(); ++iter, i++) {
313
                             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray1, i, SaxonProcessor::sxn_environ->env->NewStringUTF( (iter->first).c_str()  ));
314
                             SaxonProcessor::sxn_environ->env->SetObjectArrayElement( stringArray2, i, SaxonProcessor::sxn_environ->env->NewStringUTF((iter->second).c_str()) );
315
           }
316
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDappConfig,proc, stringArray1,stringArray2);
317
                if (exceptionOccurred()) {
318
                           exception = checkAndCreateException(saxonCAPIClass);
319
                        exceptionClear();
320
                       }
321
           SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray1);
322
          SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray2);
323
                
324
        }
325
}
326

    
327

    
328
  jobjectArray SaxonProcessor::createJArray(XdmValue ** values, int length){
329
    jobjectArray valueArray = NULL;
330

    
331
    jclass xdmValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
332
                                                   "net/sf/saxon/s9api/XdmValue");
333

    
334

    
335
    valueArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) length,
336
                                                           xdmValueClass, 0);
337

    
338
    for (int i=0; i<length; i++) {
339
#ifdef DEBUG
340
                                std::string s1 = typeid(values[i]).name();
341
                                std::cerr<<"In createJArray\nType of itr:"<<s1<<std::endl;
342

    
343

    
344
                                jobject xx = values[i]->getUnderlyingValue();
345

    
346
                                if(xx == NULL) {
347
                                        std::cerr<<"value failed"<<std::endl;
348
                                } else {
349

    
350
                                        std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
351
                                }
352
                                if(values[i]->getUnderlyingValue() == NULL) {
353
                                        std::cerr<<"value["<<i<<"]->getUnderlyingValue() is NULL"<<std::endl;
354
                                }
355
#endif
356
        SaxonProcessor::sxn_environ->env->SetObjectArrayElement(valueArray, i,values[i]->getUnderlyingValue());
357
    }
358
    return valueArray;
359

    
360
  }
361

    
362

    
363
JParameters SaxonProcessor::createParameterJArray(std::map<std::string,XdmValue*> parameters, std::map<std::string,std::string> properties){
364
                JParameters comboArrays;
365
                comboArrays.stringArray = NULL;
366
                comboArrays.objectArray = NULL;
367
                jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
368
                                "java/lang/Object");
369
                jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
370
                                "java/lang/String");
371

    
372
                int size = parameters.size() + properties.size();
373
#ifdef DEBUG
374
                std::cerr<<"Properties size: "<<properties.size()<<std::endl;
375
                std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
376
#endif
377
                if (size > 0) {
378
                    
379
                        comboArrays.objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
380
                                        objectClass, 0);
381
                        comboArrays.stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
382
                                        stringClass, 0);
383
                        int i = 0;
384
                        for (std::map<std::string, XdmValue*>::iterator iter =
385
                                        parameters.begin(); iter != parameters.end(); ++iter, i++) {
386

    
387
#ifdef DEBUG
388
                                std::cerr<<"map 1"<<std::endl;
389
                                std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
390
#endif
391
                                SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
392
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
393
                                                                (iter->first).c_str()));
394
#ifdef DEBUG
395
                                std::string s1 = typeid(iter->second).name();
396
                                std::cerr<<"Type of itr:"<<s1<<std::endl;
397

    
398
                                if((iter->second) == NULL) {std::cerr<<"iter->second is null"<<std::endl;
399
                                } else {
400
                                        std::cerr<<"getting underlying value"<<std::endl;
401
                                jobject xx = (iter->second)->getUnderlyingValue();
402

    
403
                                if(xx == NULL) {
404
                                        std::cerr<<"value failed"<<std::endl;
405
                                } else {
406

    
407
                                        std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
408
                                }
409
                                if((iter->second)->getUnderlyingValue() == NULL) {
410
                                        std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
411
                                }}
412
#endif
413

    
414
                                SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
415
                                                (iter->second)->getUnderlyingValue());
416

    
417
                        }
418

    
419
                        for (std::map<std::string, std::string>::iterator iter =
420
                                        properties.begin(); iter != properties.end(); ++iter, i++) {
421
                                SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
422
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
423
                                                                (iter->first).c_str()));
424
                                SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
425
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
426
                                                                (iter->second).c_str()));
427
                        }
428

    
429
                         return comboArrays;
430

    
431
                } else {
432
                    return comboArrays;
433
                }
434
    }
435

    
436
JParameters SaxonProcessor::createParameterJArray2(std::map<std::string,XdmValue*> parameters){
437
                JParameters comboArrays;
438
                comboArrays.stringArray = NULL;
439
                comboArrays.objectArray = NULL;
440
                jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
441
                                "java/lang/Object");
442
                jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
443
                                "java/lang/String");
444

    
445
                int size = parameters.size();
446
#ifdef DEBUG
447
                std::cerr<<"Parameter size: "<<parameters.size()<<std::endl;
448
#endif
449
                if (size > 0) {
450

    
451
                        comboArrays.objectArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
452
                                        objectClass, 0);
453
                        comboArrays.stringArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
454
                                        stringClass, 0);
455
                        int i = 0;
456
                        for (std::map<std::string, XdmValue*>::iterator iter =
457
                                        parameters.begin(); iter != parameters.end(); ++iter, i++) {
458

    
459
#ifdef DEBUG
460
                                std::cerr<<"map 1"<<std::endl;
461
                                std::cerr<<"iter->first"<<(iter->first).c_str()<<std::endl;
462
#endif
463
                                SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.stringArray, i,
464
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
465
                                                                (iter->first).c_str()));
466
#ifdef DEBUG
467
                                std::string s1 = typeid(iter->second).name();
468
                                std::cerr<<"Type of itr:"<<s1<<std::endl;
469

    
470
                                if((iter->second) == NULL) {std::cerr<<"iter->second is null"<<std::endl;
471
                                } else {
472
                                        std::cerr<<"getting underlying value"<<std::endl;
473
                                jobject xx = (iter->second)->getUnderlyingValue();
474

    
475
                                if(xx == NULL) {
476
                                        std::cerr<<"value failed"<<std::endl;
477
                                } else {
478

    
479
                                        std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
480
                                }
481
                                if((iter->second)->getUnderlyingValue() == NULL) {
482
                                        std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
483
                                }}
484
#endif
485

    
486
                                SaxonProcessor::sxn_environ->env->SetObjectArrayElement(comboArrays.objectArray, i,
487
                                                (iter->second)->getUnderlyingValue());
488

    
489
                        }
490

    
491

    
492
                         return comboArrays;
493

    
494
                } else {
495
                    return comboArrays;
496
                }
497
    }
498

    
499

    
500
SaxonProcessor& SaxonProcessor::operator=( const SaxonProcessor& other ){
501
        versionClass = other.versionClass;
502
        procClass = other.procClass;
503
        saxonCAPIClass = other.saxonCAPIClass;
504
        cwd = other.cwd;
505
        proc = other.proc;
506
        //SaxonProcessor::sxn_environ= other.environ;
507
        parameters = other.parameters;
508
        configProperties = other.configProperties;
509
        licensei = other.licensei;
510
        exception = other.exception;
511
        return *this;
512
}
513

    
514
SaxonProcessor::SaxonProcessor(const SaxonProcessor &other) {
515
        versionClass = other.versionClass;
516
        procClass = other.procClass;
517
        saxonCAPIClass = other.saxonCAPIClass;
518
        cwd = other.cwd;
519
        proc = other.proc;
520
        //SaxonProcessor::sxn_environ= other.environ;
521
        parameters = other.parameters;
522
        configProperties = other.configProperties;
523
        licensei = other.licensei;
524
        exception = other.exception;
525
}
526

    
527
XsltProcessor * SaxonProcessor::newXsltProcessor(){
528
    return (new XsltProcessor(this, cwd));
529
}
530

    
531
Xslt30Processor * SaxonProcessor::newXslt30Processor(){
532
    return (new Xslt30Processor(this, cwd));
533
}
534

    
535
XQueryProcessor * SaxonProcessor::newXQueryProcessor(){
536
    return (new XQueryProcessor(this,cwd));
537
}
538

    
539
XPathProcessor * SaxonProcessor::newXPathProcessor(){
540
    return (new XPathProcessor(this, cwd));
541
}
542

    
543
SchemaValidator * SaxonProcessor::newSchemaValidator(){
544
        if(licensei) {
545
                return (new SchemaValidator(this, cwd));
546
        } else {
547
                std::cerr<<"\nError: Processor is not licensed for schema processing!"<<std::endl;
548
                return NULL;
549
        }
550
}
551

    
552

    
553

    
554
const char * SaxonProcessor::version() {
555
     if(versionStr == NULL) {
556

    
557
             static jmethodID MID_version = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "getProductVersion", "(Lnet/sf/saxon/s9api/Processor;)Ljava/lang/String;");
558
            if (!MID_version) {
559
                std::cerr<<"\nError: MyClassInDll "<<"SaxonCAPI.getProductVersion()"<<" not found"<<std::endl;
560
                return NULL;
561
            }
562

    
563
            jstring jstr = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, MID_version, proc));
564
         const char * tempVersionStr = SaxonProcessor::sxn_environ->env->GetStringUTFChars(jstr, NULL);
565
         int verLen = strlen(tempVersionStr)+22+strlen(CVERSION)+1;
566
         versionStr =new char [verLen];
567
         snprintf(versionStr, verLen, "Saxon/C %s %s %s", CVERSION, "running with", tempVersionStr);
568
         delete tempVersionStr;
569

    
570
    }
571

    
572
    return versionStr;
573
}
574

    
575
void SaxonProcessor::setcwd(const char* dir){
576
    cwd = std::string(dir);
577
}
578

    
579
const char* SaxonProcessor::getcwd(){
580
        return cwd.c_str();
581
}
582

    
583
void SaxonProcessor::setResourcesDirectory(const char* dir){
584
        //memset(&resources_dir[0], 0, sizeof(resources_dir));
585
 #if defined(__linux__) || defined (__APPLE__)
586
        strncat(_getResourceDirectory(), dir, strlen(dir));
587
 #else
588
        int destSize = strlen(dir) + strlen(dir);
589
        strncat_s(_getResourceDirectory(), destSize,dir, strlen(dir));
590

    
591
 #endif
592
}
593

    
594

    
595
void SaxonProcessor::setCatalog(const char* catalogFile, bool isTracing){
596
        jclass xmlResolverClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/trans/XmlCatalogResolver;");
597
        static jmethodID catalogMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xmlResolverClass, "setCatalog", "(Ljava/lang/String;Lnet/sf/saxon/Configuration;Z)V");
598
        
599
        if (!catalogMID) {
600
                std::cerr<<"\nError: Saxonc."<<"setCatalog()"<<" not found"<<std::endl;
601
        return;
602
        }
603
        if(catalogFile == NULL) {
604
                
605
                return;
606
        }
607
        static jmethodID configMID = SaxonProcessor::sxn_environ->env->GetMethodID(procClass, "getUnderlyingConfiguration", "()Lnet/sf/saxon/Configuration;");
608
        
609
        if (!configMID) {
610
                std::cerr<<"\nError: Saxonc."<<"getUnderlyingConfiguration()"<<" not found"<<std::endl;
611
        return;
612
        }
613

    
614

    
615
        if(!proc) {
616
                std::cout<<"proc is NULL in SaxonProcessorsetCatalog"<<std::endl;
617
                return;
618
        }
619

    
620
         jobject configObj = SaxonProcessor::sxn_environ->env->CallObjectMethod(proc, configMID);
621
          
622
        if(!configObj) {
623
                std::cout<<"proc is NULL in SaxonProcessor setcatalog - config obj"<<std::endl;
624
                return;
625
        }
626
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(xmlResolverClass, catalogMID, SaxonProcessor::sxn_environ->env->NewStringUTF(catalogFile), configObj ,(jboolean)isTracing);
627
#ifdef DEBUG
628
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
629
#endif
630
}
631

    
632
const char * SaxonProcessor::getResourcesDirectory(){
633
        return _getResourceDirectory();
634
}
635

    
636

    
637
XdmNode * SaxonProcessor::parseXmlFromString(const char* source){
638
        
639
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlString", "(Ljava/lang/String;Lnet/sf/saxon/s9api/Processor;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
640
    if (!mID) {
641
        std::cerr<<"\nError: Saxonc."<<"parseXmlString()"<<" not found"<<std::endl;
642
        return NULL;
643
    }
644
//TODO SchemaValidator
645

    
646
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, SaxonProcessor::sxn_environ->env->NewStringUTF(cwd.c_str()), proc, NULL, SaxonProcessor::sxn_environ->env->NewStringUTF(source));
647
        if(xdmNodei) {
648
                XdmNode * value = new XdmNode(xdmNodei);
649
                value->setProcessor(this);
650
                return value;
651
        }   else if (exceptionOccurred()) {
652
                   exception = checkAndCreateException(saxonCAPIClass);
653
                exceptionClear();
654
       }
655
   
656
#ifdef DEBUG
657
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
658
#endif
659
 
660
   return NULL;
661
}
662

    
663
int SaxonProcessor::getNodeKind(jobject obj){
664
        jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmNode;");
665
        static jmethodID nodeKindMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,"getNodeKind", "()Lnet/sf/saxon/s9api/XdmNodeKind;");
666
        if (!nodeKindMID) {
667
                std::cerr << "Error: MyClassInDll." << "getNodeKind" << " not found\n"
668
                                << std::endl;
669
                return 0;
670
        } 
671

    
672
        jobject nodeKindObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(obj, nodeKindMID));
673
        if(!nodeKindObj) {
674
                
675
                return 0;
676
        }
677
        jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/option/cpp/XdmUtils;");
678

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

    
681
        if (!mID2) {
682
                std::cerr << "Error: MyClassInDll." << "convertNodeKindType" << " not found\n"
683
                                << std::endl;
684
                return 0;
685
        } 
686
        if(!nodeKindObj){
687
                return 0;        
688
        }
689
        int nodeKind = (int)(SaxonProcessor::sxn_environ->env->CallStaticIntMethod(xdmUtilsClass, mID2, nodeKindObj));
690
        return nodeKind;
691
}
692

    
693

    
694

    
695
XdmNode * SaxonProcessor::parseXmlFromFile(const char* source){
696

    
697
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlFile", "(Lnet/sf/saxon/s9api/Processor;Ljava/lang/String;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
698
    if (!mID) {
699
        std::cerr<<"\nError: Saxonc.Dll "<<"parseXmlFile()"<<" not found"<<std::endl;
700
        return NULL;
701
    }
702
//TODO SchemaValidator
703
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(cwd.c_str()),  NULL, SaxonProcessor::sxn_environ->env->NewStringUTF(source));
704
     if(exceptionOccurred()) {
705
                 exception = checkAndCreateException(saxonCAPIClass);
706
           exceptionClear();
707
                           
708
     } else {
709

    
710
        XdmNode * value = new XdmNode(xdmNodei);
711
        value->setProcessor(this);
712
        return value;
713
   }
714
   return NULL;
715
}
716

    
717
XdmNode * SaxonProcessor::parseXmlFromUri(const char* source){
718

    
719
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlFile", "(Lnet/sf/saxon/s9api/Processor;Ljava/lang/String;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
720
    if (!mID) {
721
        std::cerr<<"\nError: Saxonc.Dll "<<"parseXmlFromUri()"<<" not found"<<std::endl;
722
        return NULL;
723
    }
724
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(""), SaxonProcessor::sxn_environ->env->NewStringUTF(source));
725
     if(exceptionOccurred()) {
726
           exception = checkAndCreateException(saxonCAPIClass);
727
     } else {
728
        XdmNode * value = new XdmNode(xdmNodei);
729
        value->setProcessor(this);
730
        return value;
731
   }
732
   return NULL;
733
}
734

    
735

    
736
  /**
737
     * Set a configuration property.
738
     *
739
     * @param name of the property
740
     * @param value of the property
741
     */
742
    void SaxonProcessor::setConfigurationProperty(const char * name, const char * value){
743
        if(name != NULL){
744
                configProperties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value == NULL ? "" : value))));
745
        }
746
    }
747

    
748
   void SaxonProcessor::clearConfigurationProperties(){
749
        configProperties.clear();
750
   }
751

    
752

    
753

    
754
void SaxonProcessor::release(){
755
         if(SaxonProcessor::jvmCreatedCPP!=0) {
756
                SaxonProcessor::jvmCreatedCPP =0; 
757
                //std::cerr<<"SaxonProc: JVM finalized calling !"<<std::endl;
758
                 finalizeJavaRT (SaxonProcessor::sxn_environ->jvm);
759
                 
760
                //delete SaxonProcessor::sxn_environ;
761
        /*clearParameters();
762
        clearProperties();*/
763
} else {
764
//#ifdef DEBUG
765
     std::cerr<<"SaxonProc: JVM finalize not called!"<<std::endl;
766
//#endif
767
}
768
}
769

    
770

    
771

    
772

    
773
/* ========= Factory method for Xdm ======== */
774

    
775
    XdmAtomicValue * SaxonProcessor::makeStringValue(const char * str){
776
            jobject obj = getJavaStringValue(SaxonProcessor::sxn_environ, str);
777
            static jmethodID mssID_atomic = NULL;
778
            if(mssID_atomic == NULL) {
779
                mssID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
780
            }
781
            if(!mssID_atomic) {
782
                std::cerr<<"XdmAtomic constructor (String)"<<std::endl;
783
                return NULL;
784
            }
785
            jobject obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mssID_atomic, obj));
786
            XdmAtomicValue * value = new XdmAtomicValue(obj2, "xs:string");
787
            value->setProcessor(this);
788
            return value;
789
    }
790

    
791
    XdmAtomicValue * SaxonProcessor::makeStringValue(std::string str){
792
            jobject obj = getJavaStringValue(SaxonProcessor::sxn_environ, str.c_str());
793
            static jmethodID msID_atomic = NULL;
794
            if(msID_atomic == NULL) {
795
                msID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
796
            }
797
            if(!msID_atomic) {
798
                std::cerr<<"XdmAtomic constructor (String)"<<std::endl;
799
                return NULL;
800
            }
801
            jobject obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, msID_atomic, obj));
802
            XdmAtomicValue * value = new XdmAtomicValue(obj2, "xs:string");
803
            value->setProcessor(this);
804
            return value;
805
    }
806

    
807
    XdmAtomicValue * SaxonProcessor::makeIntegerValue(int i){
808
            //jobject obj = integerValue(*SaxonProcessor::sxn_environ, i);
809
            static jmethodID miiID_atomic = NULL;
810
            if(miiID_atomic == NULL) {
811
                miiID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
812
            }
813
            if(!miiID_atomic) {
814
                std::cerr<<"XdmAtomic constructor (J)"<<std::endl;
815
                return NULL;
816
            }
817
            jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, miiID_atomic, (jlong)i));
818
            XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}integer");
819
            value->setProcessor(this);
820
            return value;
821
    }
822

    
823
    XdmAtomicValue * SaxonProcessor::makeDoubleValue(double d){
824
            //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
825
            static jmethodID mdID_atomic = NULL;
826
            if(mdID_atomic == NULL) {
827
                mdID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(D)V"));
828
            }
829
            jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mdID_atomic, (jdouble)d));
830
            XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}double");
831
            value->setProcessor(this);
832
            return value;
833
    }
834

    
835
    XdmAtomicValue * SaxonProcessor::makeFloatValue(float d){
836
            //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
837
            static jmethodID mfID_atomic = NULL;
838
            if(mfID_atomic == NULL) {
839
                mfID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(F)V"));
840
            }
841
            jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mfID_atomic, (jfloat)d));
842
            XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}float");
843
            value->setProcessor(this);
844
            return value;
845
    }
846

    
847
    XdmAtomicValue * SaxonProcessor::makeLongValue(long l){
848
            //jobject obj = longValue(*SaxonProcessor::sxn_environ, l);
849
            static jmethodID mlID_atomic = NULL;
850
            if(mlID_atomic == NULL) {
851
                mlID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
852
        }
853
            jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mlID_atomic, (jlong)l));
854
            XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}long");
855
            value->setProcessor(this);
856
            return value;
857
    }
858

    
859
    XdmAtomicValue * SaxonProcessor::makeBooleanValue(bool b){
860
            //jobject obj = booleanValue(*SaxonProcessor::sxn_environ, b);
861
            static jmethodID mID_atomic = NULL;
862
            if(mID_atomic == NULL) {
863
                mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Z)V"));
864
            }
865
            jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jboolean)b));
866
            XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}boolean");
867
            value->setProcessor(this);
868
            return value;
869
    }
870

    
871
    XdmAtomicValue * SaxonProcessor::makeQNameValue(const char* str){
872
            jobject val = xdmValueAsObj(SaxonProcessor::sxn_environ, "QName", str);
873
            XdmAtomicValue * value = new XdmAtomicValue(val, "QName");
874
            value->setProcessor(this);
875
            return value;
876
    }
877

    
878
    XdmAtomicValue * SaxonProcessor::makeAtomicValue(const char * typei, const char * strValue){
879
            jobject obj = xdmValueAsObj(SaxonProcessor::sxn_environ, typei, strValue);
880
            XdmAtomicValue * value = new XdmAtomicValue(obj, typei);
881
            value->setProcessor(this);
882
            return value;
883
    }
884

    
885
    const char * SaxonProcessor::getStringValue(XdmItem * item){
886
        const char *result = stringValue(SaxonProcessor::sxn_environ, item->getUnderlyingValue());
887
#ifdef DEBUG
888
        if(result == NULL) {
889
                std::cout<<"getStringValue of XdmItem is NULL"<<std::endl;
890
        } else {
891
                std::cout<<"getStringValue of XdmItem is OK"<<std::endl;
892
        }
893
#endif
894
    
895
        return result;
896

    
897
   }
898

    
899
#if CVERSION_API_NO >= 123
900

    
901
   XdmArray * SaxonProcessor::makeArray(short * input, int length){
902
         if(input == NULL) {
903
            std::cerr<<"Error found when converting string to XdmArray"<<std::endl;
904
            return NULL;
905
         }
906
         jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmArray;");
907
         static jmethodID mmssID = NULL;
908
         if(mmssID == NULL) {
909
            mmssID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([S)Lnet/sf/saxon/s9api/XdmArray;");
910
         }
911
         if (!mmssID) {
912
            std::cerr<<"\nError: Saxonc.Dll "<<"makeArray([S)"<<" not found"<<std::endl;
913
            return NULL;
914
         }
915

    
916

    
917
         jshortArray sArray = NULL;
918

    
919
         sArray = SaxonProcessor::sxn_environ->env->NewShortArray((jint) length);
920
         jshort fill[length];
921
         for (int i=0; i<length; i++) {
922
            fill[i] =input[i];
923
         }
924
         SaxonProcessor::sxn_environ->env->SetShortArrayRegion(sArray, 0, length, fill);
925

    
926
         jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmssID, sArray);
927
         if(!xdmArrayi) {
928
            std::cerr<<"Error found when converting string to XdmArray";
929
            return NULL;
930
         }
931

    
932
         if(exceptionOccurred()) {
933
                    exception = checkAndCreateException(saxonCAPIClass);
934
         } else {
935
                 XdmArray * value = new XdmArray(xdmArrayi, length);
936
                 value->setProcessor(this);
937
                 return value;
938
         }
939
         return NULL;
940
   }
941

    
942

    
943
   XdmArray * SaxonProcessor::makeArray(int * input, int length){
944
           if(input == NULL) {
945
                   std::cerr<<"Error found when converting string to XdmArray";
946
                   return NULL;
947
           }
948
         jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmArray;");
949
         static jmethodID mmiiID = NULL;
950
         if(mmiiID == NULL) {
951
            mmiiID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([I)Lnet/sf/saxon/s9api/XdmArray;");
952
         }
953
         if (!mmiiID) {
954
                 std::cerr<<"\nError: Saxonc.Dll "<<"makeArray([I)"<<" not found"<<std::endl;
955
                 return NULL;
956
             }
957

    
958

    
959
             jintArray iArray = NULL;
960

    
961
             iArray = SaxonProcessor::sxn_environ->env->NewIntArray((jint) length);
962
             jint fill[length];
963
             for (int i=0; i<length; i++) {
964
                fill[i] =input[i];
965
             }
966
             SaxonProcessor::sxn_environ->env->SetIntArrayRegion(iArray, 0, length, fill);
967

    
968

    
969
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmiiID, iArray);
970
        if(!xdmArrayi) {
971
            std::cerr<<"Error found when converting string to XdmArray";
972
            return NULL;
973
        }
974
              if(exceptionOccurred()) {
975
                    exception = checkAndCreateException(saxonCAPIClass);
976
              } else {
977
                 XdmArray * value = new XdmArray(xdmArrayi, length);
978
                 value->setProcessor(this);
979
                 return value;
980
            }
981
            return NULL;
982

    
983
   }
984

    
985
   XdmArray * SaxonProcessor::makeArray(long * input, int length){
986
           if(input == NULL) {
987
                   std::cerr<<"Error found when converting string to XdmArray";
988
                   return NULL;
989
           }
990
         jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmArray;");
991
         static jmethodID mmiID = NULL;
992
         if(mmiID == NULL) {
993
            mmiID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([J)Lnet/sf/saxon/s9api/XdmArray;");
994
         }
995
             if (!mmiID) {
996
                 std::cerr<<"\nError: Saxonc.Dll "<<"makeArray([J)"<<" not found"<<std::endl;
997
                 return NULL;
998
             }
999

    
1000

    
1001
             jlongArray lArray = NULL;
1002

    
1003
             lArray = SaxonProcessor::sxn_environ->env->NewLongArray((jint) length);
1004
             jlong fill[length];
1005
             for (int i=0; i<length; i++) {
1006
                fill[i] =input[i];
1007
             }
1008
             SaxonProcessor::sxn_environ->env->SetLongArrayRegion(lArray, 0, length, fill);
1009

    
1010

    
1011
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmiID, lArray);
1012
        if(!xdmArrayi) {
1013
            std::cerr<<"Error found when converting string to XdmArray";
1014
            return NULL;
1015
        }
1016
              if(exceptionOccurred()) {
1017
                    exception = checkAndCreateException(saxonCAPIClass);
1018
              } else {
1019
                 XdmArray * value = new XdmArray(xdmArrayi, length);
1020
                 value->setProcessor(this);
1021
                 return value;
1022
            }
1023
            return NULL;
1024
   }
1025

    
1026

    
1027

    
1028
   XdmArray * SaxonProcessor::makeArray(bool * input, int length){
1029
         if(input == NULL) {
1030
                   std::cerr<<"Error found when converting string to XdmArray";
1031
                   return NULL;
1032
         }
1033
         jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmArray;");
1034
         static jmethodID mmbID = NULL;
1035
         if(mmbID == NULL) {
1036
            mmbID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([Z)Lnet/sf/saxon/s9api/XdmArray;");
1037
         }
1038
         if (!mmbID) {
1039
                 std::cerr<<"\nError: Saxonc.Dll "<<"makeArray([Z)"<<" not found"<<std::endl;
1040
            return NULL;
1041
         }
1042

    
1043

    
1044
         jbooleanArray bArray = NULL;
1045

    
1046
         bArray = SaxonProcessor::sxn_environ->env->NewBooleanArray((jint) length);
1047
         jboolean fill[length];
1048
         for (int i=0; i<length; i++) {
1049
            fill[i] =input[i];
1050
         }
1051
         SaxonProcessor::sxn_environ->env->SetBooleanArrayRegion(bArray, 0, length, fill);
1052

    
1053

    
1054
         jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmbID, bArray);
1055
         if(!xdmArrayi) {
1056
            std::cerr<<"Error found when converting string to XdmArray";
1057
            return NULL;
1058
         }
1059
         if(exceptionOccurred()) {
1060
            exception = checkAndCreateException(saxonCAPIClass);
1061
         } else {
1062
                 XdmArray * value = new XdmArray(xdmArrayi, length);
1063
                 value->setProcessor(this);
1064
                 return value;
1065
            }
1066
            return NULL;
1067

    
1068

    
1069
   }
1070

    
1071

    
1072

    
1073
   XdmArray * SaxonProcessor::makeArray(const char ** input, int length){
1074
        if(input == NULL || length <= 0) {
1075
                std::cerr<<"Error found when converting string to XdmArray";
1076
                return NULL;
1077
        }
1078
               jobject obj = NULL;
1079
               jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmArray;");
1080
               jmethodID mmID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmArray;");
1081

    
1082
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
1083
        jobjectArray valueArray = NULL;
1084
        jobject obj2 = NULL;
1085
        valueArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) length, xdmAtomicClass, 0);
1086
        for(int i = 0; i< length; i++) {
1087
            if(input[i] == NULL) {
1088
                std::cerr<<"Error found when converting string to XdmArray";
1089
                return NULL;
1090
            }
1091
            obj = getJavaStringValue(SaxonProcessor::sxn_environ, input[i]);
1092
            obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, obj));
1093
            SaxonProcessor::sxn_environ->env->SetObjectArrayElement(valueArray, i,obj2);
1094
        }
1095

    
1096
        jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmID, valueArray);
1097
        if(!xdmArrayi) {
1098
            std::cerr<<"Error found when converting string to XdmArray";
1099
            return NULL;
1100
        }
1101

    
1102
        if(exceptionOccurred()) {
1103
            checkAndCreateException(saxonCAPIClass);
1104
        } else {
1105
            XdmArray * value = new XdmArray(xdmArrayi, length);
1106
                   value->setProcessor(this);
1107
            return value;
1108
        }
1109
        return NULL;
1110
       }
1111

    
1112

    
1113

    
1114

    
1115
    XdmMap * makeMap(std::map<XdmAtomicValue *, XdmValue*> dataMap) {
1116
                             jobjectArray keyArray = NULL;
1117
                             jobjectArray valueArray = NULL;
1118
                             jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
1119
                                             "java/lang/Object");
1120

    
1121
                             int size = dataMap.size();
1122

    
1123
                             if (size > 0) {
1124

    
1125
                                     keyArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
1126
                                                     objectClass, 0);
1127
                                     valueArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) size,
1128
                                                     objectClass, 0);
1129
                                     int i = 0;
1130
                                     for (std::map<XdmAtomicValue *, XdmValue*>::iterator iter =
1131
                                                     dataMap.begin(); iter != dataMap.end(); ++iter, i++) {
1132

    
1133

    
1134
                             SaxonProcessor::sxn_environ->env->SetObjectArrayElement(keyArray, i,
1135
                                                             (iter->first)->getUnderlyingValue());
1136

    
1137
                                             SaxonProcessor::sxn_environ->env->SetObjectArrayElement(valueArray, i,
1138
                                                             (iter->second)->getUnderlyingValue());
1139

    
1140
                                     }
1141
                        jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
1142
                                jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"makeXdmMap",
1143
                                                                "([Lnet/sf/saxon/s9api/XdmAtomicValue;[Lnet/sf/saxon/s9api/XdmValue;)Lnet/sf/saxon/s9api/XdmMap;");
1144
                                if (!xmID) {
1145
                                                std::cerr << "Error: SaxonDll." << "makeXdmMap"
1146
                                                        << " not found\n" << std::endl;
1147
                                                return;
1148
                                        }
1149

    
1150

    
1151
                                jobject results = (jobject)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,keyArray, valueArray));
1152

    
1153
                             }
1154

    
1155

    
1156
             }
1157

    
1158
#endif
1159

    
1160

    
(13-13/52)