Project

Profile

Help

Revision 5401a5ae

Added by O'Neil Delpratt almost 2 years ago

Saxon/C Development

View differences:

latest9.9/hec/Saxon.C.API/SaxonApiException.cpp
1
// SaxonApiException.cpp : Defines the exported functions for the DLL application.
2
//
3

  
4
#include "SaxonApiException.h"
5

  
6

  
7

  
8
  const char * SaxonApiException::what () {
9
        return message.c_str();
10
  }
11

  
12
  SaxonApiException::SaxonApiException(){
13
	    message = "";
14
	    lineNumber = -1;
15
	    errorCode = "";
16
	    systemId = "";
17
    }
18

  
19

  
20
	SaxonApiException::SaxonApiException(const SaxonApiException &ex){
21
		message = ex.message;
22
		lineNumber = ex.lineNumber;
23
		errorCode = ex.errorCode;
24
		systemId = ex.systemId;
25
	}
26

  
27

  
28
	SaxonApiException::SaxonApiException(const char * m, const char * ec, const char * sysId, int linenumber){
29
		if(m != NULL) {
30
		    message = std::string(m);
31
		} else {
32
		    message = "";
33
		}
34

  
35
        lineNumber = linenumber;
36

  
37
        if (ec != NULL) {
38
            errorCode = std::string(ec);
39
        } else {
40
            errorCode = "";
41
        }
42

  
43
        if(sysId != NULL) {
44
            systemId = sysId;
45
        } else {
46
            systemId = "";
47
        }
48
	}
49

  
50

  
51

  
52

  
53
    /**
54
     * A destructor.
55
     */
56
	SaxonApiException::~SaxonApiException() throw {
57
        message.clear();
58
        errorCode.clear();
59
        systemId.clear();
60
	}
61

  
62
    /**
63
     * Get the error code associated with the ith exception in the vector, if there is one
64
     * @param i - ith exception in the vector
65
     * @return the associated error code, or null if no error code is available
66
     */
67
	const char * SaxonApiException::getErrorCode(){
68
		return errorCode.c_str();
69
	}
70

  
71

  
72
	int SaxonApiException::getLineNumber(){
73
        return lineNumber;
74
	}
75

  
76

  
77
    const char * SaxonApiException::getSystemId() {
78
        return systemId.c_str();
79
    }
80

  
81
	const char * SaxonApiException::getMessage(){
82
	    return message.c_str();
83

  
84
	}
latest9.9/hec/Saxon.C.API/SaxonApiException.h
1
#ifndef SAXON_API_EXCEPTION_H
2
#define SAXON_API_EXCEPTION_H
3

  
4
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5
// Copyright (c) 2020 Saxonica Limited.
6
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
9
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10

  
11
#include <iostream>
12
#include <exception>
13

  
14

  
15
/*! <code>SaxonApiException</code>. An exception thrown by the Saxon s9api API (Java). This is always a C++ wrapper for some other underlying exception in Java
16
 * <p/>
17
 */
18
class SaxonApiException: public std::exception {
19

  
20
public:
21

  
22
    /**
23
     * A default Constructor. Create a SaxonApiException
24
     */
25
     SaxonApiException();
26

  
27

  
28
         /**
29
          * A constructor. Create a SaxonApiException
30
          * @param message - The detail message string of this throwable.
31
          */
32
     explicit SaxonApiException(const char * message);
33

  
34
    /**
35
     * A Copy constructor. Create a SaxonApiException
36
     * @param ex - The exception object to copy
37
     */
38
	SaxonApiException(const SaxonApiException &ex);
39

  
40

  
41

  
42
    /** Returns a pointer to the (constant) error description.
43
        *  @return A pointer to a const char*. The underlying memory
44
        *          is in posession of the Exception object. Callers must
45
        *          not attempt to free the memory.
46
             */
47
    virtual const char * what ();
48

  
49
    /**
50
     * A constructor. Create a SaxonApiException
51
     * @param message - The detail message string of this throwable.
52
     * @param errorCode - The error code of the underlying exception thrown, if known
53
     * @param systemId - Get the URI of the module associated with the exception, if known.
54
     * @param lineNumber - The line number in the stylesheet related to cause of the exception
55
     */
56
	SaxonApiException(const char * message, const char * errorCode, const char * systemId, int linenumber);
57

  
58

  
59
    /**
60
     * A destructor.
61
     */
62
	virtual ~SaxonApiException() throw ();
63

  
64

  
65

  
66
    /**
67
     * Get the error code associated with the exception, if it exists
68
     * @return the associated error code, or null if no error code is available
69
     */
70
	const char * getErrorCode();
71

  
72

  
73
	int getLineNumber();
74

  
75

  
76
    /**
77
     * Returns the detail message string of the throwable, if there is one
78
     * @return the detail message string of this <tt>Throwable</tt> instance
79
     *         (which may be <tt>null</tt>).
80
     */
81
	const char * getMessage();
82

  
83
	/**
84
	* Get the URI of the module associated with the exception, if known.
85
	*/
86
	const char * getSystemId();
87

  
88

  
89

  
90

  
91
private:
92
	std::string message;
93
	int lineNumber;
94
	std::string errorCode;
95
	std::string systemId;
96
};
97

  
98
#endif /* SAXON_API_EXCEPTION_H */
latest9.9/hec/Saxon.C.API/SaxonProcessor.cpp
12 12
#include "XdmItem.h"
13 13
#include "XdmNode.h"
14 14
#include "XdmAtomicValue.h"
15
#if CVERSION_API_NO >= 123
16
    #include "XdmFunctionItem.h"
