Project

Profile

Help

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

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

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
        if(!valType.empty()) {
25
            valType.clear();
26
        }
27
    }
28

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

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

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

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

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

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

    
94
        return 0;
95
    }
96

    
97

    
98

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

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

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