Project

Profile

Help

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

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

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
XdmItem * XdmItem::getHead(){ return this;}
40

    
41
  XdmItem * XdmItem::itemAt(int n){
42
        if (n < 0 || n >= size()) {
43
                return nullptr;        
44
        }
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
        if(value == nullptr) {
59
                return nullptr;        
60
        }
61
        return value;
62
}
63

    
64
    const char * XdmItem:: getStringValue(){
65
        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
                            return nullptr;
74
                    } else {
75
                            jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, sbmID));
76
                            if(result) {
77
                                            const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
78
                                            stringValue = std::string(str);
79
                        return stringValue.c_str();
80
                            }
81
                            return nullptr;
82
                    }
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

    
95
XdmItem::~XdmItem() {
96
    //decrementRefCount();
97
    //std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
98

    
99
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
100

    
101
    if(value !=nullptr && SaxonProcessor::jvmCreatedCPP>0) {
102
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
103
    }
104
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
105
    if(stringValue.empty()) {
106
        stringValue.clear();
107
    }
108
}
109

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

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