Project

Profile

Help

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

he / latest9.6 / hec / Saxon.C.API / XdmValue.cpp @ 4e3fba42

1
#include "XdmValue.h"
2
#include "XdmItem.h"
3

    
4
     //XdmValue::XdmValue(const XdmValue &other){
5
        //SaxonProcessor *proc = other.proc; //TODO
6
        /*char* valueType = NULL; 
7

8
        xdmSize=other.xdmSize;
9
        jValues = other.jValues;
10
     }*/
11

    
12
     int XdmValue::size(){
13
             return xdmSize;        
14
        }
15

    
16
      XdmValue::XdmValue(jobject val){
17
                XdmItem * value = new XdmItem(val);
18
                values.resize(0);//TODO memory issue might occur here
19
                values.push_back(value);
20
                xdmSize++; 
21
                jValues = NULL;
22
        valueType = NULL;
23
        }
24

    
25

    
26
        XdmValue::~XdmValue() {
27
                //proc->env->ReleaseObject
28
                for(int i =0; i< values.size(); i++){
29
                        if(values[i]->getRefCount()<1){
30
                                delete values[i];
31
                        }
32
                }
33
                values.clear();
34
                if(valueType != NULL) {delete valueType;}
35
                if(jValues && proc != NULL) {
36
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);
37
                }
38
                xdmSize=0;
39
        }
40

    
41
     void XdmValue::addXdmItem(XdmItem* val){
42
        if(val != NULL) {
43
                values.push_back(val);
44
                xdmSize++;
45
                jValues = NULL; //TODO clear jni array from memory if needed
46
        }        
47
    }
48

    
49

    
50
     XdmValue * XdmValue::addUnderlyingValue(jobject val){
51
        XdmItem * valuei = new XdmItem(val);
52
        valuei->setProcessor(proc);
53
        values.push_back(valuei);
54
        xdmSize++;
55
        jValues = NULL; //TODO clear jni array from memory if needed
56
                
57
    }
58

    
59

    
60

    
61

    
62
        XdmItem * XdmValue::getHead(){
63
                if(values.size() >0){
64
                        return values[0];
65
                } else {
66
                        return NULL;                
67
                }
68
        }
69

    
70
        jobject XdmValue::getUnderlyingValue(SaxonProcessor * proci){
71

    
72
                if(jValues == NULL) {        
73
                        proc = proci;        
74
                        jValues;
75
                        int i;
76
                        JNIEnv *env = SaxonProcessor::sxn_environ->env;
77
                        int count = values.size();
78
                        if(count == 0) {
79
                                return NULL;
80
                        }
81
                        jclass objectClass = lookForClass(env,
82
                                "java/lang/Object");
83
                        jValues = (jobjectArray)env->NewObjectArray((jint)count, objectClass,0);
84

    
85
                        for(i=0; i<count;i++){
86
                          env->SetObjectArrayElement(jValues,i,values[i]->getUnderlyingValue(proc));        
87
                        }
88
                }
89
                return (jobject)jValues;
90
        }
91

    
92
        void XdmValue::releaseXdmValue(){
93
        
94
        
95
        
96
        }
97

    
98
        XdmItem * XdmValue::itemAt(int n){
99
                /*if(jValues != NULL) {
100
                        values.clear();
101
                        int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(jvalues);
102
                        for (int p=0; p < sizex; ++p) 
103
                        {
104
                                jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(jValues, p);
105
                                values->addUnderlyingValue(resulti);
106
                        }
107
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);
108
                        jValues = NULL;
109
                }*/
110
                if(n >= 0 && n< values.size()) {
111
                        return values[n];
112
                }
113
                return NULL;
114
        }
115

    
116
        /**
117
        * Get the type of the object
118
        */
119
        XDM_TYPE XdmValue::getType(){
120
                return XDM_VALUE;
121
        }
122

    
123

    
124
     /**
125
     * Constructor. Create a value from a collection of items
126
     * @param container - entire container is expected
127
     */
128
//TODO
129
//Errors in codes. I will come back to this later. see guide: http://www.cplusplus.com/articles/SNywvCM9/
130
        /*template <class ContainerType>
131
     XdmValue::XdmValue(const ContainerType& container){
132
        ContainerType::const_iterator current(container.begin()), end(container.end());
133
        for( ; current != end; ++current)
134
        {
135
           std::cout << *current << ' ';
136
        }
137

138

139
     }*/
140

    
141
     /**
142
     * Constructor. Create a value from a collection of items
143
     * @param container - entire container is expected
144
     */
145
//TODO
146
     /*XdmValue::XdmValue(ForwardIteratorType begin, ForwardIteratorType end){
147

148

149

150
     }*/
