Project

Profile

Help

Bug #4274 » SaxonProcessor.cpp

O'Neil Delpratt, 2019-08-14 00:15

 
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

    
16
#ifndef CPP_ONLY
17
/*#include "XsltProcessor.cpp"
18
#include "XQueryProcessor.cpp"
19
#include "XdmValue.cpp"*/
20
//#include "php_saxon.cpp"
21
#endif
22
//#define DEBUG
23
#ifdef DEBUG
24
#include <signal.h>
25
#endif
26
#include <stdio.h>
27

    
28

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

    
35
bool SaxonProcessor::exceptionOccurred(){
36
        bool found = SaxonProcessor::sxn_environ->env->ExceptionCheck();
37
        if(!found){
38
                if( exception != NULL){
39
                bool result =  exception->count() > 1;
40
                return result;
41
                } else {return false;}
42
        } else {
43
                return found;
44
        }
45
}
46

    
47
const char* SaxonProcessor::checkException(jobject cpp) {
48
                const char * message = NULL;                
49
                if(exception == NULL) {
50
                  message = checkForException(*sxn_environ, cpp);
51
                 } else {
52
                        message = exception->getErrorMessages();        
53
                }
54
                return message;
55
        }
56

    
57
void SaxonProcessor::checkAndCreateException(jclass cppClass){
58
                exception = NULL;
59
                if(exceptionOccurred()) {
60
                        if(exception != NULL) {
61
                                delete exception;
62
                        }
63
                exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
64
#ifdef DEBUG
65
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
66
#endif
67
                exceptionClear(false);
68
                }
69
        }
