Project

Profile

Help

Support #2625 » XdmValue.h

Duygu Colak, 2016-02-23 08:34

 
1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2014 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
#ifndef SAXON_XDMVALUE_H
9
#define SAXON_XDMVALUE_H
10

    
11

    
12
#include <string.h>
13
#include "SaxonProcessor.h"
14
#include <typeinfo> //used for testing only
15

    
16
/*! <code>XdmValue</code>. Value in the XDM data model. A value is a sequence of zero or more items,
17
 * each item being either an atomic value or a node. This class is a wrapper of the the XdmValue object created in Java.
18
 * <p/>
19
 */
20
using namespace std;
21
class SaxonApiException;
22
class SaxonProcessor;
23

    
24
class XdmValue {
25

    
26

    
27
public:
28
/**
29
     * A default Constructor. Create a empty value
30
     */
31
#        XdmValue(){
32
#                valueType='U';
33
#        }
34

    
35
    /**
36
     * A Constructor. Create an xs:boolean value
37
     * @param val - boolean value
38
     */
39
        XdmValue(bool val){
40
                valueBool= val;
41
                valueType= 'B';
42
        } 
43

    
44
    /**
45
     * A Constructor. Create an xs:string value
46
     * @param val - string value
47
     */
48
        XdmValue(string val){
49
                valueStr = val;
50
                valueType= 'S';        
51
        }
52

    
53
    /**
54
     * A Constructor. Create a XdmValue based on the target type. Conversion is applied if possible
55
     * @param type - specify target type of the value  
56
     * @param val - Value to convert
57
     */
58
        XdmValue(string tStr, string val){
59
                valueStr = val;
60
                typeStr = tStr;
61
                valueType= 'U';        
62
        }
63

    
64

    
65
    /**
66
     * A Constructor. Create an xs:string value
67
     * @param val - string value
68
     */
69
        XdmValue(char * val){
70
                valueStr = string(val);
71
                valueType= 'S';
72
        }
73

    
74
    /**
75
     * A Constructor. Create an xs:int value
76
     * @param val - int value
77
     */
78
        XdmValue(int val){
79
                valueType= 'I';
80
                valueInt = val;
81
        } 
82

    
83
        //TODO XdmValue with constructor of sequence of values
84

    
85
    /**
86
     * A Constructor. Wrap an Java XdmValue object.
87
     * @param val - Java XdmValue object
88
     */
89
        XdmValue(jobject val){
90
                xdmValuei = val;
91
                valueType='O';
92
        }
93

    
94

    
95
        ~XdmValue() {
96
                //proc->env->ReleaseObject
97
        }
98

    
99
        void releaseXdmValue(SaxonProcessor *proc);
100

    
101

    
102
    /**
103
     * Get Java XdmValue object.
104
     * @return jobject - The Java object of the XdmValue in its JNI representation
105
     */
106
        jobject getUnderlyingValue(SaxonProcessor *p);
107

    
108
    /**
109
     * Get the string representation of the XdmValue.
110
     * @return char array
111
     */
112
        const char * getStringValue(SaxonProcessor *p);
113
        
114
        void setProcessor(SaxonProcessor *p){processor = p;}
115

    
116
        const char * getErrorMessage(int i);
117
        const char * getErrorCode(int i);
118
        int exceptionCount();
119
        string checkFailures(){return failure;}
120
        SaxonProcessor *processor;
121
private:
122
        string typeStr;/*!< Internal usage.*/
123
        char valueType;  /*!< Internal usage. The type of the XdmValue, U Null, I Int, Z bool, S String, O jobject */
124
        string valueStr;  /*!< Internal usage. String representation of the XdmValue, if available */
125
        int valueInt;
126
        bool valueBool;
127
        jobject xdmValuei;
128
        SaxonApiException * exception;
129
        string failure;
130

    
131
};
132

    
133
#endif /** SAXON_XDMVALUE_H **/
(4-4/10)