Project

Profile

Help

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

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

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 =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
                return nullptr;        
34
        }
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
        if(value == nullptr) {
49
                return nullptr;        
50
        }
51
        return value;
52
}
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
                            return nullptr;
64
                    } else {
65
                            jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, sbmID));
66
                            if(result) {
67
                                            const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
68
                                            stringValue = std::string(str);
69
                        return stringValue.c_str();
70
                            }
71
                            return nullptr;
72
                    }
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

    
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
}
(25-25/49)