70

    
71
void SaxonProcessor::exceptionClear(bool clearCPPException){
72
        SaxonProcessor::sxn_environ->env->ExceptionClear();
73
        if(exception != NULL && clearCPPException) {
74
                delete exception;
75
        }
76
}
77

    
78
SaxonApiException * SaxonProcessor::getException(){
79
        return exception;
80
}
81

    
82
SaxonProcessor::SaxonProcessor() {
83
    licensei = false;
84
}
85

    
86

    
87

    
88
SaxonApiException * SaxonProcessor::checkForExceptionCPP(JNIEnv* env, jclass callingClass,  jobject callingObject){
89

    
90
    if(exception != NULL) {
91
        delete exception;        
92
        }
93
    if (env->ExceptionCheck()) {
94
        string result1 = "";
95
        string errorCode = "";
96
        jthrowable exc = env->ExceptionOccurred();
97

    
98
#ifdef DEBUG        
99
        env->ExceptionDescribe();
100
#endif
101
         jclass exccls(env->GetObjectClass(exc));
102
        jclass clscls(env->FindClass("java/lang/Class"));
103

    
104
        jmethodID getName(env->GetMethodID(clscls, "getName", "()Ljava/lang/String;"));
105
        jstring name(static_cast<jstring>(env->CallObjectMethod(exccls, getName)));
106
        char const* utfName(env->GetStringUTFChars(name, 0));
107
        result1 = (string(utfName));
108
        //env->ReleaseStringUTFChars(name, utfName);
109

    
110
         jmethodID  getMessage(env->GetMethodID(exccls, "getMessage", "()Ljava/lang/String;"));
111
        if(getMessage) {
112

    
113
                jstring message(static_cast<jstring>(env->CallObjectMethod(exc, getMessage)));
114
                char const* utfMessage = NULL;                
115
                if(!message) {
116
                        utfMessage = "";
117
                        return NULL;
118
                } else {
119
                        utfMessage = (env->GetStringUTFChars(message, 0));
120
                }
121
                if(utfMessage != NULL) {
122
                        result1 = (result1 + " : ") + utfMessage;
123
                } 
124
                
125
                //env->ReleaseStringUTFChars(message,utfMessage);
126
                if(callingObject != NULL && result1.compare(0,36, "net.sf.saxon.option.cpp.SaxonCException", 36) == 0){
127
                        jmethodID  getErrorCodeID(env->GetMethodID(callingClass, "getExceptions", "()[Lnet/sf/saxon/option/cpp/SaxonCException;"));
128
                        jclass saxonExceptionClass(env->FindClass("net/sf/saxon/option/cpp/SaxonCException"));
129
                                if(getErrorCodeID){        
130
                                        jobjectArray saxonExceptionObject((jobjectArray)(env->CallObjectMethod(callingObject, getErrorCodeID)));
131
                                        if(saxonExceptionObject) {
132
                                                jmethodID lineNumID = env->GetMethodID(saxonExceptionClass, "getLinenumber", "()I");
133
                                                jmethodID ecID = env->GetMethodID(saxonExceptionClass, "getErrorCode", "()Ljava/lang/String;");
134
                                                jmethodID emID = env->GetMethodID(saxonExceptionClass, "getErrorMessage", "()Ljava/lang/String;");
135
                                                jmethodID typeID = env->GetMethodID(saxonExceptionClass, "isTypeError", "()Z");
136
                                                jmethodID staticID = env->GetMethodID(saxonExceptionClass, "isStaticError", "()Z");
137
                                                jmethodID globalID = env->GetMethodID(saxonExceptionClass, "isGlobalError", "()Z");
138

    
139

    
140
                                                int exLength = (int)env->GetArrayLength(saxonExceptionObject);
141
                                                SaxonApiException * saxonExceptions = new SaxonApiException();
142
                                                for(int i=0; i<exLength;i++){
143
                                                        jobject exObj = env->GetObjectArrayElement(saxonExceptionObject, i);
144

    
145
                                                        jstring errCode = (jstring)(env->CallObjectMethod(exObj, ecID));
146
                                                        jstring errMessage = (jstring)(env->CallObjectMethod(exObj, emID));
147
                                                        jboolean isType = (env->CallBooleanMethod(exObj, typeID));
148
                                                        jboolean isStatic = (env->CallBooleanMethod(exObj, staticID));
149
                                                        jboolean isGlobal = (env->CallBooleanMethod(exObj, globalID));
150
                                                        saxonExceptions->add((errCode ? env->GetStringUTFChars(errCode,0) : NULL )  ,(errMessage ? env->GetStringUTFChars(errMessage,0) : NULL),(int)(env->CallIntMethod(exObj, lineNumID)), (bool)isType, (bool)isStatic, (bool)isGlobal);
151
                                                        //env->ExceptionDescribe();
152
                                                }
153
                                                //env->ExceptionDescribe();
154
                                                env->ExceptionClear();
155
                                                return saxonExceptions;
156
                                        }
157
                                }
158
                }
159
        }
160
        SaxonApiException * saxonExceptions = new SaxonApiException(NULL, result1.c_str());
161
        //env->ExceptionDescribe();
162
        env->ExceptionClear();
163
        return saxonExceptions;
164
     }
165
        return NULL;
166

    
167
}
168

    
169

    
170

    
171
SaxonProcessor::SaxonProcessor(bool l){
172

    
173
    cwd="";
174
    licensei = l;
175
    versionStr = NULL;
176
    SaxonProcessor::refCount++;
177
    exception = NULL;
178

    
179
     if(SaxonProcessor::jvmCreatedCPP == 0){
180
        SaxonProcessor::jvmCreatedCPP=1;
181
    SaxonProcessor::sxn_environ= new sxnc_environment;//(sxnc_environment *)malloc(sizeof(sxnc_environment));
182

    
183

    
184
    /*
185
     * First of all, load required component.
186
     * By the time of JET initialization, all components should be loaded.
187
     */
188

    
189
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
190

    
191
    /*
192
     * Initialize JET run-time.
193
     * The handle of loaded component is used to retrieve Invocation API.
194
     */
195
    initDefaultJavaRT (&SaxonProcessor::sxn_environ); 
196
    } else {
197
#ifdef DEBUG
198
     std::cerr<<"SaxonProc constructor: jvm exists!"<<std::endl;
199
#endif
200

    
201
}
202

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

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

    
220
SaxonProcessor::SaxonProcessor(const char * configFile){
221
    cwd="";
222
    versionStr = NULL;
223
    SaxonProcessor::refCount++;
224
    exception = NULL;
225

    
226
    if(SaxonProcessor::jvmCreatedCPP == 0){
227
        SaxonProcessor::jvmCreatedCPP=1;
228
    //SaxonProcessor::sxn_environ= new sxnc_environment;
229
        SaxonProcessor::sxn_environ= (sxnc_environment *)malloc(sizeof(sxnc_environment));
230

    
231
    /*
232
     * First of all, load required component.
233
     * By the time of JET initialization, all components should be loaded.
234
     */
235

    
236
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
237

    
238
    /*
239
     * Initialize JET run-time.
240
     * The handle of loaded component is used to retrieve Invocation API.
241
     */
242
    initDefaultJavaRT (&SaxonProcessor::sxn_environ); 
243
    }
244
 
245
    versionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/Version");
246

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

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

    
268
     std::cerr<<"SaxonProc constructor(configFile)"<<std::endl;
269
#endif
270
    xdmAtomicClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
271
}
272

    
273
    SaxonProcessor::~SaxonProcessor(){
274
        clearConfigurationProperties();
275
        if(versionStr != NULL) {
276
                delete versionStr;
277
        }
278
        SaxonProcessor::refCount--;        //This might be redundant due to the bug fix 2670
279
   }
280

    
281

    
282

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

    
315

    
316
SaxonProcessor& SaxonProcessor::operator=( const SaxonProcessor& other ){
317
        versionClass = other.versionClass;
318
        procClass = other.procClass;
319
        saxonCAPIClass = other.saxonCAPIClass;
320
        cwd = other.cwd;
321
        proc = other.proc;
322
        //SaxonProcessor::sxn_environ= other.environ;
323
        parameters = other.parameters;
324
        configProperties = other.configProperties;
325
        licensei = other.licensei;
326
        exception = other.exception;
327
        return *this;
328
}
329

    
330
XsltProcessor * SaxonProcessor::newXsltProcessor(){
331
    applyConfigurationProperties();
332
    return (new XsltProcessor(this, cwd));
333
}
334

    
335
XQueryProcessor * SaxonProcessor::newXQueryProcessor(){
336
    applyConfigurationProperties();
337
    return (new XQueryProcessor(this,cwd));
338
}
339

    
340
XPathProcessor * SaxonProcessor::newXPathProcessor(){
341
    applyConfigurationProperties();
342
    return (new XPathProcessor(this, cwd));
343
}
344

    
345
SchemaValidator * SaxonProcessor::newSchemaValidator(){
346
        if(licensei) {
347
                 applyConfigurationProperties();
348
                return (new SchemaValidator(this, cwd));
349
        } else {
350
                std::cerr<<"\nError: Processor is not licensed for schema processing!"<<std::endl;
351
                return NULL;
352
        }
353
}
354

    
355

    
356

    
357
const char * SaxonProcessor::version() {
358
     if(versionStr == NULL) {
359
             static jmethodID MID_version = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "getProductVersion", "(Lnet/sf/saxon/s9api/Processor;)Ljava/lang/String;");
360
            if (!MID_version) {
361
                std::cerr<<"\nError: MyClassInDll "<<"SaxonCAPI.getProductVersion()"<<" not found"<<std::endl;
362
                return NULL;
363
            }
364

    
365
            jstring jstr = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, MID_version, proc));