17
    #include "XdmMap.h"
18
    #include "XdmArray.h"
19
#endif
15 20

  
16 21
//#define DEBUG
17 22
#ifdef DEBUG
......
28 33

  
29 34
bool SaxonProcessor::exceptionOccurred(){
30 35
	bool found = SaxonProcessor::sxn_environ->env->ExceptionCheck();
31
	if(!found){
32
		if( exception != NULL){
33
		bool result =  exception->count() > 1;
34
		return result;
35
		} else {return false;}
36
	} else {
37
		return found;
38
	}
36
	return found;
39 37
}
40 38

  
41 39
const char* SaxonProcessor::checkException(jobject cpp) {
42
		const char * message = NULL;		
43
		if(exception == NULL) {
44
		  message = checkForException(sxn_environ, cpp);
45
	 	} else {
46
			message = exception->getErrorMessages();	
47
		}
40
		const char * message = NULL;
41
		message = checkForException(sxn_environ, cpp);
48 42
		return message;
49 43
	}
50 44

  
51
void SaxonProcessor::checkAndCreateException(jclass cppClass){
52
		exception = NULL;
45
SaxonApiException * SaxonProcessor::checkAndCreateException(jclass cppClass){
53 46
		if(exceptionOccurred()) {
54
			if(exception != NULL) {
55
				delete exception;
56
			}
57
		exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
47
		    SaxonApiException * exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, NULL);
58 48
#ifdef DEBUG
59
		SaxonProcessor::sxn_environ->env->ExceptionDescribe();
49
		    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
60 50
#endif
61
		exceptionClear(false);
51
		    return exception;
62 52
		}
53
		return NULL;
63 54
	}
