Project

Profile

Help

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

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

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

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

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

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

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