366
         const char * tempVersionStr = SaxonProcessor::sxn_environ->env->GetStringUTFChars(jstr, NULL);
367
         int verLen = strlen(tempVersionStr)+22+strlen(CVERSION)+1;
368
         versionStr =new char [verLen];
369
         snprintf(versionStr, verLen, "Saxon/C %s %s %s", CVERSION, "running with", tempVersionStr);
370
         delete tempVersionStr;
371

    
372
    }
373
    return versionStr;
374
}
375

    
376
void SaxonProcessor::setcwd(const char* dir){
377
    cwd = std::string(dir);
378
}
379

    
380
void SaxonProcessor::setResourcesDirectory(const char* dir){
381
        //memset(&resources_dir[0], 0, sizeof(resources_dir));
382
        strncat(_getResourceDirectory(), dir, strlen(dir));
383
}
384

    
385

    
386
void SaxonProcessor::setCatalog(const char* catalogFile, bool isTracing){
387
        jclass xmlResolverClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/trans/XmlCatalogResolver;");
388
        static jmethodID catalogMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xmlResolverClass, "setCatalog", "(Ljava/lang/String;Lnet/sf/saxon/Configuration;Z)V");
389
        
390
        if (!catalogMID) {
391
                std::cerr<<"\nError: Saxonc."<<"setCatalog()"<<" not found"<<std::endl;
392
        return;
393
        }
394
        if(catalogFile == NULL) {
395
                
396
                return;
397
        }
398
        static jmethodID configMID = SaxonProcessor::sxn_environ->env->GetMethodID(procClass, "getUnderlyingConfiguration", "()Lnet/sf/saxon/Configuration;");
399
        
400
        if (!configMID) {
401
                std::cerr<<"\nError: Saxonc."<<"getUnderlyingConfiguration()"<<" not found"<<std::endl;
402
        return;
403
        }
404

    
405

    
406
        if(!proc) {
407
                std::cout<<"proc is NULL in SaxonProcessorsetCatalog"<<std::endl;
408
                return;
409
        }
410

    
411
         jobject configObj = SaxonProcessor::sxn_environ->env->CallObjectMethod(proc, configMID);
412
          
