Project

Profile

Help

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

he / tags / 9.8.0.14 / hec / Saxon.C.API / XdmNode.cpp @ 02f8308b

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

    
25
    }
26

    
27
    const char * XdmNode::getNodeName(){
28
        
29
        if(nodeName != NULL) {
30
                return nodeName;
31
        }
32
        XDM_NODE_KIND kind = getNodeKind();
33
         jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
34
        jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getNodeName",
35
                                        "(Lnet/sf/saxon/s9api/XdmNode;)Ljava/lang/String;");
36
        switch (kind) {
37
            case DOCUMENT:
38
            case TEXT:
39
            case COMMENT:
40
                return NULL;
41
            case PROCESSING_INSTRUCTION:
42
            case NAMESPACE:
43
            case ELEMENT:
44
            case ATTRIBUTE:
45
               
46
                if (!xmID) {
47
                        std::cerr << "Error: MyClassInDll." << "getNodeName"<< " not found\n" << std::endl;
48
                        return NULL;
49
                } else {
50
                        jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID, value->xdmvalue));
51
                        if(!result) {
52
                                return NULL;
53
                        } else {
54
                                nodeName = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
55
                                return nodeName;
56
                        } 
57
                }
58
            default:
59
                return NULL;
60
        }
61
        
62

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

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

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

    
103

    
104

    
105

    
106
    XdmNode* XdmNode::getParent(){
107
        if(parent == NULL && proc!= NULL) {
108
                jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
109
                jmethodID bmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
110
                                        "getParent",
111
                                        "()Lnet/sf/saxon/s9api/XdmNode;");
112
                if (!bmID) {
113
                        std::cerr << "Error: MyClassInDll." << "getParent"
114
                                << " not found\n" << std::endl;
115
                        return NULL;
116
                } else {
117
                        jobject nodeObj = (SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, bmID));
118
                        if(nodeObj) {
119
                                parent = new XdmNode(NULL, nodeObj, UNKNOWN);
120
                                parent->setProcessor(proc);
121
                                //parent->incrementRefCount();
122
                                return parent;
123
                        }
124
                        return NULL;
125
                }
126
        } else {
127
                return parent;
128
        }
129
        
130
    }
131
    
132
    const char* XdmNode::getAttributeValue(const char *str){
133

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

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

    
157
                return stri;
158
        } else {
159

    
160
                return NULL;
161
        }
162

    
163
    }
164

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

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

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

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

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

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

    
258
    }
259
  
(25-25/45)