Project

Profile

Help

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

he / latest9.6 / hec / Saxon.C.API / XdmNode.cpp @ d69c1ee9

1

    
2
#include "XdmNode.h"
3

    
4

    
5
XdmNode::XdmNode(jobject obj): XdmItem(obj), nodeKind(UNKNOWN), baseURI(NULL), nodeName(NULL), children(NULL), parent(NULL), attrValues(NULL){
6
        childCount = -1;
7
        attrCount = -1;
8
}
9

    
10
XdmNode::XdmNode(XdmNode * p, jobject obj, XDM_NODE_KIND kind): XdmItem(obj), nodeKind(kind), baseURI(NULL), nodeName(NULL), children(NULL), parent(p), attrValues(NULL){
11
        childCount = -1;
12
        attrCount = -1;
13
}
14

    
15
bool XdmNode::isAtomic() {
16
        return false;
17
} 
18
    
19
    XDM_NODE_KIND XdmNode::getNodeKind(){
20

    
21
        if(nodeKind == UNKNOWN && proc != NULL) {
22
                nodeKind = static_cast<XDM_NODE_KIND>(proc->getNodeKind(value->xdmvalue));
23
        } 
24
        return nodeKind;
25

    
26
    }
27

    
28
    const char * XdmNode::getNodeName(){
29
        
30
        if(nodeName != NULL) {
31
                return nodeName;
32
        }
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",
36
                                        "(Lnet/sf/saxon/s9api/XdmNode;)Ljava/lang/String;");
37
        switch (kind) {
38
            case DOCUMENT:
39
            case TEXT:
40
            case COMMENT:
41
                return NULL;
42
            case PROCESSING_INSTRUCTION:
43
            case NAMESPACE:
44
            case ELEMENT:
45
            case ATTRIBUTE:
46
               
47
                if (!xmID) {
48
                        std::cerr << "Error: MyClassInDll." << "getNodeName"<< " not found\n" << std::endl;
49
                        return NULL;
50
                } else {
51
                        jstring result = (jstring)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, value->xdmvalue));
52
                        if(!result) {
53
                                return NULL;
54
                        } else {
55
                                nodeName = proc->environ->env->GetStringUTFChars(result, NULL);
56
                                return nodeName;
57
                        } 
58
                }
59
            default:
60
                return NULL;
61
        }
62
        
63

    
64
    }
65
    
66
    const char* XdmNode::getBaseUri(){
67

    
68
        if(baseURI != NULL) {
69
                return baseURI;
70
        }
71

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

    
104

    
105

    
106

    
107
    XdmNode* XdmNode::getParent(){
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,
111
                                        "getParent",
112
                                        "()Lnet/sf/saxon/s9api/XdmNode;");
113
                if (!bmID) {
114
                        std::cerr << "Error: MyClassInDll." << "getParent"
115
                                << " not found\n" << std::endl;
116
                        return NULL;
117
                } else {
118
                        jobject nodeObj = (proc->environ->env->CallObjectMethod(value->xdmvalue, bmID));
119
                        if(nodeObj) {
120
                                parent = new XdmNode(NULL, nodeObj, UNKNOWN);
121
                                parent->setProcessor(proc);
122
                                //parent->incrementRefCount();
123
                                return parent;
124
                        }
125
                        return NULL;
126
                }
127
        } else {
128
                return parent;
129
        }
130
        
131
    }
132
    
133
    const char* XdmNode::getAttributeValue(const char *str){
134

    
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",
138
                                        "(Lnet/sf/saxon/s9api/XdmNode;Ljava/lang/String;)Ljava/lang/String;");
139
        if (!xmID) {
140
                        std::cerr << "Error: SaxonDll." << "getAttributeValue"
141
                                << " not found\n" << std::endl;
142
                        return NULL;
143
                }
144
        if(str == NULL) {
145
                return NULL;
146
        }
147
        jstring eqname = proc->environ->env->NewStringUTF(str);
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
152
        if(result) {
153
                const char * stri = proc->environ->env->GetStringUTFChars(result,
154
                                        NULL);
155
                
156
                //proc->environ->env->DeleteLocalRef(result);
157

    
158
                return stri;
159
        } else {
160

    
161
                return NULL;
162
        }
163

    
164
    }
165

    
166
    XdmNode** XdmNode::getAttributeNodes(){
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",
170
                                        "(Lnet/sf/saxon/s9api/XdmNode;)[Lnet/sf/saxon/s9api/XdmNode;");
171
                jobjectArray results = (jobjectArray)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
172
                value->xdmvalue));
173
                if(results == NULL) {
174
                        return NULL;        
175
                }
176
                int sizex = proc->environ->env->GetArrayLength(results);
177
                attrCount = sizex;
178
                if(sizex>0) {        
179
                        attrValues =  new XdmNode*[sizex];
180
                        XdmNode * tempNode =NULL;
181
                        for (int p=0; p < sizex; ++p){
182
                                jobject resulti = proc->environ->env->GetObjectArrayElement(results, p);
183
                                tempNode = new XdmNode(this, resulti, ATTRIBUTE);
184
                                tempNode->setProcessor(proc);
185
                                this->incrementRefCount();
186
                                attrValues[p] = tempNode;
187
                        }
188
                }
189
        } 
190
        return attrValues;
191
    }
192

    
193
    int XdmNode::getAttributeCount(){
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",
197
                                        "(Lnet/sf/saxon/s9api/XdmNode;)I");
198
                
199
                if (!xmID) {
200
                        std::cerr << "Error: SaxonDll." << "getAttributeCount"
201
                                << " not found\n" << std::endl;
202
                        return 0;
203
                }
204
                jint result = (jlong)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
205
                value->xdmvalue));
206

    
207
                attrCount =(int)result;
208
        }
209
        return attrCount;
210
    }
211

    
212
    int XdmNode::getChildCount(){
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",
216
                                        "(Lnet/sf/saxon/s9api/XdmNode;)I");
217
                
218
                if (!xmID) {
219
                        std::cerr << "Error: SaxonDll." << "getchildCount"
220
                                << " not found\n" << std::endl;
221
                        return 0;
222
                }
223
                jint result = (jlong)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,
224
                value->xdmvalue));
225

    
226
                childCount =(int)result;
227
        }
228
        return childCount;
229
    }
230
    
231
    XdmNode** XdmNode::getChildren(){
232

    
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",
236
                                        "(Lnet/sf/saxon/s9api/XdmNode;)[Lnet/sf/saxon/s9api/XdmNode;");
237
                
238
                if (!xmID) {
239
                        std::cerr << "Error: SaxonDll." << "getchildren"
240
                                << " not found\n" << std::endl;
241
                        return NULL;
242
                }
243
                jobjectArray results = (jobjectArray)(proc->environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, 
244
                value->xdmvalue));
245
                int sizex = proc->environ->env->GetArrayLength(results);
246
                childCount = sizex;        
247
                children =  new XdmNode*[sizex];
248
                XdmNode * tempNode = NULL;
249
                for (int p=0; p < sizex; ++p){
250
                        jobject resulti = proc->environ->env->GetObjectArrayElement(results, p);
251
                        tempNode = new XdmNode(this, resulti, UNKNOWN);
252
                        tempNode->setProcessor(proc);
253
                        //tempNode->incrementRefCount();
254
                        children[p] = tempNode;
255
                }
256
        }
257
        return children;
258

    
259
    }
260
  
(19-19/34)