Project

Profile

Help

Download (3.36 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / XdmAtomicValue.cpp @ 339c45ee

1 72bf04c6 Norman Walsh
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 a69dd173 O'Neil Delpratt
            valType = std::string(ty);
21
    }
22
23
    XdmAtomicValue::~XdmAtomicValue(){
24
        if(!valType.empty()) {
25
            valType.clear();
26
        }
27 72bf04c6 Norman Walsh
    }
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 901b6eca O'Neil Delpratt
38 72bf04c6 Norman Walsh
                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 ead48a5d O'Neil Delpratt
                jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmUtilsClass, xmID,value));
47 72bf04c6 Norman Walsh
                if(result) {
48
                        const char * stri = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
49 ead48a5d O'Neil Delpratt
                                        nullptr);
50 72bf04c6 Norman Walsh
                
51
                //SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
52
                        valType = std::string(stri);
53
                        return stri;
54
                }
55
56 901b6eca O'Neil Delpratt
            return "Q{http://www.w3.org/2001/XMLSchema}anyAtomicType";
57 72bf04c6 Norman Walsh
    }
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 ead48a5d O'Neil Delpratt
                        jboolean result = (jboolean)(SaxonProcessor::sxn_environ->env->CallBooleanMethod(value, bmID));
70 72bf04c6 Norman Walsh
                        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 ead48a5d O'Neil Delpratt
                        jdouble result = (jdouble)(SaxonProcessor::sxn_environ->env->CallDoubleMethod(value, bmID));
88 72bf04c6 Norman Walsh
                        if(result) {
89
                                return (double)result;
90
                        }
91 ead48a5d O'Neil Delpratt
//checkForException(*(SaxonProcessor::sxn_environ), nullptr);
92 72bf04c6 Norman Walsh
                }
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 ead48a5d O'Neil Delpratt
                        jlong result = (jlong)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, bmID));
114 72bf04c6 Norman Walsh
                        if(result) {
115
                                return (long)result;
116
                        }
117
                }
118
119
        return 0;
120
     }