Project

Profile

Help

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

he / latest10 / hec / Saxon.C.API / XdmMap.cpp @ 61000456

1
#include "XdmMap.h"
2
#include <map>
3

    
4

    
5
XdmMap::XdmMap(): XdmFunctionItem() {
6

    
7
}
8

    
9
XdmMap::XdmMap(const XdmMap &d) {
10
      arity = d.arity;
11
      data = d.data; //TODO check if copy works
12
    }
13

    
14
XdmMap::XdmMap(jobject obj): XdmFunctionItem(obj) {}
15

    
16

    
17

    
18

    
19
    int XdmMap::mapSize(){
20
        return  data.size();
21
    }
22

    
23
    XdmValue * XdmMap::get(XdmAtomicValue* key) {
24
    jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
25
    static jmethodID tbmapID = nullptr;
26

    
27
    if(tbmapID == nullptr) {
28
    tbmapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "get",
29
                                            "(Lnet/sf/saxon/s9api/XdmAtomicValue;)Lnet/sf/saxon/s9api/XdmValue;");
30

    
31
    }
32
    if (!tbmapID) {
33
                            std::cerr << "Error: Saxonc.XdmMap." << "get"
34
                                    << " not found\n" << std::endl;
35
                            return nullptr;
36
    } else {
37
                            jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, tbmapID, ((XdmItem *)key)->getUnderlyingValue()));
38
                            if(valueObj) {
39
                                    XdmValue * newValue = new XdmValue((proc == nullptr ? nullptr : proc));
40
                                    newValue->addUnderlyingValue(valueObj);
41
                                    return newValue;
42
                            }
43
                            return nullptr;
44
    }
45

    
46
    }
47

    
48
    XdmValue * XdmMap::get(const char * key) {
49
        jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
50
        static jmethodID tbsmapID = nullptr;
51

    
52
        if(tbsmapID == nullptr) {
53
        tbsmapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "get",
54
                                                "(Ljava/lang/String;)Lnet/sf/saxon/s9api/XdmValue;");
55

    
56
        }
57
        if (!tbsmapID) {
58
                                std::cerr << "Error: Saxonc.XdmMap." << "get"
59
                                        << " not found\n" << std::endl;
60
                                return nullptr;
61
        } else {
62
                jobject strObj = getJavaStringValue(SaxonProcessor::sxn_environ, key);
63
                        jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, tbsmapID, strObj));
64
                        if(valueObj) {
65
                                XdmValue * newValue = new XdmValue((proc == nullptr ? nullptr : proc));
66
                                       newValue->addUnderlyingValue(valueObj);
67
                                       return newValue;
68
                               }
69
                               return nullptr;
70
        }
71

    
72

    
73
    }
74

    
75
    XdmValue * XdmMap::get(int key) {
76
        jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
77
        static jmethodID tbimapID = nullptr;
78

    
79
        if(tbimapID == nullptr) {
80
        tbimapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "get",
81
                                                "(I)Lnet/sf/saxon/s9api/XdmValue;");
82

    
83
        }
84
        if (!tbimapID) {
85
                                std::cerr << "Error: Saxonc.XdmMap." << "get"
86
                                        << " not found\n" << std::endl;
87
                                return nullptr;
88
        } else {
89
                        jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, tbimapID, key));
90
                        if(valueObj) {
91
                                XdmValue * newValue = new XdmValue((proc == nullptr ? nullptr : proc));
92
                                       newValue->addUnderlyingValue(valueObj);
93
                                       return newValue;
94
                               }
95
                               return nullptr;
96
        }
97

    
98

    
99
    }
100

    
101
    XdmValue *  XdmMap::get(double key) {
102
        jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
103
        static jmethodID tbdmapID = nullptr;
104

    
105
        if(tbdmapID == nullptr) {
106
            tbdmapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "get",
107
                                                "(D)Lnet/sf/saxon/s9api/XdmValue;");
108

    
109
        }
110
        if (!tbdmapID) {
111
                                std::cerr << "Error: Saxonc.XdmMap." << "get"
112
                                        << " not found\n" << std::endl;
113
                                return nullptr;
114
        } else {
115
                        jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, tbdmapID, key));
116
                        if(valueObj) {
117
                                XdmValue * newValue = new XdmValue((proc == nullptr ? nullptr : proc));
118
                                       newValue->addUnderlyingValue(valueObj);
119
                                       return newValue;
120
                               }
121
                               return nullptr;
122
        }
123

    
124

    
125
    }
126

    
127
    XdmValue * XdmMap::get(long key) {
128
        jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
129
        static jmethodID tbdmapID = nullptr;
130

    
131
        if(tbdmapID == nullptr) {
132
            tbdmapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "get",
133
                                                "(J)Lnet/sf/saxon/s9api/XdmValue;");
134

    
135
        }
136
        if (!tbdmapID) {
137
                                std::cerr << "Error: Saxonc.XdmMap." << "get"
138
                                        << " not found\n" << std::endl;
139
                                return nullptr;
140
        } else {
141
                        jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, tbdmapID, key));
142
                        if(valueObj) {
143
                                XdmValue * newValue = new XdmValue((proc == nullptr ? nullptr : proc));
144
                                       newValue->addUnderlyingValue(valueObj);
145
                                       return newValue;
146
                               }
147
                               return nullptr;
148
        }
149

    
150
    }
151

    
152
//TODO test this method
153
    XdmMap * XdmMap::put(XdmAtomicValue* key, XdmValue * valuei) {
154
        if(key == nullptr || valuei == nullptr) {
155
            std::cerr << "Error: Saxonc.XdmMap." << "key or value is nullptr" << std::endl;
156
            return nullptr;
157
        }
158
        jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
159
        static jmethodID putmapID = nullptr;
160

    
161
        if(putmapID == nullptr) {
162
                    putmapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "put",
163
                                                        "(Lnet/sf/saxon/s9api/XdmAtomicValue;Lnet/sf/saxon/s9api/XdmValue;)Lnet/sf/saxon/s9api/XdmMap;");
164

    
165
        }