64 55

  
65
void SaxonProcessor::exceptionClear(bool clearCPPException){
56
void SaxonProcessor::exceptionClear(){
66 57
	SaxonProcessor::sxn_environ->env->ExceptionClear();
67
	if(exception != NULL && clearCPPException) {
58
	/* if(exception != NULL && clearCPPException) {
68 59
		delete exception;
69
	}
60
	} */
70 61
}
71 62

  
72
SaxonApiException * SaxonProcessor::getException(){
73
	return exception;
74
}
63

  
75 64

  
76 65
SaxonProcessor::SaxonProcessor() {
77 66
    licensei = false;
78
    SaxonProcessor(licensei);
67
    SaxonProcessor(false);
79 68
}
80 69

  
81 70

  
82 71

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

  
85
    if(exception != NULL) {
86
	delete exception;	
87
	}
88 74
    if (env->ExceptionCheck()) {
89 75
	std::string result1 = "";
90 76
	std::string errorCode = "";
......
99 85
        jmethodID getName(env->GetMethodID(clscls, "getName", "()Ljava/lang/String;"));
100 86
        jstring name(static_cast<jstring>(env->CallObjectMethod(exccls, getName)));
101 87
        char const* utfName(env->GetStringUTFChars(name, 0));
102
	result1 = (std::string(utfName));
103
	//env->ReleaseStringUTFChars(name, utfName);
88
	    result1 = (std::string(utfName));
89
	    env->ReleaseStringUTFChars(name, utfName);
104 90

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

  
108
		jstring message(static_cast<jstring>(env->CallObjectMethod(exc, getMessage)));
94
		jstring message((jstring)(env->CallObjectMethod(exc, getMessage)));
109 95
		char const* utfMessage = NULL;		
110 96
		if(!message) {
111 97
			utfMessage = "";
......
117 103
			result1 = (result1 + " : ") + utfMessage;
118 104
		} 
119 105
		
120
		//env->ReleaseStringUTFChars(message,utfMessage);
121
		if(callingObject != NULL && result1.compare(0,36, "net.sf.saxon.option.cpp.SaxonCException", 36) == 0){
122
			jmethodID  getErrorCodeID(env->GetMethodID(callingClass, "getExceptions", "()[Lnet/sf/saxon/option/cpp/SaxonCException;"));
123
			jclass saxonExceptionClass(env->FindClass("net/sf/saxon/option/cpp/SaxonCException"));
124
				if(getErrorCodeID){	
125
					jobjectArray saxonExceptionObject((jobjectArray)(env->CallObjectMethod(callingObject, getErrorCodeID)));
126
					if(saxonExceptionObject) {
127
						jmethodID lineNumID = env->GetMethodID(saxonExceptionClass, "getLinenumber", "()I");
128
						jmethodID ecID = env->GetMethodID(saxonExceptionClass, "getErrorCode", "()Ljava/lang/String;");
129
						jmethodID emID = env->GetMethodID(saxonExceptionClass, "getErrorMessage", "()Ljava/lang/String;");
130
						jmethodID typeID = env->GetMethodID(saxonExceptionClass, "isTypeError", "()Z");
131
						jmethodID staticID = env->GetMethodID(saxonExceptionClass, "isStaticError", "()Z");
132
						jmethodID globalID = env->GetMethodID(saxonExceptionClass, "isGlobalError", "()Z");
133

  
134

  
135
						int exLength = (int)env->GetArrayLength(saxonExceptionObject);
136
						SaxonApiException * saxonExceptions = new SaxonApiException();
137
						for(int i=0; i<exLength;i++){
138
							jobject exObj = env->GetObjectArrayElement(saxonExceptionObject, i);
139

  
140
							jstring errCode = (jstring)(env->CallObjectMethod(exObj, ecID));
141
							jstring errMessage = (jstring)(env->CallObjectMethod(exObj, emID));
142
							jboolean isType = (env->CallBooleanMethod(exObj, typeID));
143
							jboolean isStatic = (env->CallBooleanMethod(exObj, staticID));
144
							jboolean isGlobal = (env->CallBooleanMethod(exObj, globalID));
145
							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);
146
							//env->ExceptionDescribe();
147
						}
148
						//env->ExceptionDescribe();
149
						env->ExceptionClear();
150
						return saxonExceptions;
151
					}
152
				}
106
		env->ReleaseStringUTFChars(message,utfMessage);
107

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

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

  
124

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

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

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

  
137

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

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

  
150
			if(message) {
151
           	    env->DeleteLocalRef(message);
152
   			}
153
			env->ExceptionClear();
154
			return saxonExceptions;
153 155
		}
154 156
	}
155
	SaxonApiException * saxonExceptions = new SaxonApiException(NULL, result1.c_str());
157
	SaxonApiException * saxonExceptions = new SaxonApiException(result1.c_str());
156 158
	//env->ExceptionDescribe();
157 159
	env->ExceptionClear();
158 160
	return saxonExceptions;
......
169 171
    licensei = l;
170 172
    versionStr = NULL;
171 173
    SaxonProcessor::refCount++;
172
    exception = NULL;
173 174

  
174 175
     if(SaxonProcessor::jvmCreatedCPP == 0){
175 176
	SaxonProcessor::jvmCreatedCPP=1;
......
216 217
    cwd="";
217 218
    versionStr = NULL;
218 219
    SaxonProcessor::refCount++;
219
    exception = NULL;
220 220

  
221 221
    if(SaxonProcessor::jvmCreatedCPP == 0){
222 222
	SaxonProcessor::jvmCreatedCPP=1;
......
315 315
	   }
316 316
		SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mIDappConfig,proc, stringArray1,stringArray2);
317 317
		if (exceptionOccurred()) {
318
	   		checkAndCreateException(saxonCAPIClass);
319
			exceptionClear(false);
318
	   		exception = checkAndCreateException(saxonCAPIClass);
319
			exceptionClear();
320 320
      		 }
321 321
 	  SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray1);
322 322
	  SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray2);
......
433 433
		}
434 434
    }
435 435

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

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

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

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

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

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

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

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

  
489
			}
490

  
491

  
492
			 return comboArrays;
