Project

Profile

Help

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

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

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