Project

Profile

Help

Revision 0608038f

Added by O'Neil Delpratt over 5 years ago

Bug fix relating to issue 2772

View differences:

latest9.6/hec/Saxon.C.API/XdmNode.cpp
31 31
		return nodeName;
32 32
	}
33 33
	XDM_NODE_KIND kind = getNodeKind();
34
 	jclass xdmUtilsClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XdmUtils");
35
	jmethodID xmID = (jmethodID) proc->environ->env->GetStaticMethodID(xdmUtilsClass,"getNodeName",
34
 	jclass xdmUtilsClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmUtils");
35
	jmethodID xmID = (jmethodID) environ->env->GetStaticMethodID(xdmUtilsClass,"getNodeName",
36 36
					"(Lnet/sf/saxon/s9api/XdmNode;)Ljava/lang/String;");
37 37
	switch (kind) {
38 38
            case DOCUMENT:
......
48 48
			std::cerr << "Error: MyClassInDll." << "getNodeName"<< " not found\n" << std::endl;
49 49
			return NULL;
50 50
		} else {
51
			jstring result = (jstring)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, value->xdmvalue));
51
			jstring result = (jstring)(environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, value->xdmvalue));
52 52
			if(!result) {
53 53
				return NULL;
54 54
			} else {
55
				nodeName = proc->environ->env->GetStringUTFChars(result, NULL);
55
				nodeName = environ->env->GetStringUTFChars(result, NULL);
56 56
				return nodeName;
57 57
			} 
58 58
		}
......
69 69
		return baseURI;
70 70
	}
71 71

  
72
	jclass xdmNodeClass = lookForClass(proc->environ->env, "net/sf/saxon/s9api/XdmNode");