493

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

  
436 499

  
437 500
SaxonProcessor& SaxonProcessor::operator=( const SaxonProcessor& other ){
438 501
	versionClass = other.versionClass;
......
448 511
	return *this;
449 512
}
450 513

  
451
SaxonProcessor(const SaxonProcessor &other) {
514
SaxonProcessor::SaxonProcessor(const SaxonProcessor &other) {
452 515
	versionClass = other.versionClass;
453 516
	procClass = other.procClass;
454 517
	saxonCAPIClass = other.saxonCAPIClass;
......
462 525
}
463 526

  
464 527
XsltProcessor * SaxonProcessor::newXsltProcessor(){
465
    applyConfigurationProperties();
466 528
    return (new XsltProcessor(this, cwd));
467 529
}
468 530

  
469 531
Xslt30Processor * SaxonProcessor::newXslt30Processor(){
470
    applyConfigurationProperties();
471 532
    return (new Xslt30Processor(this, cwd));
472 533
}
473 534

  
474 535
XQueryProcessor * SaxonProcessor::newXQueryProcessor(){
475
    applyConfigurationProperties();
476 536
    return (new XQueryProcessor(this,cwd));
477 537
}
478 538

  
479 539
XPathProcessor * SaxonProcessor::newXPathProcessor(){
480
    applyConfigurationProperties();
481 540
    return (new XPathProcessor(this, cwd));
482 541
}
483 542

  
484 543
SchemaValidator * SaxonProcessor::newSchemaValidator(){
485 544
	if(licensei) {
486
 		applyConfigurationProperties();
487 545
		return (new SchemaValidator(this, cwd));
488 546
	} else {
489 547
		std::cerr<<"\nError: Processor is not licensed for schema processing!"<<std::endl;
......
591 649
		value->setProcessor(this);
592 650
		return value;
593 651
	}   else if (exceptionOccurred()) {
594
	   	checkAndCreateException(saxonCAPIClass);
595
		exceptionClear(false);
652
	   	exception = checkAndCreateException(saxonCAPIClass);
653
		exceptionClear();
596 654
       }
597 655
   
598 656
#ifdef DEBUG
......
644 702
//TODO SchemaValidator
645 703
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(cwd.c_str()),  NULL, SaxonProcessor::sxn_environ->env->NewStringUTF(source));
646 704
     if(exceptionOccurred()) {
647
	 	checkAndCreateException(saxonCAPIClass);
648
	   exceptionClear(false);
705
	 	exception = checkAndCreateException(saxonCAPIClass);
706
	   exceptionClear();
649 707
	   		
650 708
     } else {
651 709

  
......
665 723
    }
666 724
   jobject xdmNodei = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(saxonCAPIClass, mID, proc, SaxonProcessor::sxn_environ->env->NewStringUTF(""), SaxonProcessor::sxn_environ->env->NewStringUTF(source));
667 725
     if(exceptionOccurred()) {
668
	   checkAndCreateException(saxonCAPIClass);
726
	   exception = checkAndCreateException(saxonCAPIClass);
669 727
     } else {
670 728
	XdmNode * value = new XdmNode(xdmNodei);
671 729
	value->setProcessor(this);
......
715 773
/* ========= Factory method for Xdm ======== */
716 774

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

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

  
735 807
    XdmAtomicValue * SaxonProcessor::makeIntegerValue(int i){
736
	//jobject obj = integerValue(*SaxonProcessor::sxn_environ, i);
737
	jmethodID mID_atomic = (jmethodID)(SaxonProcessor::sxn_environ->env->GetMethodID (xdmAtomicClass, "<init>", "(J)V"));
738
	
739

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

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

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

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

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

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

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

  
796 885
    const char * SaxonProcessor::getStringValue(XdmItem * item){
......
810 899
#if CVERSION_API_NO >= 123
811 900

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

  
824 916

  
825
             jshortArray sArray = NULL;
917
         jshortArray sArray = NULL;
826 918

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

  
834
             
835
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmID, sArray);
836
        if(!xdmArrayi) {
837
            cerr<<"Error found when converting string to XdmArray";
926
         jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmssID, sArray);
927
         if(!xdmArrayi) {
928
            std::cerr<<"Error found when converting string to XdmArray";
838 929
            return NULL;
839
        }
840
              if(exceptionOccurred()) {
841
         	   checkAndCreateException(saxonCAPIClass);
842
              } else {
843
         	XdmArray * value = new XdmArray(xdmArrayi);
930
         }
931

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

  
850 942

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

  
864 959
             jintArray iArray = NULL;
865 960

  
866
             jArray = SaxonProcessor::sxn_environ->env->NewShortArray((jint) length);
961
             iArray = SaxonProcessor::sxn_environ->env->NewIntArray((jint) length);
867 962
             jint fill[length];
868 963
             for (int i=0; i<length; i++) {
869 964
                fill[i] =input[i];
870 965
             }
871
             SaxonProcessor::sxn_environ->env->SetIntArrayRegion(valueArray, 0, length, fill);
966
             SaxonProcessor::sxn_environ->env->SetIntArrayRegion(iArray, 0, length, fill);
872 967

  
873 968

  
874
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmID, iArray);
969
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmiiID, iArray);
875 970
        if(!xdmArrayi) {
876
            cerr<<"Error found when converting string to XdmArray";
971
            std::cerr<<"Error found when converting string to XdmArray";
877 972
            return NULL;
878 973
        }
879 974
              if(exceptionOccurred()) {
880
         	   checkAndCreateException(saxonCAPIClass);
975
         	   exception = checkAndCreateException(saxonCAPIClass);
881 976
              } else {
882
         	XdmArray * value = new XdmArray(xdmArrayi);
977
         	XdmArray * value = new XdmArray(xdmArrayi, length);
883 978
         	value->setProcessor(this);
884 979
         	return value;
885 980
            }
......
889 984

  
890 985
   XdmArray * SaxonProcessor::makeArray(long * input, int length){
891 986
           if(input == NULL) {
892
                   cerr<<"Error found when converting string to XdmArray";
987
                   std::cerr<<"Error found when converting string to XdmArray";
893 988
                   return NULL;
894 989
           }
895 990
         jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "Lnet/sf/saxon/s9api/XdmArray;");
896
         jmethodID mmID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([J)Lnet/sf/saxon/s9api/XdmArray;");
897
             if (!mmID) {
991
         static jmethodID mmiID = NULL;
992
         if(mmiID == NULL) {
993
            mmiID = (jmethodID)SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmArrayClass, "makeArray", "([J)Lnet/sf/saxon/s9api/XdmArray;");
994
         }
995
             if (!mmiID) {
898 996
         	std::cerr<<"\nError: Saxonc.Dll "<<"makeArray([J)"<<" not found"<<std::endl;
899 997
                 return NULL;
900 998
             }
......
910 1008
             SaxonProcessor::sxn_environ->env->SetLongArrayRegion(lArray, 0, length, fill);
911 1009

  
912 1010

  
913
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmID, iArray);
1011
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmiID, lArray);
914 1012
        if(!xdmArrayi) {
915
            cerr<<"Error found when converting string to XdmArray";
1013
            std::cerr<<"Error found when converting string to XdmArray";
916 1014
            return NULL;
917 1015
        }
