Project

Profile

Help

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

he / src / main / c / Saxon.C.API / Xslt30Processor.cpp @ 03fcd3f9

1
// Xslt30Processor.cpp : Defines the exported functions for the DLL application.
2
//
3

    
4
#include "Xslt30Processor.h"
5
#include "XdmValue.h"
6
#include "XdmItem.h"
7
#include "XdmNode.h"
8
#include "XdmAtomicValue.h"
9
#include "XdmFunctionItem.h"
10
#include "XsltExecutable.h"
11
#ifdef DEBUG
12
#include <typeinfo> //used for testing only
13
#endif
14

    
15
Xslt30Processor::Xslt30Processor() {
16

    
17
        SaxonProcessor *p = new SaxonProcessor(false);
18
        Xslt30Processor(p, "");
19

    
20
}
21

    
22
Xslt30Processor::Xslt30Processor(SaxonProcessor * p, std::string curr) {
23

    
24
        proc = p;
25
    tunnel = false;
26
    jitCompilation = false;
27
    exception = nullptr;
28

    
29
        /*
30
         * Look for class.
31
         */
32
        cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
33
                        "net/sf/saxon/option/cpp/Xslt30Processor");
34

    
35
        cppXT = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
36
                        "(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
37

    
38
#ifdef DEBUG
39
        jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
40
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
41
    
42
#endif
43

    
44
        if(cppXT == nullptr) {
45
            exception = proc->checkAndCreateException(cppClass);
46
        }
47

    
48
        if(!(proc->cwd.empty()) && curr.empty()){
49
                cwdXT = proc->cwd;
50
        } else if(!curr.empty()){
51
                cwdXT = curr;
52
        }
53
}
54

    
55
    Xslt30Processor::~Xslt30Processor(){
56
            clearParameters();
57
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(cppXT);
58
            cwdXT.erase();
59
    }
60

    
61

    
62
Xslt30Processor::Xslt30Processor(const Xslt30Processor &other) {
63
        proc = other.proc;
64
        cppClass = other.cppClass;
65
        cppXT = other.cppXT;
66
    cwdXT = other.cwdXT;
67
        tunnel = other.tunnel;
68

    
69
        std::map<std::string, XdmValue*>::const_iterator paramIter = other.parameters.begin();
70
    while(paramIter != other.parameters.end())
71
    {
72

    
73
       XdmValue * valuei = paramIter->second;
74
       if(valuei == nullptr) {
75
                     //std::cerr<<"Error in Xslt30Processor copy constructor"<<std::endl;
76
       } else {
77
            parameters[paramIter->first] = new XdmValue(*(valuei));
78
       }
79
       paramIter++;
80
    }
81

    
82
        jitCompilation = other.jitCompilation;
83

    
84
}
85

    
86

    
87

    
88

    
89
bool Xslt30Processor::exceptionOccurred() {
90
        return proc->exceptionOccurred() || exception != nullptr;
91
}
92

    
93
const char * Xslt30Processor::getErrorCode() {
94
 if(exception == nullptr) {return nullptr;}
95
 return exception->getErrorCode();
96
 }
