Project

Profile

Help

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

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

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 = SaxonProcessor::sxn_environ->env->NewGlobalRef(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
    std::cout << std::endl << "cpp0-1" << std::endl;
101
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
102

    
103
    if(getRefCount()<1){
104
        if(value !=nullptr && SaxonProcessor::jvmCreatedCPP>0) {
105
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
106
        }
107
        std::cout << std::endl << "cpp0-1" << std::endl;
108
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
109
        if(stringValue.empty()) {
110
            stringValue.clear();
111
        }
112
    }
113
}
114

    
115
void XdmItem::incrementRefCount() {
116
    refCount++;
117
    //std::cerr<<"refCount-inc-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
118
}
119

    
120
void XdmItem::decrementRefCount() {
121
    if (refCount > 0)
122
        refCount--;
123
    //std::cerr<<"refCount-dec-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
124
}
(29-29/55)