918 1016
              if(exceptionOccurred()) {
919
         	   checkAndCreateException(saxonCAPIClass);
1017
         	   exception = checkAndCreateException(saxonCAPIClass);
920 1018
              } else {
921
         	XdmArray * value = new XdmArray(xdmArrayi);
1019
         	XdmArray * value = new XdmArray(xdmArrayi, length);
922 1020
         	value->setProcessor(this);
923 1021
         	return value;
924 1022
            }
......
928 1026

  
929 1027

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

  
942 1043

  
943
             jintArray bArray = NULL;
1044
         jbooleanArray bArray = NULL;
944 1045

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

  
952 1053

  
953
            jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmID, bArray);
954
        if(!xdmArrayi) {
955
            cerr<<"Error found when converting string to XdmArray";
1054
         jobject xdmArrayi = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmArrayClass, mmbID, bArray);
1055
         if(!xdmArrayi) {
1056
            std::cerr<<"Error found when converting string to XdmArray";
956 1057
            return NULL;
957
        }
958
              if(exceptionOccurred()) {
959
         	   checkAndCreateException(saxonCAPIClass);
960
              } else {
961
         	XdmArray * value = new XdmArray(xdmArrayi);
1058
         }
1059
         if(exceptionOccurred()) {
1060
            exception = checkAndCreateException(saxonCAPIClass);
1061
         } else {
1062
         	XdmArray * value = new XdmArray(xdmArrayi, length);
962 1063
         	value->setProcessor(this);
963 1064
         	return value;
964 1065
            }
......
971 1072

  
972 1073
   XdmArray * SaxonProcessor::makeArray(const char ** input, int length){
973 1074
        if(input == NULL || length <= 0) {
974
                cerr<<"Error found when converting string to XdmArray";
1075
                std::cerr<<"Error found when converting string to XdmArray";
975 1076
                return NULL;
976 1077
        }
977 1078
       	jobject obj = NULL;
......
984 1085
        valueArray = SaxonProcessor::sxn_environ->env->NewObjectArray((jint) length, xdmAtomicClass, 0);
985 1086
        for(int i = 0; i< length; i++) {
986 1087
            if(input[i] == NULL) {
987
                cerr<<"Error found when converting string to XdmArray";
1088
                std::cerr<<"Error found when converting string to XdmArray";
988 1089
                return NULL;
989 1090
            }
990 1091
            obj = getJavaStringValue(SaxonProcessor::sxn_environ, input[i]);
......
994 1095

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

  
......
1008 1109
        return NULL;
1009 1110
       }
1010 1111

  
1112

  
1113

  
1114

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

  
1121
             		int size = dataMap.size();
1122

  
1123
             		if (size > 0) {
1124

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

  
1133

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

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

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

  
1150

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

  
1153
             		}
1154

  
1155

  
1156
             }
