Project

Profile

Help

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

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

1

    
2

    
3
#include "XdmItem.h"
4

    
5
XdmItem::XdmItem(): XdmValue(){
6
        value = nullptr;
7
}
8

    
9
    XdmItem::XdmItem(const XdmItem &other): XdmValue(other){
10
        value = other.value;
11
            xdmSize =1;
12
            refCount = other.refCount;
13
    }
14

    
15

    
16
XdmItem::XdmItem(jobject obj){
17
        value = obj;
18
        xdmSize =1;
19
        refCount =0;
20
}
21

    
22
bool XdmItem::isAtomic(){
23
        return false;
24
}
25

    
26

    
27

    
28
bool XdmItem::isNode(){
29
    return false;
30

    
31
}
32

    
33
bool XdmItem::isFunction(){
34
   return false;
35

    
36
}
37

    
38

    
39

    
40

    
41
   XdmItem * XdmItem::getHead(){ return this;}
42

    
43
  XdmItem * XdmItem::itemAt(int n){
44
        if (n < 0 || n >= size()) {
45
                return nullptr;        
46
        }
47
        return this;
48
  }
49

    
50

    
51

    
52
 int XdmItem::size(){
53
        return 1;        
54
   }
55

    
56
jobject XdmItem::getUnderlyingValue(){
57
#ifdef DEBUG
58
        std::cerr<<std::endl<<"XdmItem-getUnderlyingValue:"<<std::endl; 
59
#endif 
60
        if(value == nullptr) {
61
                return nullptr;        
62
        }
63
        return value;
64
}
65

    
66
    const char * XdmItem:: getStringValue(){
67
        if(stringValue.empty()) {
68
                    jclass xdmItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmItem");
69
                    jmethodID sbmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmItemClass,
70
                                            "getStringValue",
71
                                            "()Ljava/lang/String;");
72
                    if (!sbmID) {
73
                            std::cerr << "Error: Saxonc." << "getStringValue"
74
                                    << " not found\n" << std::endl;
75
                            return nullptr;
76
                    } else {
77
                            jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, sbmID));
78
                            if(result) {
79
                                            const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
80
                                            stringValue = std::string(str);
81
                        return stringValue.c_str();
82
                            }
83
                            return nullptr;
84
                    }
85
            } else {
86
                    return stringValue.c_str();
87
            }
88
   }
89

    
90
        /**
91
        * Get the type of the object
92
        */
93
        XDM_TYPE XdmItem::getType(){
94
                return XDM_ITEM;
95
        }
96

    
97
XdmItem::~XdmItem() {
98
    decrementRefCount();
99
    std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
100
    if(getRefCount()<1){
101
        if(value !=nullptr && SaxonProcessor::jvmCreatedCPP>0) {
102
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
103
        }
104

    
105
        if(stringValue.empty()) {
106
            stringValue.clear();
107
        }
108
    }
109
}
110

    
111
void XdmItem::incrementRefCount() {
112
    refCount++;
113
    //std::cerr<<"refCount-inc-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
114
}
115

    
116
void XdmItem::decrementRefCount() {
117
    if (refCount > 0)
118
        refCount--;
119
    //std::cerr<<"refCount-dec-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
120
}
(29-29/55)