Project

Profile

Help

Download (2.39 KB) Statistics
| Branch: | Tag: | Revision:

he / latest10 / hec / Saxon.C.API / XdmItem.cpp @ 6304fb8b

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