1157

  
1011 1158
#endif
1012 1159

  
1013 1160

  
latest9.9/hec/Saxon.C.API/SaxonProcessor.h
1 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2019 Saxonica Limited.
2
// Copyright (c) 2020 Saxonica Limited.
3 3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
......
21 21
#endif
22 22

  
23 23
//#define DEBUG //remove
24
#define CVERSION "1.2.2"
25
#define CVERSION_API_NO 122
24
#define CVERSION "1.3.0"
25
#define CVERSION_API_NO 130
26 26
#include <string>
27 27
#include <iostream>
28 28
#include <sstream>  
......
37 37
#include "XQueryProcessor.h"
38 38
#include "XPathProcessor.h"
39 39
#include "SchemaValidator.h"
40
#include "SaxonApiException.h"
40 41
//#include "com_saxonica_functions_extfn_PhpCall.h"
41 42
//#include "com_saxonica_functions_extfn_PhpCall_PhpFunctionCall.h"
42 43

  
......
51 52
class XdmAtomicValue;
52 53

  
53 54
#if CVERSION_API_NO >= 123
55
class XdmFunctionItem;
54 56
class XdmArray;
55 57
class XdmMap;
56 58
#endif
......
80 82
}JParameters;
81 83

  
82 84

  
83
/*! <code>SaxonApiException</code>. An exception thrown by the Saxon s9api API (Java). This is always a C++ wrapper for some other underlying exception in Java
84
 * <p/>
85
 */
86
class SaxonApiException {
87

  
88
public:
89

  
90
    /**
91
     * A default Constructor. Create a SaxonApiException
92
     */
93
     SaxonApiException(){
94
	exceptions = std::vector<MyException>(0);
95
    }
96

  
97
    /**
98
     * A Copy constructor. Create a SaxonApiException
99
     * @param ex - The exception object to copy
100
     */
101
	SaxonApiException(const SaxonApiException &ex){
102
		exceptions = ex.exceptions;
103
	}
104

  
105
    /**
106
     * A constructor. Create a SaxonApiException
107
     * @param ec - The error code of the underlying exception thrown, if known
108
     * @param exM - The error message of the underlying exception thrown, if known
109
     */
110
	SaxonApiException(const char * ec, const char * exM){
111
		exceptions = std::vector<MyException>(0);
112
		MyException newEx;	
113
		if(ec != NULL){
114
			newEx.errorCode =   std::string(ec);
115
		} else {
116
			newEx.errorCode ="Unknown";	
117
		}
118
		if(exM != NULL){
119
			newEx.errorMessage =  std::string(exM);
120
		} else {
121
			newEx.errorMessage="Unkown";		
122
		}
123
		newEx.isType = false;
124
	    	newEx.isStatic = false;
125
	    	newEx.isGlobal = false;
126
		newEx.linenumber = 0;
127
		exceptions.push_back(newEx);
128
	}
129

  
130
    /**
131
     * A constructor. Create a SaxonApiException
132
     * @param ec - The error code of the underlying exception thrown, if known
133
     * @param exM - The error message of the underlying exception thrown, if known
134
     * @param typeErr - Flag indicating if the error is a type error
135
     * @param stat - Flag indicating a static error
136
     * @param glob - Flag for if the error is global
137
     * @param l - Line number information of where the error occurred
138
     */
139
	SaxonApiException(const char * ec, const char * exM, bool typeErr, bool stat, bool glob, int l){
140
		exceptions = std::vector<MyException>(20);
141
		MyException newEx;
142
		if(ec != NULL){
143
			newEx.errorCode =   std::string(ec);
144
		} else {
145
			newEx.errorCode ="ERROR1";	
146
		}
147
		if(exM != NULL){
148
			newEx.errorMessage =  std::string(exM);
149
		} else {
150
			newEx.errorMessage="ERROR2";		
151
		}
152
		newEx.isType = typeErr;
153
	    	newEx.isStatic = stat;
154
	    	newEx.isGlobal = glob;
155
		newEx.linenumber = l;
156
		exceptions.push_back(newEx);
157
	}
158

  
159
    /**
160
     * Creates a SaxonApiException and adds it to a vector of exceptions
161
     * @param ec - The error code of the underlying exception thrown, if known
162
     * @param exM - The error message of the underlying exception thrown, if known
163
     * @param typeErr - Flag indicating if the error is a type error
164
     * @param stat - Flag indicating a static error
165
     * @param glob - Flag for if the error is global
166
     * @param l - Line number information of where the error occurred
167
     */
168
	void add(const char * ec, const char * exM, bool typeErr, bool stat, bool glob, int l){
169
		MyException newEx;
170
		if(ec != NULL){
171
			newEx.errorCode =   std::string(ec);
172
		} else {
173
			newEx.errorCode ="ERROR1";	
174
		}
175
		if(exM != NULL){
176
			newEx.errorMessage =  std::string(exM);
177
		} else {
178
			newEx.errorMessage="ERROR2";		
179
		}
180
		newEx.isType = typeErr;
181
	    	newEx.isStatic = stat;
182
	    	newEx.isGlobal = glob;
183
		newEx.linenumber = l;
184
		exceptions.push_back(newEx);
185
	}
186

  
187

  
188
    /**
189
     * A destructor.
190
     */
191
	~SaxonApiException(){ 
192
	  clear();
193
	}
194

  
195
    /**
196
     * Get the error code associated with the ith exception in the vector, if there is one
197
     * @param i - ith exception in the vector
198
     * @return the associated error code, or null if no error code is available
199
     */
200
	const char * getErrorCode(int i){
201
		if((size_t)i <= exceptions.size()){
202
			return exceptions[i].errorCode.c_str();
203
		}
204
		return NULL;
205
	}
206

  
207

  
208
	int getLineNumber(int i){
209
		if((size_t)i <= exceptions.size()){
210
			return exceptions[i].linenumber;	
211
		}
212
		return 0;
213
	}
214

  
215
	bool isGlobalError(int i){
216
		if((size_t)i <= exceptions.size()){
217
			return exceptions[i].isGlobal;
218
		}
219
		return false;
220
	}
221

  
222
	bool isStaticError(int i){
223
		if((size_t)i <= exceptions.size()){
224
			return exceptions[i].isStatic;
225
		}
226
		return false;
227
	}
228

  
229
	bool isTypeError(int i){
230
		if((size_t) i <= exceptions.size()){
231
			return exceptions[i].isType;
232
		}
233
		return false;
234
	}
235

  
236
	void clear(){
237
	  for(size_t i =0; i< exceptions.size();i++) {
238
		exceptions[i].errorCode.clear();
239
		exceptions[i].errorMessage.clear();	
240
	  }
241
	  exceptions.clear();
242
	}
243

  
244
	int count(){
245
		return (int)exceptions.size();	
246
	}
247

  
248
    /**
249
     * Returns the detail message string of the ith throwable, if there is one
250
     * @param i - ith exception in the vector
251
     * @return the detail message string of this <tt>Throwable</tt> instance
252
     *         (which may be <tt>null</tt>).
253
     */
254
	const char * getErrorMessage(int i){
255
		if((size_t)i <= exceptions.size()){
256
			return exceptions[i].errorMessage.c_str();
257
		}
258
		return NULL;
259
	}
260

  
261
	const char * getErrorMessages(){
262
		std::string result;
263
		for(size_t i = 0;i<exceptions.size();i++) {
264
			result += getErrorMessage(i);
265
		}
266
		if(result.empty()) { return NULL;}
267
		return result.c_str();
268
	}
269

  
270
    /**
271
     * Returns the ith Exception added, if there is one
272
     * @param i - ith exception in the vector
273
     * @return MyException
274
     */
275
	MyException getException(int i){
276
		if((size_t)i <= exceptions.size()){
277
			return exceptions[i];	
278
		}
279
		throw 0;
280
	}
281

  
282
	
283

  
284
private:
285
	std::vector<MyException> exceptions; /*!< Capture exceptions in a std:vector */
286
};
287

  
288

  
289

  
290

  
291

  
292

  
293

  
294 85

  
295 86
//==========================================
296 87

  
......
505 296
        * @return an XdmArray whose members are xs:boolean values corresponding one-to-one with the input