166
        if (!putmapID) {
167
            std::cerr << "Error: Saxonc.XdmMap." << "put"
168
                          << " not found\n" << std::endl;
169
            return nullptr;
170
        } else {
171
                                jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, putmapID, ((XdmItem *)key)->getUnderlyingValue(), valuei->getUnderlyingValue()));
172
                                if(valueObj) {
173
                                        XdmMap * newValue = new XdmMap(valueObj);
174
                                               return newValue;
175
                                       }
176
                                       return nullptr;
177
                }
178

    
179
    }
180

    
181
    XdmMap * XdmMap::remove(XdmAtomicValue* key){
182
                jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
183
                static jmethodID removemapID = nullptr;
184

    
185
                if(removemapID == nullptr) {
186
                    removemapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "remove",
187
                                                        "(Lnet/sf/saxon/s9api/XdmAtomicValue;)Lnet/sf/saxon/s9api/XdmMap;");
188

    
189
                }
190
                if (!removemapID) {
191
                                        std::cerr << "Error: Saxonc.XdmMap." << "remove"
192
                                                << " not found\n" << std::endl;
193
                                        return nullptr;
194
                } else {
195
                                jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, removemapID, ((XdmItem *)key)->getUnderlyingValue()));
196
                                if(valueObj) {
197
                                        XdmMap * newValue = new XdmMap(valueObj);
198
                                               return newValue;
199
                                       }
200
                                       return nullptr;
201
                }
202

    
203

    
204

    
205
    }
206

    
207
    std::set<XdmAtomicValue*> XdmMap::keySet(){
208
        std::set<XdmAtomicValue *> myset;
209

    
210
        jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
211
        static jmethodID keySetmID = nullptr;
212

    
213
        if(keySetmID == nullptr) {
214
            keySetmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getXdmMapKeys",
215
                                                                "(Lnet/sf/saxon/s9api/XdmMap)[Lnet/sf/saxon/s9api/XdmAtomicValue;");
216
            }
217
            if (!keySetmID) {
218
                std::cerr << "Error: SaxonDll." << "makeXdmMap"<< " not found\n" << std::endl;
219
                return myset;
220
            }
221

    
222

    
223
            jobjectArray results = (jobjectArray)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, keySetmID,value->xdmvalue));
224
            if(results) {
225
                       int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
226

    
227

    
228
                           XdmAtomicValue * tempValue = nullptr;
229
                                   for (int p=0; p < sizex; ++p){
230
                                           jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
231
                                           tempValue = new XdmAtomicValue();
232
                                           tempValue->addUnderlyingValue(resulti);
233
                                           myset.push_back(tempValue);
234
                                   }
235
        }
236

    
237

    
238

    
239
         return myset;
240
    }
241

    
242
    //std::map<XdmAtomicValue*, XdmValue*> XdmMap::asMap();
243

    
244
    bool XdmMap::isEmpty() {
245
                jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
246
                static jmethodID isEmptyMapID = nullptr;
247

    
248
                if(isEmptyMapID == nullptr) {
249
                    isEmptyMapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "isEmpty",
250
                                                        "()Z");
251

    
252
                }
253
                if (!isEmptyMapID) {
254
                                        std::cerr << "Error: Saxonc.XdmMap." << "isEmpty"
255
                                                << " not found\n" << std::endl;
256
                                        return false;
257
                } else {
258
                                jboolean result = (SaxonProcessor::sxn_environ->env->CallBooleanMethod(value->xdmvalue, isEmptyMapID));
259
                                return result;
260
                }
261
    }
262

    
263
    bool XdmMap::containsKey(XdmAtomicValue * key) {
264
                jclass xdmMapClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmMap");
265
                static jmethodID containsMapID = nullptr;
266

    
267
                if(containsMapID == nullptr) {
268
                    containsMapID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmMapClass, "containsKey",
269
                                                        "(Lnet/sf/saxon/s9api/XdmAtomicValue;)Z");
270

    
271
                }
272
                if (!containsMapID) {
273
                                        std::cerr << "Error: Saxonc.XdmMap." << "containsKey"
274
                                                << " not found\n" << std::endl;
275
                                        return false;
276
                } else {
277
                                jboolean result = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, containsMapID, ((XdmItem *)key)->getUnderlyingValue()));
278
                                return result;
279
                }
280

    
281

    
282

    
283
    }
284

    
285
    std::list<XdmValue *> XdmMap::values() {
286
         std::list<XdmValue *> mylist;
287

    
288
            jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
289
            jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getXdmMapValues",
290
                                                                "(Lnet/sf/saxon/s9api/XdmMap)[Lnet/sf/saxon/s9api/XdmValue;");
291
            if (!xmID) {
292
                std::cerr << "Error: SaxonDll." << "makeXdmMap"<< " not found\n" << std::endl;
293
                return mylist;
294
            }
295

    
296

    
297
            jobjectArray results = (jobjectArray)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value->xdmvalue));
298
            if(results) {
299
                       int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
300

    
301

    
302
                           XdmValue * tempValue = nullptr;
303
                           for (int p=0; p < sizex; ++p){
304
                                           jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
305
                                           tempValue = new XdmValue();
306
                                           tempValue->addUnderlyingValue(resulti);
307
                                           mylist.push_back(tempValue);
308

    
309
                                   }
310

    
311
            }
312

    
313

    
314
         return mylist;
315
    }
(29-29/53)