Project

Profile

Help

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

he / src / main / c / Saxon.C.API / XdmAtomicValue.cpp @ 03fcd3f9

1

    
2
//
3

    
4
#include "XdmAtomicValue.h"
5

    
6
    XdmAtomicValue::XdmAtomicValue():XdmItem(){}
7

    
8
    XdmAtomicValue::XdmAtomicValue(const XdmAtomicValue &aVal): XdmItem(aVal){
9
        valType = aVal.valType;
10

    
11
    }
12

    
13
   
14
        
15

    
16
    XdmAtomicValue::XdmAtomicValue(jobject obj):XdmItem(obj){
17
    }
18

    
19
    XdmAtomicValue::XdmAtomicValue(jobject obj, const char* ty):XdmItem(obj){
20
            valType = std::string(ty);
21
    }
22

    
23
    XdmAtomicValue::~XdmAtomicValue(){
24
        std::cerr<<"XdmAtomicValue destructor called ref="<<getRefCount()<<std::endl;
25
        if(!valType.empty()) {
26
            valType.clear();
27
        }
28
    }
29

    
30
    void XdmAtomicValue::setType(const char * ty){
31
        valType = std::string(ty);
32
    }
33

    
34
    const char* XdmAtomicValue::getPrimitiveTypeName(){
35
        if(!valType.empty()) {
36
                return valType.c_str();        
37
        }
38

    
39
                jclass xdmUtilsClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmUtils");
40
                jmethodID xmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmUtilsClass,"getPrimitiveTypeName",
41
                                        "(Lnet/sf/saxon/s9api/XdmAtomicValue;)Ljava/lang/String;");
42
                if (!xmID) {
43
                        std::cerr << "Error: SaxonDll." << "getPrimitiveTypeName"
44
                                << " not found\n" << std::endl;
45
                        return "";
46
                }
47
                jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value));
48
                if(result) {
49
                        const char * stri = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
50
                                        nullptr);
51
                
52
                //SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
53
                        valType = std::string(stri);
54
                        return stri;
55
                }
56

    
57
            return "Q{http://www.w3.org/2001/XMLSchema}anyAtomicType";
58
    }
59

    
60
    bool XdmAtomicValue::getBooleanValue(){
61
                jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
62
                jmethodID bmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
63
                                        "getBooleanValue",
64
                                        "()Z");
65
                if (!bmID) {
66
                        std::cerr << "Error: MyClassInDll." << "getBooleanValue"
67
                                << " not found\n" << std::endl;
68
                        return false;
69
                } else {
70
                        jboolean result = (jboolean)(SaxonProcessor::sxn_environ->env->CallBooleanMethod(value, bmID));
71
                        if(result) {
72
                                return (bool)result;
73
                        }
74
                }
75
        return false;
76
    }
77

    
78
    double XdmAtomicValue::getDoubleValue(){
79
                jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
80
                jmethodID bmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
81
                                        "getDoubleValue",
82
                                        "()D");
83
                if (!bmID) {
84
                        std::cerr << "Error: MyClassInDll." << "getDecimalValue"
85
                                << " not found\n" << std::endl;
86
                        return 0;
87
                } else {
88
                        jdouble result = (jdouble)(SaxonProcessor::sxn_environ->env->CallDoubleMethod(value, bmID));
89
                        if(result) {
90
                                return (double)result;
91
                        }
92
//checkForException(*(SaxonProcessor::sxn_environ), nullptr);
93
                }
94

    
95
        return 0;
96
    }
97

    
98

    
99

    
100
    const char * XdmAtomicValue::getStringValue(){
101
                return XdmItem::getStringValue();
102
    }
103

    
104
    long XdmAtomicValue::getLongValue(){
105
                jclass xdmNodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
106
                jmethodID bmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmNodeClass,
107
                                        "getLongValue",
108
                                        "()J");
109
                if (!bmID) {
110
                        std::cerr << "Error: MyClassInDll." << "getLongValue"
111
                                << " not found\n" << std::endl;
112
                        return 0;
113
                } else {
114
                        jlong result = (jlong)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, bmID));
115
                        if(result) {
116
                                return (long)result;
117
                        }
118
                }
119

    
120
        return 0;
121
     }
(25-25/55)