73
	jmethodID bmID = (jmethodID) proc->environ->env->GetMethodID(xdmNodeClass,
72
	jclass xdmNodeClass = lookForClass(environ->env, "net/sf/saxon/s9api/XdmNode");
73
	jmethodID bmID = (jmethodID) environ->env->GetMethodID(xdmNodeClass,
74 74
					"getBaseURI",
75 75
					"()Ljava/net/URI;");
76 76
	if (!bmID) {
......
78 78
				<< " not found\n" << std::endl;
79 79
		return NULL;
80 80
	} else {
81
		jobject nodeURIObj = (proc->environ->env->CallObjectMethod(value->xdmvalue, bmID));
81
		jobject nodeURIObj = (environ->env->CallObjectMethod(value->xdmvalue, bmID));
82 82
		if(!nodeURIObj){
83 83
			return NULL;
84 84
		} else {
85
			jclass URIClass = lookForClass(proc->environ->env, "java/net/URI");
86
			jmethodID strMID = (jmethodID) proc->environ->env->GetMethodID(URIClass,
85
			jclass URIClass = lookForClass(environ->env, "java/net/URI");
86
			jmethodID strMID = (jmethodID) environ->env->GetMethodID(URIClass,
87 87
					"toString",
88 88
					"()Ljava/lang/String;");
89 89
			if(strMID){
90 90
				jstring result = (jstring)(
91
				proc->environ->env->CallObjectMethod(nodeURIObj, strMID));
92
				baseURI = proc->environ->env->GetStringUTFChars(result,
91
				environ->env->CallObjectMethod(nodeURIObj, strMID));
92
				baseURI = environ->env->GetStringUTFChars(result,
93 93
					NULL);
94 94
			
95 95
				return baseURI;
......
106 106

  
107 107
    XdmNode* XdmNode::getParent(){
108 108
	if(parent == NULL && proc!= NULL) {
109
		jclass xdmNodeClass = lookForClass(proc->environ->env, "net/sf/saxon/s9api/XdmNode");
110
		jmethodID bmID = (jmethodID) proc->environ->env->GetMethodID(xdmNodeClass,
109
		jclass xdmNodeClass = lookForClass(environ->env, "net/sf/saxon/s9api/XdmNode");
110
		jmethodID bmID = (jmethodID) environ->env->GetMethodID(xdmNodeClass,
111 111
					"getParent",
112 112
					"()Lnet/sf/saxon/s9api/XdmNode;");
113 113
		if (!bmID) {
......
115 115
				<< " not found\n" << std::endl;
116 116
			return NULL;
117 117
		} else {
118
			jobject nodeObj = (proc->environ->env->CallObjectMethod(value->xdmvalue, bmID));
118
			jobject nodeObj = (environ->env->CallObjectMethod(value->xdmvalue, bmID));
119 119
			if(nodeObj) {
120 120
				parent = new XdmNode(NULL, nodeObj, UNKNOWN);
121 121
				parent->setProcessor(proc);
......
133 133
    const char* XdmNode::getAttributeValue(const char *str){
134 134

  
135 135
	if(str == NULL) { return NULL;}
136
	jclass xdmUtilsClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XdmUtils");
137
	jmethodID xmID = (jmethodID) proc->environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeValue",
136
	jclass xdmUtilsClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmUtils");
137
	jmethodID xmID = (jmethodID) environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeValue",
138 138
					"(Lnet/sf/saxon/s9api/XdmNode;Ljava/lang/String;)Ljava/lang/String;");
139 139
	if (!xmID) {
140 140
			std::cerr << "Error: SaxonDll." << "getAttributeValue"
......
144 144
	if(str == NULL) {
145 145
		return NULL;
146 146
	}
147
	jstring eqname = proc->environ->env->NewStringUTF(str);
147
	jstring eqname = environ->env->NewStringUTF(str);
148 148

  
149
	jstring result = (jstring)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value->xdmvalue, eqname));
150
	proc->environ->env->DeleteLocalRef(eqname);
151
	checkForException(*(proc->environ), xdmUtilsClass, (jobject)result);//Remove code
149
	jstring result = (jstring)(environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value->xdmvalue, eqname));
150
	environ->env->DeleteLocalRef(eqname);
151
	checkForException(*(environ), xdmUtilsClass, (jobject)result);//Remove code
152 152
	if(result) {
153
		const char * stri = proc->environ->env->GetStringUTFChars(result,
153
		const char * stri = environ->env->GetStringUTFChars(result,
154 154
					NULL);
155 155
		
156
		//proc->environ->env->DeleteLocalRef(result);
156
		//environ->env->DeleteLocalRef(result);
157 157

  
158 158
		return stri;
159 159
	} else {
......
165 165

  
166 166
    XdmNode** XdmNode::getAttributeNodes(){
167 167
	if(attrValues == NULL) {
168
		jclass xdmUtilsClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XdmUtils");
169
		jmethodID xmID = (jmethodID) proc->environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeNodes",
168
		jclass xdmUtilsClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmUtils");
169
		jmethodID xmID = (jmethodID) environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeNodes",
170 170
					"(Lnet/sf/saxon/s9api/XdmNode;)[Lnet/sf/saxon/s9api/XdmNode;");
171
		jobjectArray results = (jobjectArray)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
171
		jobjectArray results = (jobjectArray)(environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
172 172
		value->xdmvalue));
173 173
		if(results == NULL) {
174 174
			return NULL;	
175 175
		}
176
		int sizex = proc->environ->env->GetArrayLength(results);
176
		int sizex = environ->env->GetArrayLength(results);
177 177
		attrCount = sizex;
178 178
		if(sizex>0) {	
179 179
			attrValues =  new XdmNode*[sizex];
180 180
			XdmNode * tempNode =NULL;
181 181
			for (int p=0; p < sizex; ++p){
182
				jobject resulti = proc->environ->env->GetObjectArrayElement(results, p);
182
				jobject resulti = environ->env->GetObjectArrayElement(results, p);
183 183
				tempNode = new XdmNode(this, resulti, ATTRIBUTE);
184 184
				tempNode->setProcessor(proc);
185 185
				this->incrementRefCount();
......
192 192

  
193 193
    int XdmNode::getAttributeCount(){
194 194
	if(attrCount == -1 && proc!= NULL) {
195
		jclass xdmUtilsClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XdmUtils");
196
		jmethodID xmID = (jmethodID) proc->environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeCount",
195
		jclass xdmUtilsClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmUtils");
196
		jmethodID xmID = (jmethodID) environ->env->GetStaticMethodID(xdmUtilsClass,"getAttributeCount",
197 197
					"(Lnet/sf/saxon/s9api/XdmNode;)I");
198 198
		
199 199
		if (!xmID) {
......
201 201
				<< " not found\n" << std::endl;
202 202
			return 0;
203 203
		}
204
		jint result = (jlong)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
204
		jint result = (jlong)(environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
205 205
		value->xdmvalue));
206 206

  
207 207
		attrCount =(int)result;
......
211 211

  
212 212
    int XdmNode::getChildCount(){
213 213
	if(childCount == -1 && proc!= NULL) {
214
		jclass xdmUtilsClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XdmUtils");
215
		jmethodID xmID = (jmethodID) proc->environ->env->GetStaticMethodID(xdmUtilsClass,"getChildCount",
214
		jclass xdmUtilsClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmUtils");
215
		jmethodID xmID = (jmethodID) environ->env->GetStaticMethodID(xdmUtilsClass,"getChildCount",
216 216
					"(Lnet/sf/saxon/s9api/XdmNode;)I");
217 217
		
218 218
		if (!xmID) {
......
220 220
				<< " not found\n" << std::endl;
221 221
			return 0;
222 222
		}
223
		jint result = (jlong)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
223
		jint result = (jlong)(environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
224 224
		value->xdmvalue));
225 225

  
226 226
		childCount =(int)result;
......
231 231
    XdmNode** XdmNode::getChildren(){
232 232

  
233 233
	if(children == NULL && proc!= NULL) {
234
		jclass xdmUtilsClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XdmUtils");
235
		jmethodID xmID = (jmethodID) proc->environ->env->GetStaticMethodID(xdmUtilsClass,"getChildren",
234
		jclass xdmUtilsClass = lookForClass(environ->env, "net/sf/saxon/option/cpp/XdmUtils");
235
		jmethodID xmID = (jmethodID) environ->env->GetStaticMethodID(xdmUtilsClass,"getChildren",
236 236
					"(Lnet/sf/saxon/s9api/XdmNode;)[Lnet/sf/saxon/s9api/XdmNode;");
237 237
		
238 238
		if (!xmID) {
......
240 240
				<< " not found\n" << std::endl;
241 241
			return NULL;
242 242
		}
243
		jobjectArray results = (jobjectArray)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
243
		jobjectArray results = (jobjectArray)(environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
244 244
		value->xdmvalue));
245
		int sizex = proc->environ->env->GetArrayLength(results);
245
		int sizex = environ->env->GetArrayLength(results);
246 246
		childCount = sizex;	
247 247
		children =  new XdmNode*[sizex];
248 248
		XdmNode * tempNode = NULL;
249 249
		for (int p=0; p < sizex; ++p){
250
			jobject resulti = proc->environ->env->GetObjectArrayElement(results, p);
250
			jobject resulti = environ->env->GetObjectArrayElement(results, p);
251 251
			tempNode = new XdmNode(this, resulti, UNKNOWN);
252 252
			tempNode->setProcessor(proc);
253 253
			//tempNode->incrementRefCount();

Also available in: Unified diff