Project

Profile

Help

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

he / src / main / c / Saxon.C.API / XdmArray.cpp @ a69dd173

1
#include "XdmArray.h"
2

    
3

    
4

    
5
XdmArray::XdmArray(): XdmFunctionItem(){
6

    
7

    
8
}
9

    
10
XdmArray::XdmArray(const XdmArray &d): XdmFunctionItem(d) {
11
}
12

    
13

    
14

    
15
XdmArray::XdmArray(jobject obj) : XdmFunctionItem(obj){}
16

    
17
int XdmArray::arrayLength() const {
18
    jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmArray");
19
    static jmethodID arLenmID = nullptr;
20

    
21
    if(arLenmID == nullptr) {
22

    
23
        arLenmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmArrayClass, "arrayLength",
24
                                                                          "()I");
25
    }
26

    
27
    if (!arLenmID) {
28
        std::cerr << "Error: Saxonc.XdmArray." << "arrayLength"
29
                  << " not found\n" << std::endl;
30
        return 0;
31
    } else {
32
        jint valuei = (SaxonProcessor::sxn_environ->env->CallIntMethod(value, arLenmID));
33
        return valuei;
34
    }
35
}
36

    
37
XdmValue* XdmArray::get(int n){
38
    jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmArray");
39
    static jmethodID tbmID = nullptr;
40

    
41
    if(tbmID == nullptr) {
42

    
43
        tbmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmArrayClass, "get",
44
                                            "(I)Lnet/sf/saxon/s9api/XdmValue;");
45
    }
46

    
47
    if (!tbmID) {
48
                            std::cerr << "Error: Saxonc.XdmArray." << "get"
49
                                    << " not found\n" << std::endl;
50
                            return nullptr;
51
    } else {
52
                            jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, tbmID, n));
53
                            if(valueObj) {
54
                                    auto * newValue = new XdmValue();
55
                                    newValue->addUnderlyingValue(valueObj);
56
                                    return newValue;
57
                            }
58
                            return nullptr;
59
    }
60
}
61

    
62
XdmArray* XdmArray::put(int n, XdmValue * valuei) {
63
    jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmArray");
64
    static jmethodID tbpmID = nullptr;
65

    
66
    if(tbpmID == nullptr) {
67
        tbpmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmArrayClass, "put",
68
                                            "(I;Lnet/sf/saxon/s9api/XdmValue;)Lnet/sf/saxon/s9api/XdmArray;");
69
    }
70
    if (!tbpmID) {
71
                            std::cerr << "Error: Saxonc.XdmArray." << "put"
72
                                    << " not found\n" << std::endl;
73
                            return nullptr;
74
    } else {
75
                            jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, tbpmID, n, valuei->getUnderlyingValue()));
76
                            if(valueObj) {
77
                                    auto * newValue = new XdmArray(valueObj);
78
                                    return newValue;
79
                            }
80
                            return nullptr;
81
    }
82

    
83

    
84
}
85

    
86
XdmArray* XdmArray::addMember(XdmValue* valuei) {
87
    jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmArray");
88
    static jmethodID tbamID = nullptr;
89

    
90
    if(tbamID) {
91
        tbamID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmArrayClass, "concat",
92
                                            "(Lnet/sf/saxon/s9api/XdmValue;)Lnet/sf/saxon/s9api/XdmArray;");
93

    
94
    }
95

    
96
    if (!tbamID) {
97
                            std::cerr << "Error: Saxonc.XdmArray." << "concat"
98
                                    << " not found\n" << std::endl;
99
                            return nullptr;
100
    } else {
101
                            jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, tbamID, valuei->getUnderlyingValue()));
102
                            if(valueObj) {
103
                                    auto * newValue = new XdmArray(valueObj);
104
                                    return newValue;
105
                            }
106
                            return nullptr;
107
    }
108
}
109

    
110
XdmArray* XdmArray::concat(XdmArray* valuei) {
111
    jclass xdmArrayClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmArray");
112
    static jmethodID tbcaID = nullptr;
113

    
114

    
115
    if(tbcaID == nullptr) {
116
        tbcaID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmArrayClass, "concat",
117
                                            "(Lnet/sf/saxon/s9api/XdmArray;)Lnet/sf/saxon/s9api/XdmArray;");
118
    }
119

    
120
    if (!tbcaID) {
121
                            std::cerr << "Error: Saxonc.XdmArray." << "concat"
122
                                    << " not found\n" << std::endl;
123
                            return nullptr;
124
    } else {
125
                            jobject valueObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value, tbcaID, valuei->getUnderlyingValue()));
126
                            if(valueObj) {
127
                                    auto * newValue = new XdmArray(valueObj);
128
                                    return newValue;
129
                            }
130
                            std::cerr << "Error: Saxonc.XdmArray." << "concat" << " failed\n" << std::endl;
131
                            return nullptr;
132
    }
133

    
134
}
135

    
136
std::list<XdmValue *> XdmArray::asList() {
137
  std::list<XdmValue *> arr;
138

    
139
        jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
140
        static jmethodID xmID = nullptr;
141

    
142

    
143
        if(xmID == nullptr) {
144
            xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"convertXdmArrayToArrayObject",
145
                                        "(Lnet/sf/saxon/s9api/XdmArray;)[Lnet/sf/saxon/s9api/XdmValue;");
146
        }
147

    
148
        if (!xmID) {
149
                        std::cerr << "Error: SaxonDll." << "convertXdmArrayToArrayObject"
150
                                << " not found\n" << std::endl;
151
                        return arr;
152
                }
153

    
154

    
155
        auto results = (jobjectArray)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value));
156
        if(results) {
157
           int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
158

    
159

    
160
                       XdmValue * tempValue;
161
                       for (int p=0; p < sizex; ++p){
162
                               jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
163
                               tempValue = new XdmValue();
164
                               tempValue->addUnderlyingValue(resulti);
165
                               arr.push_back(tempValue);
166

    
167
                       }
168
               return arr;
169

    
170
        } else {
171
            return arr;
172
        }
173

    
174

    
175
}
(23-23/55)