97

    
98

    
99
void Xslt30Processor::setParameter(const char* name, XdmValue * value) {
100
        if(value != nullptr && name != nullptr){
101
                value->incrementRefCount();
102
                int s = parameters.size();
103
                std::string skey = ("sparam:"+std::string(name));
104
                parameters[skey] = value;
105
                if(s == parameters.size()) {
106
            std::map<std::string, XdmValue*>::iterator it;
107
            it = parameters.find(skey);
108
            if (it != parameters.end()) {
109
                XdmValue * valuei = it->second;
110
                if(valuei != nullptr) {
111
                    valuei->decrementRefCount();
112
                    if (valuei->getRefCount() < 1) {
113
                        delete value;
114
                    }
115
                    parameters.erase(skey);
116
                    parameters[skey] = value;
117
                    value->incrementRefCount();
118
                }
119
            }
120
                }
121
         }
122
}
123

    
124
XdmValue* Xslt30Processor::getParameter(const char* name) {
125
        std::map<std::string, XdmValue*>::iterator it;
126
        it = parameters.find("sparam:"+std::string(name));
127
        if (it != parameters.end())
128
          return it->second;
129
            return nullptr;
130
}
131

    
132
bool Xslt30Processor::removeParameter(const char* name) {
133
        return (bool)(parameters.erase("param:"+std::string(name)));
134
}
135

    
136
void Xslt30Processor::setJustInTimeCompilation(bool jit){
137
    jitCompilation = jit;
138
}
139

    
140

    
141
void Xslt30Processor::clearParameters(bool delValues) {
142
    std::cout<<"clearParameter" <<std::endl;
143
        if(delValues){
144
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
145
            XdmValue * value = itr->second;
146
            std::cout<<"clearParameter cp0" <<"ob ref="<<(value)<<std::endl;
147
            if(value != nullptr) {
148
                std::cout<<"clearParameter cp0-1" <<std::endl;
149
                value->decrementRefCount();
150
#ifdef DEBUG
151
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
152
#endif
153
                if (value->getRefCount() < 1) {
154
                    delete value;
155
                }
156
            }
157
            std::cout<<"clearParameter cp0-2" <<std::endl;
158
        }
159

    
160
        } else {
161
        std::cout<<"clearParameter cp1-0" <<std::endl;
162
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
163

    
164
                        XdmValue * value = itr->second;
165
            std::cout<<"clearParameter cp1" <<"ob ref="<<(value)<<std::endl;
166

    
167
            if(value == NULL) {
168
                std::cout<<"clearParameter cp1-0 after itr NULL found!!!!!" <<std::endl;
169
            }
170
                        if(value != nullptr) {
171
                std::cout<<"clearParameter cp1-1" <<std::endl;
172
                value->decrementRefCount();
173
            }
174
                
175
                }
176

    
177
        }
178
    std::cout<<"clearParameter cp1" <<std::endl;
179
        parameters.clear();
180
    std::cout<<"clearParameter cp2" <<std::endl;
181

    
182
        
183
}
184

    
185

    
186

    
187
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
188
        std::map<std::string,XdmValue*>& ptr = parameters;
189
        return ptr;
190
}
191

    
192

    
193
void Xslt30Processor::exceptionClear(){
194
 if(exception != nullptr) {
195
         delete exception;
196
         exception = nullptr;
197
        SaxonProcessor::sxn_environ->env->ExceptionClear();
198
 }
199
  
200
 }
201

    
202
   void Xslt30Processor::setcwd(const char* dir){
203
    if (dir!= nullptr) {
204
        cwdXT = std::string(dir);
205
    }
206
   }
207

    
208
SaxonApiException* Xslt30Processor::getException() {
209
    return exception;
210
}
211

    
212

    
213

    
214
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
215
        static jmethodID cAndSNodemID = nullptr;
216

    
217
        if(cAndSNodemID == nullptr) {
218
                        cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
219
                                        "compileFromXdmNodeAndSave",
220
                                        "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
221
        }
222
        if (!cAndSNodemID) {
223
                std::cerr<<"Error: "<<getDllname()<<"compileFromStringAndSave funtion not found"<<std::endl;
224

    
225
        } else {
226
        if(cppXT == nullptr) {
227
#if defined(DEBUG)
228
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
229
#endif
230
            return;
231
        }
232
                
233
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
234
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
235
                                                node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
236
                
237
                exception = proc->checkAndCreateException(cppClass);
238

    
239
    }
240

    
241

    
242

    
243
}
244

    
245
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
246
        static jmethodID cAndSStringmID = nullptr;
247
        if(cAndSStringmID == nullptr) {
248
           cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
249
                                        "compileFromStringAndSave",
250
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
251
        }
