Project

Profile

Help

Download (2.49 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / XdmItem.cpp @ 339c45ee

1 72bf04c6 Norman Walsh
2
3
#include "XdmItem.h"
4
5
XdmItem::XdmItem(): XdmValue(){
6 ead48a5d O'Neil Delpratt
        value = nullptr;
7 72bf04c6 Norman Walsh
}
8
9
    XdmItem::XdmItem(const XdmItem &other): XdmValue(other){
10 ead48a5d O'Neil Delpratt
        value = other.value;
11 72bf04c6 Norman Walsh
            xdmSize =1;
12
            refCount = other.refCount;
13
    }
14
15
16
XdmItem::XdmItem(jobject obj){
17 00082f6f O'Neil Delpratt
        value = SaxonProcessor::sxn_environ->env->NewGlobalRef(obj);
18 72bf04c6 Norman Walsh
        xdmSize =1;
19 a69dd173 O'Neil Delpratt
        refCount =0;
20 72bf04c6 Norman Walsh
}
21
22
bool XdmItem::isAtomic(){
23
        return false;
24
}
25
26
27
28 501beb26 O'Neil Delpratt
bool XdmItem::isNode(){
29
    return false;
30
31
}
32
33
bool XdmItem::isFunction(){
34
   return false;
35
36
}
37
38
39 146cfacb O'Neil Delpratt
XdmItem * XdmItem::getHead(){ return this;}
40 72bf04c6 Norman Walsh
41
  XdmItem * XdmItem::itemAt(int n){
42
        if (n < 0 || n >= size()) {
43 ead48a5d O'Neil Delpratt
                return nullptr;        
44 72bf04c6 Norman Walsh
        }
45
        return this;
46
  }
47
48
49
50
 int XdmItem::size(){
51
        return 1;        
52
   }
53
54
jobject XdmItem::getUnderlyingValue(){
55
#ifdef DEBUG
56
        std::cerr<<std::endl<<"XdmItem-getUnderlyingValue:"<<std::endl; 
57
#endif 
58 ead48a5d O'Neil Delpratt
        if(value == nullptr) {
59
                return nullptr;        
60 72bf04c6 Norman Walsh
        }
61 ead48a5d O'Neil Delpratt
        return value;
62 72bf04c6 Norman Walsh
}
63
64 a69dd173 O'Neil Delpratt
    const char * XdmItem:: getStringValue(){
65 72bf04c6 Norman Walsh
        if(stringValue.empty()) {
66
                    jclass xdmItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmItem");
67
                    jmethodID sbmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmItemClass,
68
                                            "getStringValue",
69
                                            "()Ljava/lang/String;");
70
                    if (!sbmID) {
71
                            std::cerr << "Error: Saxonc." << "getStringValue"
72
                                    << " not found\n" << std::endl;
73 ead48a5d O'Neil Delpratt
                            return nullptr;
74 72bf04c6 Norman Walsh
                    } else {
75 ead48a5d O'Neil Delpratt
                            jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, sbmID));
76 72bf04c6 Norman Walsh
                            if(result) {
77 ead48a5d O'Neil Delpratt
                                            const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
78 72bf04c6 Norman Walsh
                                            stringValue = std::string(str);
79
                        return stringValue.c_str();
80
                            }
81 ead48a5d O'Neil Delpratt
                            return nullptr;
82 72bf04c6 Norman Walsh
                    }
83
            } else {
84
                    return stringValue.c_str();
85
            }
86
   }
87
88
        /**
89
        * Get the type of the object
90
        */
91
        XDM_TYPE XdmItem::getType(){
92
                return XDM_ITEM;
93
        }
94 ead48a5d O'Neil Delpratt
95
XdmItem::~XdmItem() {
96 146cfacb O'Neil Delpratt
    //decrementRefCount();
97
98 00082f6f O'Neil Delpratt
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
99
100 146cfacb O'Neil Delpratt
    if(value !=nullptr && SaxonProcessor::jvmCreatedCPP>0) {
101
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
102
    }
103
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
104
    if(stringValue.empty()) {
105
        stringValue.clear();
106 ead48a5d O'Neil Delpratt
    }
107
}
108
109
void XdmItem::incrementRefCount() {
110
    refCount++;
111
    //std::cerr<<"refCount-inc-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
112
}
113
114
void XdmItem::decrementRefCount() {
115
    if (refCount > 0)
116
        refCount--;
117
    //std::cerr<<"refCount-dec-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
118
}