Project

Profile

Help

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

he / latest10 / hec / Saxon.C.API / SaxonProcessor.cpp @ 250c5839

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::jvmCreatedCPP=0;
32

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

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

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

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

    
62

    
63

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

    
69

    
70

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

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

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

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

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

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

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

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

    
123

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

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

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

    
136

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

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

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

    
163
}
164

    
165

    
166

    
167
SaxonProcessor::SaxonProcessor(bool l){
168

    
169
    cwd="";
170
    licensei = l;
171
    versionStr = NULL;
172

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

    
177

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

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

    
195
}
196

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

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

    
215
SaxonProcessor::SaxonProcessor(const char * configFile){
216
    cwd="";
217
    versionStr = NULL;
218

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

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

    
229
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
230

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

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

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

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

    
266
    SaxonProcessor::~SaxonProcessor(){
267
        clearConfigurationProperties();
268
        SaxonProcessor::sxn_environ->env->NewDeleteGlobalRef(proc);
269
        if(versionStr != NULL) {
270
                delete versionStr;
271
        }
272
   }
273

    
274

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

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

    
288
        }
289

    
290
}
291

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

    
325

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

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

    
332

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

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

    
341

    
342
                                jobject xx = values[i]->getUnderlyingValue();
343

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

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

    
358
  }
359

    
360

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

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

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

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

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

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

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

    
415
                        }
416

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

    
427
                         return comboArrays;
428

    
429
                } else {
430
                    return comboArrays;
431
                }
432
    }
433

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

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

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

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

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

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

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

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

    
487
                        }
488

    
489

    
490
                         return comboArrays;
491

    
492
                } else {
493
                    return comboArrays;
494
                }
495
    }
496

    
497

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

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

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

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

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

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

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

    
550

    
551

    
552
const char * SaxonProcessor::version() {
553
     if(versionStr == NULL) {
554

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

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

    
568
    }
569

    
570
    return versionStr;
571
}
572

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

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

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

    
589
 #endif
590
}
591

    
592

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

    
612

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

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

    
630
const char * SaxonProcessor::getResourcesDirectory(){
631
        return _getResourceDirectory();
632
}
633

    
634

    
635
XdmNode * SaxonProcessor::parseXmlFromString(const char* source){
636
        
637
    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;");
638
    if (!mID) {
639
        std::cerr<<"\nError: Saxonc."<<"parseXmlString()"<<" not found"<<std::endl;
640
        return NULL;
641
    }
642
//TODO SchemaValidator
643

    
644
   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));
645
        if(xdmNodei) {
646
                XdmNode * value = new XdmNode(xdmNodei);
647
                value->setProcessor(this);
648
                return value;
649
        }   else if (exceptionOccurred()) {
650
                   exception = checkAndCreateException(saxonCAPIClass);
651
                exceptionClear();
652
       }
653
   
654
#ifdef DEBUG
655
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
656
#endif
657
 
658
   return NULL;
659
}
660

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

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

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

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

    
691

    
692

    
693
XdmNode * SaxonProcessor::parseXmlFromFile(const char* source){
694

    
695
    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;");
696
    if (!mID) {
697
        std::cerr<<"\nError: Saxonc.Dll "<<"parseXmlFile()"<<" not found"<<std::endl;
698
        return NULL;
699
    }
700
//TODO SchemaValidator
701
   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));
702
     if(exceptionOccurred()) {
703
                 exception = checkAndCreateException(saxonCAPIClass);
704
           exceptionClear();
705
                           
706
     } else {
707

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

    
715
XdmNode * SaxonProcessor::parseXmlFromUri(const char* source){
716

    
717
    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;");
718
    if (!mID) {
719
        std::cerr<<"\nError: Saxonc.Dll "<<"parseXmlFromUri()"<<" not found"<<std::endl;
720
        return NULL;
721
    }
722
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(""), SaxonProcessor::sxn_environ->env->NewStringUTF(source));
723
     if(exceptionOccurred()) {
724
           exception = checkAndCreateException(saxonCAPIClass);
725
     } else {
726
        XdmNode * value = new XdmNode(xdmNodei);
727
        value->setProcessor(this);
728
        return value;
729
   }
730
   return NULL;
731
}
732

    
733

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

    
746
   void SaxonProcessor::clearConfigurationProperties(){
747
        configProperties.clear();
748
   }
749

    
750

    
751

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

    
768

    
769

    
770

    
771
/* ========= Factory method for Xdm ======== */
772

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

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

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

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

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

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

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

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

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

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

    
895
   }
896

    
897
#if CVERSION_API_NO >= 123
898

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

    
914

    
915
         jshortArray sArray = NULL;
916

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

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

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

    
940

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

    
956

    
957
             jintArray iArray = NULL;
958

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

    
966

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

    
981
   }
982

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

    
998

    
999
             jlongArray lArray = NULL;
1000

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

    
1008

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

    
1024

    
1025

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

    
1041

    
1042
         jbooleanArray bArray = NULL;
1043

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

    
1051

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

    
1066

    
1067
   }
1068

    
1069

    
1070

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

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

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

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

    
1110

    
1111

    
1112

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

    
1119
                             int size = dataMap.size();
1120

    
1121
                             if (size > 0) {
1122

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

    
1131

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

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

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

    
1148

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

    
1151
                             }
1152

    
1153

    
1154
             }
1155

    
1156
#endif
1157

    
1158

    
(13-13/52)