252
        if (!cAndSStringmID) {
253
                exception = new SaxonApiException("Error: compileFromStringAndSave function not found\n");
254

    
255
        } else {
256
        if(cppXT == nullptr) {
257
#if defined(DEBUG)
258
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
259
#endif
260
            return;
261
        }
262
                
263
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSStringmID,
264
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
265
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
266
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
267
                
268
                exception = proc->checkAndCreateException(cppClass);
269

    
270
    }
271
}
272

    
273

    
274

    
275
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
276
        static jmethodID cAndFStringmID =  nullptr;
277

    
278
        if (cAndFStringmID == nullptr) {
279
            cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
280
                                        "compileFromFileAndSave",
281
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
282
        }
283
        if (!cAndFStringmID) {
284
                exception = new SaxonApiException("Error: compileFromFileAndSave function not found");
285

    
286
        } else {
287

    
288
        if(cppXT == nullptr) {
289
#if defined(DEBUG)
290
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
291
#endif
292
            return;
293
        }
294
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
295
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
296
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
297

    
298
                exception = proc->checkAndCreateException(cppClass);
299

    
300

    
301
     }
302
}
303

    
304
XsltExecutable * Xslt30Processor::compileFromString(const char* stylesheetStr) {
305
        static jmethodID cStringmID = nullptr;
306
        if (cStringmID == nullptr) {
307
                        cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
308
                                        "compileFromString",
309
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
310
        }
311
                                        
312
        if (cStringmID== nullptr) {
313
                exception = new SaxonApiException(strcat(getDllname(), ".compileFromString funtion not found"));
314
                return nullptr;
315

    
316
        } else {
317
        if(cppXT == nullptr) {
318
#if defined(DEBUG)
319
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
320
#endif
321
            return nullptr;
322
        }
323
                JParameters comboArrays;
324
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
325
                jobject executableObject = (jobject)(
326
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
327
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
328
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
329
                if (!executableObject) {
330
                        exception = proc->checkAndCreateException(cppClass);
331
                        return nullptr;
332
                }
333
                if (comboArrays.stringArray != nullptr) {
334
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
335
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
336
                }
337

    
338
                jobject obj = SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
339
        XsltExecutable * executable = new XsltExecutable(obj, cwdXT);
340
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
341
                return executable;
342
        }
343

    
344
}
345

    
346
XsltExecutable * Xslt30Processor::compileFromXdmNode(XdmNode * node) {
347
        static jmethodID cNodemID = nullptr;
348
    if(cNodemID == nullptr) {
349
                        cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
350
                        "(Ljava/lang/String;Ljava/lang/Object;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
351
        }
352
        if (!cNodemID) {
353
                std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
354
                                << " not found\n" << std::endl;
355
                return nullptr;
356

    
357
        } else {
358
            if(node == nullptr) {
359
                exception = new SaxonApiException("Error in compileFromXdmNode - node argument is NULL");
360
                return nullptr;
361
            }
362
        if(cppXT == nullptr) {
363
#if defined(DEBUG)
364
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
365
#endif
366
            return nullptr;
367
        }
368
                JParameters comboArrays;
369
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
370
                jobject executableObject = (jobject)(
371
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
372
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
373
                                                node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
374
                if (!executableObject) {
375
                        exception = proc->checkAndCreateException(cppClass);
376
                        return nullptr;
377
                }
378
                if (comboArrays.stringArray != nullptr) {
379
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
380
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
381
                }
382

    
383
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
384
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
385
                return executable;
386
        }
387

    
388
}
389

    
390
XsltExecutable * Xslt30Processor::compileFromAssociatedFile(const char* source) {
391
        static jmethodID cFilemID = nullptr;
392
    if(cFilemID == nullptr) {
393
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
394
                                        "compileFromAssociatedFile",
395
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
396
        }
397
        if (!cFilemID) {
398
                std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
399
                                << " not found\n" << std::endl;
400
                return nullptr;
401

    
402
        } else {
403
                
404
                if(source == nullptr) {
405
                        exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is NULL");
406
                        return nullptr;
407
                }
408
        if(cppXT == nullptr) {
409
#if defined(DEBUG)
410
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
411
#endif
412
            return nullptr;
413
        }
414
                JParameters comboArrays;
415
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
416
                jobject executableObject = (jobject)(
417
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
418
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
419
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
420
                if (!executableObject) {
421
                        exception = proc->checkAndCreateException(cppClass);
422
                     return nullptr;
423
                }
424
                if (comboArrays.stringArray != nullptr) {
425
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
426
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
427
                }
428

    
429
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
430
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
431
                return executable;
432
        }
433

    
434
}
435

    
436

    
437
XsltExecutable * Xslt30Processor::compileFromFile(const char* stylesheet) {
438
        static jmethodID cFilemID = nullptr;
439
        if(cFilemID == nullptr) {
440
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
441
                                        "compileFromFile",
442
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
443
        }
444

    
445
        if (!cFilemID) {
446
                std::cerr << "Error: "<<getDllname() << ".compileFromFile"
447
                                << " not found\n" << std::endl;
448
        std::cerr<<"cp0 -testCatalog"<<std::endl;
449
                return nullptr;
450

    
451
        } else {
452
        if (stylesheet == nullptr) {
453
            exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is nullptr");
454
            return nullptr;
455
        }
456
        if(cppXT == nullptr) {
457
#if defined(DEBUG)
458
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
459
#endif
460

    
461
            return nullptr;
462
        }
463

    
464
        JParameters comboArrays;
465
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
466
        jobject executableObject = (jobject) (
467
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
468
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
469
                                                                           cwdXT.c_str()),
470
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
471
                                                                           stylesheet), jitCompilation,
472
                                                                   comboArrays.stringArray, comboArrays.objectArray));
473
        if (!executableObject) {
474
            exception = proc->checkAndCreateException(cppClass);
475
            return nullptr;
476

    
477
        }
478
        if (comboArrays.stringArray != nullptr) {
479
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
480
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
481
        }
482

    
483
        XsltExecutable *executable;
484
        executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject), cwdXT);
