Project

Profile

Help

Revision 6304fb8b

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes and development work

View differences:

latest10/hec/Saxon.C.API/XdmFunctionItem.cpp
5 5

  
6 6
    XdmFunctionItem::XdmFunctionItem():XdmItem(), arity(-1){}
7 7

  
8

  
8 9
    XdmFunctionItem::XdmFunctionItem(const XdmFunctionItem &aVal): XdmItem(aVal){
9 10
        arity = aVal.arity;
10 11
    }
......
18 19
    const char* XdmFunctionItem::getName(){
19 20
          if(fname.empty()) {
20 21
             jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
21
             		jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getFunctionName",
22
             		static jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getFunctionName",
22 23
             					"(Lnet/sf/saxon/s9api/XdmFunctionItem;)Ljava/lang/String;");
23
             		if (!bmID) {
24
             		if (!xmID) {
24 25
             			std::cerr << "Error: SaxonC." << "getFunctionName"
25 26
             				<< " not found\n" << std::endl;
26
             			return NULL;
27
             			return nullptr;
27 28
             		} else {
28
             			jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticIntMethod(value->xdmvalue, xmID));
29
             			jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticIntMethod(xdmUtilsClass, xmID, value));
29 30
             			if(result) {
30
                        			const char * stri = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
31
                        			const char * stri = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
31 32

  
32 33
                        		    SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
33 34
                        			fname = std::string(stri);
......
44 45
    int XdmFunctionItem::getArity(){
45 46
          if(arity == -1) {
46 47
             jclass xdmFunctionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
47
             		jmethodID bmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmFunctionClass,
48
             		static jmethodID bfmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmFunctionClass,
48 49
             					"getArity",
49 50
             					"()I");
50
             		if (!bmID) {
51
             		if (!bfmID) {
51 52
             			std::cerr << "Error: SaxonC." << "getArity"
52 53
             				<< " not found\n" << std::endl;
53 54
             			return false;
54 55
             		} else {
55
             			jint result = (jint)(SaxonProcessor::sxn_environ->env->CallIntMethod(value->xdmvalue, bmID));
56
             			jint result = (jint)(SaxonProcessor::sxn_environ->env->CallIntMethod(value, bfmID));
56 57
             			return (int)result;
57 58
             		}
58 59

  
......
63 64
    }
64 65

  
65 66
    XdmFunctionItem * XdmFunctionItem::getSystemFunction(SaxonProcessor * processor, const char * name, int arity){
66
        if(processor == NULL || name == NULL) {
67
            std::cerr << "Error in getSystemFunction. Please make sure processor and name are not NULL." << std::endl;
68
             return NULL;
67
        if(processor == nullptr || name == nullptr) {
68
            std::cerr << "Error in getSystemFunction. Please make sure processor and name are not nullptr." << std::endl;
69
             return nullptr;
69 70
        }
70 71
             jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
71
             jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getSystemFunction",
72
             static jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getSystemFunction",
72 73
             "(Lnet/sf/saxon/s9api/Procesor;Ljava/lang/String;I)Lnet/sf/saxon/s9api/XdmFunctionItem");
73 74
             if (!xmID) {
74 75
                       std::cerr << "Error: SaxonC." << "getSystemFunction" << " not found\n" << std::endl;
75
                         			return false;
76
                         			return nullptr;
76 77
                         		} else {
77 78
                         			jobject result = (jobject)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, processor->proc, SaxonProcessor::sxn_environ->env->NewStringUTF(name), arity);
78 79
                         			if(result) {
79
                         			    XdmFunctionItem functionItem = new XdmFunctionItem(result);
80
                         			    auto functionItem = new XdmFunctionItem(result);
80 81
                         			    return functionItem;
81 82

  
82 83
                         			} else {
83
                         			    return NULL
84
                         			    return nullptr;
84 85

  
85 86
                         			}
86 87

  
......
91 92
    }
92 93

  
93 94
    XdmValue * XdmFunctionItem::call(XdmValue ** arguments, int argument_length) {
94
          if(argument_length > 0 && arguments == NULL) {
95
                      std::cerr << "Error in XdmFunctionItem.call.  NULL arguments found." << std::endl;
96
                      return NULL;
95
          if(argument_length > 0 && arguments == nullptr) {
96
                      std::cerr << "Error in XdmFunctionItem.call.  nullptr arguments found." << std::endl;
97
                      return nullptr;
97 98
          }
98
          if(proc != NULL) {
99
          if(proc != nullptr) {
99 100
                       jclass xdmFunctionClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
100
                       jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetObjectMethodID(xdmFunctionClass,"call",
101
                       static jmethodID xffmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetObjectMethodID(xdmFunctionClass,"call",
101 102
                       "(Lnet/sf/saxon/s9api/Procesor;[Lnet/sf/saxon/s9api/XdmValue)Lnet/sf/saxon/s9api/XdmValue");
102
                       if (!xmID) {
103
                       if (!xffmID) {
103 104
                                 std::cerr << "Error: SaxonC." << "getSystemFunction" << " not found\n" << std::endl;
104
                                 return false;
105
                                 return nullptr;
105 106
                       } else {
106 107

  
107 108
                                 jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
108
                                 jobject result = (jobject)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, processor->proc, argumentJArray);
109
                                 if(argumentJArray != NULL) {
109
                                 jobject result = (jobject)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xffmID, processor->proc, argumentJArray);
110
                                 if(argumentJArray != nullptr) {
110 111
                                    	SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
111 112

  
112 113

  
......
115 116
                                        jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
116 117
                                        jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
117 118
                                        jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
118
                                        XdmValue * value = NULL;
119
                                        XdmItem * xdmItem = NULL;
119
                                        XdmValue * value = nullptr;
120
                                        XdmItem * xdmItem = nullptr;
120 121

  
121 122

  
122 123
                                        if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
......
146 147
                                        }
147 148

  
148 149
                                 } else {
149
                                 	    return NULL
150
                                 	    return nullptr
150 151

  
151 152
                                 }
152 153

  
153 154
                       }
154 155
      } else {
155 156
         std::cerr << "Error in XdmFunctionItem.call.  Processor not set on the xdmFunctionItem." << std::endl;
156
         return NULL;
157
         return nullptr;
157 158
      }
158 159

  
159 160
    }

Also available in: Unified diff