151

    
152

    
153

    
154
/*
155
* XdmNode Class implementation
156
*/
157

    
158
      /*  jobject makeXdmValue(SaxonProcessor *proc, JNIEnv *env){
159
         if(env == NULL) {
160
                cerr<<"Error: env is null\n"<<endl;
161
         }
162
           jclass xdmValueClass = lookForClass(env, "net/sf/saxon/option/cpp/XdmValueForCpp");
163
           jmethodID MID_init = findConstructor (env, xdmValueClass, "()V");
164
            jobject xdmValue = (jobject)env->NewObject(xdmValueClass, MID_init);
165
                      if (!xdmValue) {
166
                        cerr<<"Error: failed to allocate an object\n"<<endl;
167
                        return NULL;
168
                      }
169

170
        
171
         return xdmValue;
172
        }
173

174

175
        jobject makeXdmValue(SaxonProcessor *proc, JNIEnv *env, bool b){ 
176
         if(env == NULL) {
177
                cerr<<"Error: env is null\n"<<endl;
178
         }
179
                jclass xdmValueClass = lookForClass(env, "net/sf/saxon/option/cpp/XdmValueForCpp");
180
                jmethodID MID_init = findConstructor (env, xdmValueClass, "(Z)V");
181
                 jobject xdmValue = (jobject)(env->NewObject(xdmValueClass, MID_init, (jboolean)b));
182
                      if (!xdmValue) {
183
                        cerr<<"Error: failed to allocate an object\n"<<endl;
184
                        return NULL;
185
                      }
186
                return xdmValue; from TLMax. 
187
        }
188

189
        jobject makeXdmValue(SaxonProcessor *proc, JNIEnv *env, int i){ 
190
         if(env == NULL) {
191
                cerr<<"Error: env is null\n"<<endl;
192
         }
193
                jclass xdmValueClass = lookForClass(env, "net/sf/saxon/option/cpp/XdmValueForCpp");
194
                jmethodID MID_init = findConstructor (env, xdmValueClass, "(I)V");
195
                 jobject xdmValue = (jobject)(env->NewObject(xdmValueClass, MID_init, (jint)i));
196
                      if (!xdmValue) {
197
                        cerr<<"Error: failed to allocate an XdmValueForCpp object \n"<<endl;
198
                        return NULL;
199
                      }
200
                return xdmValue;
201
        }
202

203

204
        jobject makeXdmValue(SaxonProcessor *proc, JNIEnv *env, string type, string valueStr){ 
205
         if(env == NULL) {
206
                cerr<<"Error: env is null\n"<<endl;
207
         }
208
                jclass xdmValueClass = lookForClass(env, "net/sf/saxon/option/cpp/XdmValueForCpp");
209
                jmethodID MID_init = findConstructor (env, xdmValueClass, "(Ljava/lang/String;Ljava/lang/String;)V");
210
                if(!MID_init) {
211
                        cerr<<"methodID not found"<<endl;
212
                }
213
                 jobject xdmValue = (jobject)(env->NewObject(xdmValueClass, MID_init, env->NewStringUTF(type.c_str()), env->NewStringUTF(valueStr.c_str())));
214
                
215
        
216
                      if (xdmValue==NULL) {
217
                        const char * errStr = checkForException(env, xdmValueClass, xdmValue);
218
                        cerr<<"Error: failed to allocate an XdmValueValue object";
219
                        if(errStr){                        
220
                                cerr<< errStr 
221
                        }
222
                        cerr<<"\n"<<endl;
223
                        return NULL;
224
                      }
225
                return xdmValue;
226
        }
227

228

229
        jobject makeXdmValue(SaxonProcessor *proc, JNIEnv *env, string valueStr){ 
230
         if(env == NULL) {
231
                cerr<<"Error: env is null\n"<<endl;
232
         }
233
                jclass xdmValueClass = lookForClass(env, "net/sf/saxon/option/cpp/XdmValueForCpp");
234
                jmethodID MID_init = findConstructor (env, xdmValueClass, "(Ljava/lang/String;Ljava/lang/String;)V");
235
                 jobject xdmValue = (jobject)(env->NewObject(xdmValueClass, MID_init, env->NewStringUTF("string"), env->NewStringUTF(valueStr.c_str())));
236

237
        
238
                      if (xdmValue==NULL) {
239
                        const char * errStr = checkForException(env, xdmValueClass, xdmValue);
240
                        cerr<<"Error: failed to allocate an XdmValueValue object";
241
                        if(errStr){                        
242
                                cerr<< errStr 
243
                        }
244
                        cerr<<"\n"<<endl;
245
                        return NULL;
246
                      }
247
                return xdmValue;
248
        }
249

250
  const char * XdmValue::getErrorMessage(int i){
251
        if(proc->exception== NULL) return NULL;
252
        return proc->exception->getErrorMessage(i);
253
    }
254

255
    const char * XdmValue::getErrorCode(int i) {
256
        if(proc->exception== NULL) return NULL;
257
        return proc->exception->getErrorCode(i);
258
     }
259

260
  int XdmValue::exceptionCount(){
261
                return proc->exception->count();
262
        }
263

264
   */
265

    
266
        
267

    
268

    
(24-24/37)