485
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
486

    
487
        return executable;
488

    
489
        }
490

    
491
}
492

    
493

    
494

    
495

    
496
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
497
                const char* stylesheetfile) {
498

    
499
        if(exceptionOccurred()) {
500
                //Possible error detected in the compile phase. Processor not in a clean state.
501
                //Require clearing exception.
502
                return nullptr;
503
        }
504

    
505
        if(sourcefile == nullptr && stylesheetfile == nullptr){
506
        
507
                return nullptr;
508
        }
509

    
510

    
511
        static jmethodID mtvID = nullptr;
512

    
513
        if(mtvID == nullptr) {
514
                        mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
515
                                        "transformToValue",
516
                                        "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
517
        }
518
        if (!mtvID) {
519
        std::cerr<<"Error: "<<getDllname()<<".transformtoValue function not found"<<std::endl;
520

    
521
        } else {
522
        if(cppXT == nullptr) {
523
#if defined(DEBUG)
524
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
525
#endif
526
            return nullptr;
527
        }
528
            JParameters comboArrays;
529
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
530

    
531
                jobject result = (jobject)(
532
                                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
533
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
534
                                                (sourcefile != nullptr ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr),
535
                                                (stylesheetfile != nullptr ?
536
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
537
                                                                                stylesheetfile) :
538
                                                                nullptr), comboArrays.stringArray, comboArrays.objectArray));
539
                if (comboArrays.stringArray != nullptr) {
540
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
541
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
542
                }
543
                if (result) {
544
                        jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
545
                          jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
546
                          jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
547
                        XdmValue * value = nullptr;
548
                          XdmItem * xdmItem = nullptr;
549

    
550

    
551
                                  if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
552
                                          xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
553
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
554
                        return xdmItem;
555

    
556
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
557
                                          xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
558
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
559
                        return xdmItem;
560
#if CVERSION_API_NO >= 123
561
                                  } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