413
        if(!configObj) {
414
                std::cout<<"proc is NULL in SaxonProcessor setcatalog - config obj"<<std::endl;
415
                return;
416
        }
417
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(xmlResolverClass, catalogMID, SaxonProcessor::sxn_environ->env->NewStringUTF(catalogFile), configObj ,(jboolean)isTracing);
418
#ifdef DEBUG
419
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
420
#endif
421
}
422

    
423

    
424
const char * SaxonProcessor::getResourcesDirectory(){
425
        return _getResourceDirectory();
426
}
427

    
428

    
429
XdmNode * SaxonProcessor::parseXmlFromString(const char* source){
430
        
431
    jmethodID mID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(saxonCAPIClass, "parseXmlString", "(Lnet/sf/saxon/s9api/Processor;Lnet/sf/saxon/s9api/SchemaValidator;Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmNode;");
432
    if (!mID) {
433
        cerr<<"\nError: MyClassInDll "<<"parseXmlString()"<<" not found"<<endl;
434
        return NULL;
435
    }
436
//TODO SchemaValidator
437

    
438
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, NULL, SaxonProcessor::sxn_environ->env->NewStringUTF(source));
439
        if(xdmNodei) {
440
                XdmNode * value = new XdmNode(xdmNodei);
441
                value->setProcessor(this);
442
                return value;
443
        }   else if (exceptionOccurred()) {
444
                   checkAndCreateException(saxonCAPIClass);
445
                exceptionClear(false);
446
       }
447
   
448
#ifdef DEBUG
449
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
450
#endif
451
 
452
   return NULL;
453
}
454

    
455
int SaxonProcessor::getNodeKind(jobject obj){
456
        jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmNode;");
457
        static jmethodID nodeKindMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,"getNodeKind", "()Lnet/sf/saxon/s9api/XdmNodeKind;");
458
        if (!nodeKindMID) {
459
                cerr << "Error: MyClassInDll." << "getNodeKind" << " not found\n"
460
                                << endl;
461
                return 0;
462
        } 
463

    
464
        jobject nodeKindObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(obj, nodeKindMID));
465
        if(!nodeKindObj) {
466
                
467
                return 0;
468
        }
469
        jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/option/cpp/XdmUtils;");
470

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

    
473
        if (!mID2) {
474
                cerr << "Error: MyClassInDll." << "convertNodeKindType" << " not found\n"
475
                                << endl;
476
                return 0;
477
        } 
478
        if(!nodeKindObj){
479
                return 0;        
480
        }
481
        int nodeKind = (long)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, mID2, nodeKindObj));
482
        return nodeKind;
483
}
484

    
485
XdmNode * SaxonProcessor::parseXmlFromFile(const char* source){
486

    
487
    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;");
488
    if (!mID) {
489
        cerr<<"\nError: MyClassInDll "<<"parseXmlFile()"<<" not found"<<endl;
490
        return NULL;
491
    }
492
//TODO SchemaValidator
493
   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));
494
     if(exceptionOccurred()) {
495
                 checkAndCreateException(saxonCAPIClass);
496
           exceptionClear(false);
497
                           
498
     } else {
499

    
500
        XdmNode * value = new XdmNode(xdmNodei);
501
        value->setProcessor(this);
502
        return value;
503
   }
504
   return NULL;
505
}
506

    
507
XdmNode * SaxonProcessor::parseXmlFromUri(const char* source){
508

    
509
    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;");
510
    if (!mID) {
511
        cerr<<"\nError: MyClassInDll "<<"parseXmlFromUri()"<<" not found"<<endl;
512
        return NULL;
513
    }
514
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(""), SaxonProcessor::sxn_environ->env->NewStringUTF(source));
515
     if(exceptionOccurred()) {
516
           checkAndCreateException(saxonCAPIClass);
517
     } else {
518
        XdmNode * value = new XdmNode(xdmNodei);
519
        value->setProcessor(this);
520
        return value;
521
   }
522
   return NULL;
523
}
524

    
525

    
526
  /**
527
     * Set a configuration property.
528
     *
529
     * @param name of the property
530
     * @param value of the property
531
     */
532
    void SaxonProcessor::setConfigurationProperty(const char * name, const char * value){
533
        if(name != NULL){
534
                configProperties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value == NULL ? "" : value))));
535
        }
536
    }
537

    
538
   void SaxonProcessor::clearConfigurationProperties(){
539
        configProperties.clear();
540
   }
