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/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

  

Also available in: Unified diff