562
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
563
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
564
                        return xdmItem;
565
#endif
566
                                  } else {
567
                                        value = new XdmValue(result, true);
568
                                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
569
                                        return value;
570
                                }
571
                                value = new XdmValue();
572
                      value->addUnderlyingValue(result);
573

    
574
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
575
                          return value;
576
                }else {
577
        
578
                        exception = proc->checkAndCreateException(cppClass);
579
                           
580
                     }
581
        }
582
        return nullptr;
583

    
584
}
585

    
586

    
587
void Xslt30Processor::transformFileToFile(const char* source,
588
                const char* stylesheet, const char* outputfile) {
589

    
590
        if(exceptionOccurred()) {
591
                //Possible error detected in the compile phase. Processor not in a clean state.
592
                //Require clearing exception.
593
                return;        
594
        }
595
        if(stylesheet==nullptr){
596
                std::cerr<< "Error: stylesheet has not been set."<<std::endl;
597
                return;
598
        }
599
        //
600
        static jmethodID mtfID = nullptr;
601

    
602
        if(mtfID == nullptr) {
603
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
604
                                        "transformToFile",
605
                                        "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
606
        }
607
        if (!mtfID) {
608
        std::cerr<<"Error: "<<getDllname()<<".transformToFile function not found"<<std::endl;
609

    
610
        } else {
611
        if(cppXT == nullptr) {
612
#if defined(DEBUG)
613
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
614
#endif
615
            return;
616
        }
617
            JParameters comboArrays;
618
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
619

    
620
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
621
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
622
                                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : nullptr),
623
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :nullptr),
624
                                                                comboArrays.stringArray, comboArrays.objectArray);
625
                if (comboArrays.stringArray!= nullptr) {
626
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
627
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
628
                }
629
                }
630
                exception = proc->checkAndCreateException(cppClass);
631
        }
632

    
633

    
634
const char * Xslt30Processor::transformFileToString(const char* source,
635
                const char* stylesheet) {
636

    
637
        if(exceptionOccurred()) {
638
                //Possible error detected in the compile phase. Processor not in a clean state.
639
                //Require clearing exception.
640
                return nullptr;
641
        }
642
        if(source == nullptr && stylesheet == nullptr){
643
                std::cerr<< "Error: nullptr file name found in transformFiletoString."<<std::endl;
644
                return nullptr;
645
        }
646

    
647
        static jmethodID mtsID =  nullptr;
648

    
649
        if(mtsID == nullptr) {
650
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
651
                                        "transformToString",
652
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
653
        }
654
        if (!mtsID) {
655
        std::cerr<<"Error: "<<getDllname()<<".transformFileToString not found"<<std::endl;
656

    
657
        } else {
658
        if(cppXT == nullptr) {
659
#if defined(DEBUG)
660
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
661
#endif
662
            return nullptr;
663
        }
664
    JParameters comboArrays;
665
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
666

    
667
        jstring result = nullptr;
668
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
669
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
670
                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
671
                                                                                                source) : nullptr),
672
                                                                (stylesheet != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : nullptr),
673
                                                                comboArrays.stringArray, comboArrays.objectArray);
674
    if (comboArrays.stringArray!= nullptr) {
675
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
676
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
677
    }
678
        if(obj) {
679
                        result = (jstring)obj;
680
        }
681

    
682
        if (result) {
683
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
684
                                        nullptr);
685
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
686
                        return str;
687
                } else  {
688
                        exception =proc->checkAndCreateException(cppClass);
689
                           
690
                     }
691
        }
692
        return nullptr;
693
}
694

    
695

    
696

    
697
const char * Xslt30Processor::getErrorMessage(){
698
         if(exception == nullptr) {return nullptr;}
699
         return exception->getMessage();
700
 }
701

    
(37-37/55)