506 297
   */
507 298
    XdmArray * makeArray(bool * input, int length);
299

  
300

  
301
    XdmMap * makeMap(std::map<XdmAtomicValue *, XdmValue*> dataMap);
508 302
    
509 303

  
510 304
#endif
......
537 331
 
538 332

  
539 333
    /**
540
     * Checks for pending exceptions without creating a local reference to the exception object
334
     * Checks for thrown exceptions
541 335
     * @return bool - true when there is a pending exception; otherwise return false
542 336
    */
543 337
    bool exceptionOccurred();
......
546 340

  
547 341
     * Clears any exception that is currently being thrown. If no exception is currently being thrown, this routine has no effect.
548 342
    */
549
    void exceptionClear(bool clearCPPException=true);
343
    void exceptionClear();
550 344

  
551 345
    /**
552 346
     * Checks for pending exceptions and creates a SaxonApiException object, which handles one or more local exceptions objects
......
557 351
    */
558 352
    SaxonApiException * checkForExceptionCPP(JNIEnv* env, jclass callingClass,  jobject callingObject);
559 353

  
560
    SaxonApiException * getException();
561 354

  
562 355
    /*
563 356
      * Clean up and destroy Java VM to release memory used. 
......
679 472
    return true;
680 473
}
681 474

  
682

  
683
	/* TODO: Remove use of this method.*/
684
	const char* checkException(jobject cpp);
685

  
686
	/* Internal use*/
687
	void checkAndCreateException(jclass cppClass);
475
	SaxonApiException * checkAndCreateException(jclass cppClass);
688 476

  
689 477

  
690 478

  
......
716 504
	std::map<std::string,std::string> configProperties; /*!< map of properties used for the transformation as (string, string) pairs */	 