541

    
542

    
543

    
544
void SaxonProcessor::release(){
545
        if(SaxonProcessor::jvmCreatedCPP!=0) {
546
                SaxonProcessor::jvmCreatedCPP =0;
547

    
548
                 finalizeJavaRT (SaxonProcessor::sxn_environ->jvm);
549

    
550
                //delete SaxonProcessor::sxn_environ;
551
        /*clearParameters();
552
        clearProperties();*/
553
} else {
554
#ifdef DEBUG
555
     std::cerr<<"SaxonProc: JVM finalize not called!"<<std::endl;
556
#endif
557
}
558
}
559

    
560

    
561

    
562

    
563
/* ========= Factory method for Xdm ======== */
564

    
565
    XdmAtomicValue * SaxonProcessor::makeStringValue(std::string str){
566
        jobject obj = getJavaStringValue(*SaxonProcessor::sxn_environ, str.c_str());
567
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
568
        jobject obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, obj));
569
        XdmAtomicValue * value = new XdmAtomicValue(obj2, "xs:string");
570
        value->setProcessor(this);
571
        return value;
572
    }
573

    
574
    XdmAtomicValue * SaxonProcessor::makeStringValue(const char * str){
575
        jobject obj = getJavaStringValue(*SaxonProcessor::sxn_environ, str);
576
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Ljava/lang/String;)V"));
577
        jobject obj2 = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, obj));
578
        XdmAtomicValue * value = new XdmAtomicValue(obj2, "xs:string");
579
        value->setProcessor(this);
580
        return value;
581
    }
582

    
583
    XdmAtomicValue * SaxonProcessor::makeIntegerValue(int i){
584
        //jobject obj = integerValue(*SaxonProcessor::sxn_environ, i);
585
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
586
        
587

    
588
        jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jlong)i));
589
        XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}integer");
590
        value->setProcessor(this);
591
        return value;
592
    }
593

    
594
    XdmAtomicValue * SaxonProcessor::makeDoubleValue(double d){
595
        //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
596
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(D)V"));
597
        jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jdouble)d));
598
        XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}double");
599
        value->setProcessor(this);
600
        return value;
601
    }
602

    
603
    XdmAtomicValue * SaxonProcessor::makeFloatValue(float d){
604
        //jobject obj = doubleValue(*SaxonProcessor::sxn_environ, d);
605
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(F)V"));
606
        jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jfloat)d));
607
        XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}float");
608
        value->setProcessor(this);
609
        return value;
610
    }
611

    
612
    XdmAtomicValue * SaxonProcessor::makeLongValue(long l){
613
        //jobject obj = longValue(*SaxonProcessor::sxn_environ, l);
614
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
615
        jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jlong)l));
616
        XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}long");
617
        value->setProcessor(this);
618
        return value;
619
    }
620

    
621
    XdmAtomicValue * SaxonProcessor::makeBooleanValue(bool b){
622
        //jobject obj = booleanValue(*SaxonProcessor::sxn_environ, b);
623
        jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(Z)V"));
624
        jobject obj = (jobject)(SaxonProcessor::sxn_environ->env->NewObject(xdmAtomicClass, mID_atomic, (jboolean)b));
625
        XdmAtomicValue * value = new XdmAtomicValue(obj, "Q{http://www.w3.org/2001/XMLSchema}boolean");
626
        value->setProcessor(this);
627
        return value;
628
    }
629

    
630
    XdmAtomicValue * SaxonProcessor::makeQNameValue(std::string str){
631
        jobject val = xdmValueAsObj(*SaxonProcessor::sxn_environ, "QName", str.c_str());
632
        XdmAtomicValue * value = new XdmAtomicValue(val, "QName");
633
        value->setProcessor(this);
634
        return value;
635
    }
636

    
637
    XdmAtomicValue * SaxonProcessor::makeAtomicValue(std::string typei, std::string strValue){
638
        jobject obj = xdmValueAsObj(*SaxonProcessor::sxn_environ, typei.c_str(), strValue.c_str());
639
        XdmAtomicValue * value = new XdmAtomicValue(obj, typei);
640
        value->setProcessor(this);
641
        return value;
642
    }
643

    
644
    const char * SaxonProcessor::getStringValue(XdmItem * item){
645
        const char *result = stringValue(*SaxonProcessor::sxn_environ, item->getUnderlyingValue());
646
#ifdef DEBUG
647
        if(result == NULL) {
648
                std::cout<<"getStringValue of XdmItem is NULL"<<std::endl;
649
        } else {
650
                std::cout<<"getStringValue of XdmItem is OK"<<std::endl;
651
        }
652
#endif
653
        return result;
654
    }
655

    
656

    
657

    
658

    
(3-3/4)