Project

Profile

Help

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

he / latest9.9 / hec / Saxon.C.API / XdmItem.cpp @ 5401a5ae

1

    
2

    
3
#include "XdmItem.h"
4

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

    
9
    XdmItem::XdmItem(const XdmItem &other): XdmValue(other){
10
            value = (sxnc_value *)malloc(sizeof(sxnc_value));
11
        value->xdmvalue = other.value->xdmvalue;
12
            xdmSize =1;
13
            refCount = other.refCount;
14
    }
15

    
16

    
17
XdmItem::XdmItem(jobject obj){
18
        value = (sxnc_value *)malloc(sizeof(sxnc_value));
19
        value->xdmvalue = obj;
20
        xdmSize =1;
21
        refCount =1;
22
}
23

    
24
bool XdmItem::isAtomic(){
25
        return false;
26
}
27

    
28

    
29

    
30

    
31
   XdmItem * XdmItem::getHead(){ return this;}
32

    
33
  XdmItem * XdmItem::itemAt(int n){
34
        if (n < 0 || n >= size()) {
35
                return NULL;        
36
        }
37
        return this;
38
  }
39

    
40

    
41

    
42
 int XdmItem::size(){
43
        return 1;        
44
   }
45

    
46
jobject XdmItem::getUnderlyingValue(){
47
#ifdef DEBUG
48
        std::cerr<<std::endl<<"XdmItem-getUnderlyingValue:"<<std::endl; 
49
#endif 
50
        if(value == NULL) {
51
                return NULL;        
52
        }
53
        return value->xdmvalue;
54
}
55

    
56
    const char * XdmItem::getStringValue(){
57
        if(stringValue.empty()) {
58
                    jclass xdmItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmItem");
59
                    jmethodID sbmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmItemClass,
60
                                            "getStringValue",
61
                                            "()Ljava/lang/String;");
62
                    if (!sbmID) {
63
                            std::cerr << "Error: Saxonc." << "getStringValue"
64
                                    << " not found\n" << std::endl;
65
                            return NULL;
66
                    } else {
67
                            jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, sbmID));
68
                            if(result) {
69
                                            const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
70
                                            stringValue = std::string(str);
71
                        return stringValue.c_str();
72
                            }
73
                            return NULL;
74
                    }
75
            } else {
76
                    return stringValue.c_str();
77
            }
78
   }
79

    
80
        /**
81
        * Get the type of the object
82
        */
83
        XDM_TYPE XdmItem::getType(){
84
                return XDM_ITEM;
85
        }
(28-28/52)