717 505
	bool licensei; /*!< indicates whether the Processor requires a Saxon that needs a license file (i.e. Saxon-EE) other a Saxon-HE Processor is created  */
718 506
	bool closed;
719
	SaxonApiException* exception; /*!< Pointer to any potential exception thrown */
507

  
720 508

  
721 509
	JNINativeMethod * nativeMethods;
722 510
	std::vector<JNINativeMethod> nativeMethodVect; /*!< Vector of native methods defined by user */
723

  
511
    SaxonApiException * exception;
724 512

  
725 513

  
726 514
private:
......
730 518
	void applyConfigurationProperties();
731 519
	// Saxon/C method for internal use
732 520
    static JParameters createParameterJArray(std::map<std::string,XdmValue*> parameters, std::map<std::string,std::string> properties);
521
    static JParameters createParameterJArray2(std::map<std::string,XdmValue*> parameters);
733 522
    static jobjectArray createJArray(XdmValue ** values, int length);
523
    static 	const char* checkException(jobject cpp);
734 524
};
735 525

  
736 526
//===============================================================================================
latest9.9/hec/Saxon.C.API/SchemaValidator.cpp
35 35
	} else {
36 36
		cwdV = curr;
37 37
	}
38
	proc->checkAndCreateException(cppClass);
38
	exception = proc->checkAndCreateException(cppClass);
39 39

  
40 40
}
41 41

  
......
64 64
			node->setProcessor(proc);
65 65
			return node;
66 66
		}
67
		proc->checkAndCreateException(cppClass);
67
		exception = proc->checkAndCreateException(cppClass);
68 68
	}
69 69
	return NULL;
70 70
}
......
139 139
	}
140 140

  
141 141
}
142
	proc->checkAndCreateException(cppClass);				
142
	exception = proc->checkAndCreateException(cppClass);
143 143
     		
144 144
	
145 145
 }
......
166 166

  
167 167

  
168 168
      }
169
      	proc->checkAndCreateException(cppClass);
169
      exception = proc->checkAndCreateException(cppClass);
170 170

  
171 171
 }
172 172

  
......
243 243
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
244 244
	}
245 245

  
246
}
247
	proc->checkAndCreateException(cppClass);				
246
    }
247
	exception = proc->checkAndCreateException(cppClass);
248 248
    
249 249
}
250 250

  
......
329 329
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
330 330
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
331 331
	}
332
	proc->checkAndCreateException(cppClass);
332
	exception = proc->checkAndCreateException(cppClass);
333 333
				
334 334
	}	
335 335
}
......
408 408
		return node;
409 409
	}
410 410

  
411
	proc->checkAndCreateException(cppClass);
411
	exception = proc->checkAndCreateException(cppClass);
412 412

  
413 413
}
414 414
	return NULL;
415 415
}
416 416

  
417 417
void SchemaValidator::exceptionClear(){
418
 if(proc->exception != NULL) {
419
 	delete proc->exception;
420
 	proc->exception = NULL;
418
 if(exception != NULL) {
419
 	delete exception;
420
 	exception = NULL;
421 421
 }
422 422
   SaxonProcessor::sxn_environ->env->ExceptionClear();
423 423
 }
424 424

  
425
const char * SchemaValidator::getErrorCode(int i) {
425
/*const char * SchemaValidator::getErrorCode(int i) {
426 426
	if(proc->exception == NULL) {return NULL;}
427 427
	return proc->exception->getErrorCode(i);
428 428
}
......
430 430
const char * SchemaValidator::getErrorMessage(int i ){
431 431
 if(proc->exception == NULL) {return NULL;}
432 432
 return proc->exception->getErrorMessage(i);
433
 }
433
 } */
434 434

  
435 435
bool SchemaValidator::exceptionOccurred() {
436
	return proc->exceptionOccurred() || proc->exception != NULL;
436
	return proc->exceptionOccurred() || exception != NULL;
437 437
}
438 438

  
439 439
const char* SchemaValidator::checkException() {
440 440
	return proc->checkException(cppV);
441 441
}
442 442

  
443
int SchemaValidator::exceptionCount(){
443
/*int SchemaValidator::exceptionCount(){
444 444
 if(proc->exception != NULL){
445 445
 return proc->exception->count();
446 446
 }
447 447
 return 0;
448
 }
448
 }   */
449 449

  
450 450
void SchemaValidator::setSourceNode(XdmNode * value) {
451 451
    if(value != NULL){
latest9.9/hec/Saxon.C.API/SchemaValidator.h
166 166
    /**
167 167
     * @return int - Count of the exceptions reported during validation
168 168
    */
169
    int exceptionCount();
169
    //int exceptionCount();
170 170

  
171 171
     //! Get the ith error message if there are any validation errors
172 172
    /**
......
205 205
	std::string outputFile;
206 206
	std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
207 207
	std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
208

  
208
    SaxonApiException * exception;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff