Clean up some SonarQube warnings (trailing whitespace, etc).
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniOcRepresentation.cpp
1 /*
2 * //******************************************************************
3 * //
4 * // Copyright 2015 Intel Corporation.
5 * //
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 * //
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
11 * //
12 * //      http://www.apache.org/licenses/LICENSE-2.0
13 * //
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
19 * //
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 */
22 #include "JniOcRepresentation.h"
23 #include "JniUtils.h"
24
25 using namespace OC;
26
27 OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobject thiz)
28 {
29     OCRepresentation *rep = GetHandle<OCRepresentation>(env, thiz);
30     if (env->ExceptionCheck())
31     {
32         LOGE("Failed to get native handle from OcRepresentation");
33     }
34     if (!rep)
35     {
36         ThrowOcException(JNI_NO_NATIVE_POINTER, "");
37     }
38     return rep;
39 }
40
41 /*
42 * Class:     org_iotivity_base_OcRepresentation
43 * Method:    getValueN
44 * Signature: (Ljava/lang/String;)Ljava/lang/Object;
45 */
46 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN
47 (JNIEnv *env, jobject thiz, jstring jKey)
48 {
49     LOGD("OcRepresentation_getValue");
50     if (!jKey)
51     {
52         ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
53         return nullptr;
54     }
55     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
56     if (!rep) return nullptr;
57
58     std::string key = env->GetStringUTFChars(jKey, NULL);
59
60     AttributeValue attrValue;
61     if (!rep->getAttributeValue(key.c_str(), attrValue))
62     {
63         ThrowOcException(JNI_NO_SUCH_KEY, " attribute key does not exist");
64         return nullptr;
65     }
66     return boost::apply_visitor(JObjectConverter(env), attrValue);
67 }
68
69 /*
70 * Class:     org_iotivity_base_OcRepresentation
71 * Method:    setValueInteger
72 * Signature: (Ljava/lang/String;I)V
73 */
74 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
75 (JNIEnv *env, jobject thiz, jstring jKey, jint jValue)
76 {
77     LOGD("OcRepresentation_setValueInteger");
78     if (!jKey)
79     {
80         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
81         return;
82     }
83     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
84     if (!rep) return;
85
86     std::string str = env->GetStringUTFChars(jKey, NULL);
87     rep->setValue(str, static_cast<int>(jValue));
88 }
89
90 /*
91 * Class:     org_iotivity_base_OcRepresentation
92 * Method:    setValueDouble
93 * Signature: (Ljava/lang/String;D)V
94 */
95 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble
96 (JNIEnv *env, jobject thiz, jstring jKey, jdouble jValue)
97 {
98     LOGD("OcRepresentation_setValueDouble");
99     if (!jKey)
100     {
101         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
102         return;
103     }
104     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
105     if (!rep) return;
106
107     std::string str = env->GetStringUTFChars(jKey, NULL);
108     rep->setValue(str, static_cast<double>(jValue));
109 }
110
111 /*
112 * Class:     org_iotivity_base_OcRepresentation
113 * Method:    setValueBoolean
114 * Signature: (Ljava/lang/String;Z)V
115 */
116 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean
117 (JNIEnv *env, jobject thiz, jstring jKey, jboolean jValue)
118 {
119     LOGD("OcRepresentation_setValueBoolean");
120     if (!jKey)
121     {
122         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
123         return;
124     }
125     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
126     if (!rep) return;
127
128     std::string str = env->GetStringUTFChars(jKey, NULL);
129     rep->setValue(str, static_cast<bool>(jValue));
130 }
131
132 /*
133 * Class:     org_iotivity_base_OcRepresentation
134 * Method:    setValueStringN
135 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
136 */
137 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringN
138 (JNIEnv *env, jobject thiz, jstring jKey, jstring jValue)
139 {
140     LOGD("OcRepresentation_setValueString");
141     if (!jKey)
142     {
143         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
144         return;
145     }
146     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
147     if (!rep) return;
148
149     std::string key = env->GetStringUTFChars(jKey, NULL);
150     std::string value = env->GetStringUTFChars(jValue, NULL);
151
152     rep->setValue(key, value);
153 }
154
155 /*
156 * Class:     org_iotivity_base_OcRepresentation
157 * Method:    setValueRepresentation
158 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;)V
159 */
160 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation
161 (JNIEnv *env, jobject thiz, jstring jKey, jobject jValue)
162 {
163     LOGD("OcRepresentation_setValueRepresentation");
164     if (!jKey)
165     {
166         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
167         return;
168     }
169     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
170     if (!rep) return;
171
172     std::string key = env->GetStringUTFChars(jKey, NULL);
173     OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
174     if (!value) return;
175
176     rep->setValue(key, *value);
177 }
178
179 /*
180 * Class:     org_iotivity_base_OcRepresentation
181 * Method:    setValueIntegerArray
182 * Signature: (Ljava/lang/String;[I)V
183 */
184 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerArray
185 (JNIEnv *env, jobject thiz, jstring jKey, jintArray jValue)
186 {
187     LOGD("OcRepresentation_setValueIntegerArray");
188     if (!jKey)
189     {
190         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
191         return;
192     }
193
194     const jsize len = env->GetArrayLength(jValue);
195     jint* ints = env->GetIntArrayElements(jValue, NULL);
196
197     std::vector<int> value;
198     for (jsize i = 0; i < len; ++i)
199     {
200         value.push_back(static_cast<int>(ints[i]));
201     }
202     env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT);
203
204     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
205     if (!rep) return;
206
207     std::string key = env->GetStringUTFChars(jKey, NULL);
208     rep->setValue(key, value);
209 }
210
211 /*
212 * Class:     org_iotivity_base_OcRepresentation
213 * Method:    setValueInteger2DArray
214 * Signature: (Ljava/lang/String;[[I)V
215 */
216 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2DArray
217 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
218 {
219     LOGD("OcRepresentation__setValueInteger2DArray");
220     if (!jKey)
221     {
222         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
223         return;
224     }
225     std::vector<std::vector<int>> value;
226     const jsize lenOuter = env->GetArrayLength(jValue);
227     for (jsize j = 0; j < lenOuter; ++j)
228     {
229         jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jValue, j));
230         jint* ints = env->GetIntArrayElements(jInnerArray, NULL);
231         std::vector<int> innerVector;
232         const jsize lenInner = env->GetArrayLength(jInnerArray);
233         for (jsize i = 0; i < lenInner; ++i)
234         {
235             innerVector.push_back(static_cast<int>(ints[i]));
236         }
237         env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
238         env->DeleteLocalRef(jInnerArray);
239         value.push_back(innerVector);
240     }
241
242     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
243     if (!rep) return;
244
245     std::string key = env->GetStringUTFChars(jKey, NULL);
246     rep->setValue(key, value);
247 }
248
249 /*
250 * Class:     org_iotivity_base_OcRepresentation
251 * Method:    setValueInteger3DArray
252 * Signature: (Ljava/lang/String;[[[I)V
253 */
254 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3DArray
255 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
256 {
257     LOGD("OcRepresentation_setValueInteger3DArray");
258     if (!jKey)
259     {
260         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
261         return;
262     }
263     std::vector<std::vector<std::vector<int>>> value;
264     const jsize lenOuter = env->GetArrayLength(jValue);
265     for (jsize k = 0; k < lenOuter; ++k)
266     {
267         jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
268         const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
269         std::vector<std::vector<int>> middleArray;
270         for (jsize j = 0; j < lenMiddle; ++j)
271         {
272             jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jMiddleArray, j));
273             jint* ints = env->GetIntArrayElements(jInnerArray, NULL);
274             std::vector<int> innerVector;
275             const jsize lenInner = env->GetArrayLength(jInnerArray);
276             for (jsize i = 0; i < lenInner; ++i)
277             {
278                 innerVector.push_back(static_cast<int>(ints[i]));
279             }
280             env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
281             env->DeleteLocalRef(jInnerArray);
282             middleArray.push_back(innerVector);
283         }
284         env->DeleteLocalRef(jMiddleArray);
285         value.push_back(middleArray);
286     }
287
288     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
289     if (!rep) return;
290
291     std::string key = env->GetStringUTFChars(jKey, NULL);
292     rep->setValue(key, value);
293 }
294
295 /*
296 * Class:     org_iotivity_base_OcRepresentation
297 * Method:    setValueDoubleArray
298 * Signature: (Ljava/lang/String;[D)V
299 */
300 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArray
301 (JNIEnv *env, jobject thiz, jstring jKey, jdoubleArray jValue)
302 {
303     LOGD("OcRepresentation_setValueDoubleArray");
304     if (!jKey)
305     {
306         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
307         return;
308     }
309
310     const jsize len = env->GetArrayLength(jValue);
311     jdouble* doubles = env->GetDoubleArrayElements(jValue, NULL);
312
313     std::vector<double> value;
314     for (jsize i = 0; i < len; ++i)
315     {
316         value.push_back(static_cast<double>(doubles[i]));
317     }
318     env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT);
319
320     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
321     if (!rep) return;
322
323     std::string key = env->GetStringUTFChars(jKey, NULL);
324     rep->setValue(key, value);
325 }
326
327 /*
328 * Class:     org_iotivity_base_OcRepresentation
329 * Method:    setValueDouble2DArray
330 * Signature: (Ljava/lang/String;[[D)V
331 */
332 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DArray
333 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
334 {
335     LOGD("OcRepresentation_setValueDouble2DArray");
336     if (!jKey)
337     {
338         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
339         return;
340     }
341     std::vector<std::vector<double>> value;
342     const jsize lenOuter = env->GetArrayLength(jValue);
343     for (jsize j = 0; j < lenOuter; ++j)
344     {
345         jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jValue, j));
346         jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, NULL);
347         std::vector<double> innerVector;
348         const jsize lenInner = env->GetArrayLength(jInnerArray);
349         for (jsize i = 0; i < lenInner; ++i)
350         {
351             innerVector.push_back(static_cast<double>(doubles[i]));
352         }
353         env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
354         env->DeleteLocalRef(jInnerArray);
355         value.push_back(innerVector);
356     }
357
358     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
359     if (!rep) return;
360
361     std::string key = env->GetStringUTFChars(jKey, NULL);
362     rep->setValue(key, value);
363 }
364
365 /*
366 * Class:     org_iotivity_base_OcRepresentation
367 * Method:    setValueDouble3DArray
368 * Signature: (Ljava/lang/String;[[[D)V
369 */
370 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DArray
371 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
372 {
373     LOGD("OcRepresentation_setValueDouble3DArray");
374     if (!jKey)
375     {
376         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
377         return;
378     }
379     std::vector<std::vector<std::vector<double>>> value;
380     const jsize lenOuter = env->GetArrayLength(jValue);
381     for (jsize k = 0; k < lenOuter; ++k)
382     {
383         jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
384         const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
385         std::vector<std::vector<double>> middleArray;
386         for (jsize j = 0; j < lenMiddle; ++j)
387         {
388             jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jMiddleArray, j));
389             jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, NULL);
390             std::vector<double> innerVector;
391             const jsize lenInner = env->GetArrayLength(jInnerArray);
392             for (jsize i = 0; i < lenInner; ++i)
393             {
394                 innerVector.push_back(static_cast<double>(doubles[i]));
395             }
396             env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
397             env->DeleteLocalRef(jInnerArray);
398             middleArray.push_back(innerVector);
399         }
400         env->DeleteLocalRef(jMiddleArray);
401         value.push_back(middleArray);
402     }
403
404     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
405     if (!rep) return;
406
407     std::string key = env->GetStringUTFChars(jKey, NULL);
408     rep->setValue(key, value);
409 }
410
411 /*
412 * Class:     org_iotivity_base_OcRepresentation
413 * Method:    setValueBooleanArray
414 * Signature: (Ljava/lang/String;[Z)V
415 */
416 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanArray
417 (JNIEnv *env, jobject thiz, jstring jKey, jbooleanArray jValue)
418 {
419     LOGD("OcRepresentation_setValueBooleanArray");
420     if (!jKey)
421     {
422         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
423         return;
424     }
425
426     const jsize len = env->GetArrayLength(jValue);
427     jboolean* booleans = env->GetBooleanArrayElements(jValue, NULL);
428
429     std::vector<bool> value;
430     for (jsize i = 0; i < len; ++i)
431     {
432         value.push_back(static_cast<bool>(booleans[i]));
433     }
434     env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT);
435
436     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
437     if (!rep) return;
438
439     std::string key = env->GetStringUTFChars(jKey, NULL);
440     rep->setValue(key, value);
441 }
442
443 /*
444 * Class:     org_iotivity_base_OcRepresentation
445 * Method:    setValueBoolean2DArray
446 * Signature: (Ljava/lang/String;[[Z)V
447 */
448 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2DArray
449 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
450 {
451     LOGD("OcRepresentation_setValueBoolean2DArray");
452     if (!jKey)
453     {
454         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
455         return;
456     }
457     std::vector<std::vector<bool>> value;
458     const jsize lenOuter = env->GetArrayLength(jValue);
459     for (jsize j = 0; j < lenOuter; ++j)
460     {
461         jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jValue, j));
462         const jsize lenInner = env->GetArrayLength(jInnerArray);
463         jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, NULL);
464
465         std::vector<bool> innerVector;
466         for (jsize i = 0; i < lenInner; ++i)
467         {
468             innerVector.push_back(static_cast<bool>(booleans[i]));
469         }
470         env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
471         env->DeleteLocalRef(jInnerArray);
472         value.push_back(innerVector);
473     }
474
475     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
476     if (!rep) return;
477
478     std::string key = env->GetStringUTFChars(jKey, NULL);
479     rep->setValue(key, value);
480 }
481
482 /*
483 * Class:     org_iotivity_base_OcRepresentation
484 * Method:    setValueBoolean3DArray
485 * Signature: (Ljava/lang/String;[[[Z)V
486 */
487 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3DArray
488 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
489 {
490     LOGD("OcRepresentation_setValueBoolean3DArray");
491     if (!jKey)
492     {
493         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
494         return;
495     }
496     std::vector<std::vector<std::vector<bool>>> value;
497     const jsize lenOuter = env->GetArrayLength(jValue);
498     for (jsize k = 0; k < lenOuter; ++k)
499     {
500         jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
501         const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
502         std::vector<std::vector<bool>> middleArray;
503         for (jsize j = 0; j < lenMiddle; ++j)
504         {
505             jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jMiddleArray, j));
506             const jsize lenInner = env->GetArrayLength(jInnerArray);
507             jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, NULL);
508
509             std::vector<bool> innerVector;
510             for (jsize i = 0; i < lenInner; ++i)
511             {
512                 innerVector.push_back(static_cast<bool>(booleans[i]));
513             }
514             env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
515             env->DeleteLocalRef(jInnerArray);
516             middleArray.push_back(innerVector);
517         }
518         env->DeleteLocalRef(jMiddleArray);
519         value.push_back(middleArray);
520     }
521
522     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
523     if (!rep) return;
524
525     std::string key = env->GetStringUTFChars(jKey, NULL);
526     rep->setValue(key, value);
527 }
528
529 /*
530 * Class:     org_iotivity_base_OcRepresentation
531 * Method:    setValueStringArray
532 * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
533 */
534 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArray
535 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
536 {
537     LOGD("OcRepresentation_setValueStringArray");
538     if (!jKey)
539     {
540         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
541         return;
542     }
543
544     std::vector<std::string> value;
545     JniUtils::convertJavaStrArrToStrVector(env, jValue, value);
546
547     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
548     if (!rep) return;
549
550     std::string key = env->GetStringUTFChars(jKey, NULL);
551     rep->setValue(key, value);
552 }
553
554 /*
555 * Class:     org_iotivity_base_OcRepresentation
556 * Method:    setValueString2DArray
557 * Signature: (Ljava/lang/String;[[Ljava/lang/String;)V
558 */
559 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DArray
560 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
561 {
562     LOGD("OcRepresentation_setValueString2DArray");
563     if (!jKey)
564     {
565         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
566         return;
567     }
568     std::vector<std::vector<std::string>> value;
569     const jsize lenOuter = env->GetArrayLength(jValue);
570     for (jsize j = 0; j < lenOuter; ++j)
571     {
572         jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
573         std::vector<std::string> innerVector;
574         JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
575         env->DeleteLocalRef(jInnerArray);
576         value.push_back(innerVector);
577     }
578
579     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
580     if (!rep) return;
581
582     std::string key = env->GetStringUTFChars(jKey, NULL);
583     rep->setValue(key, value);
584 }
585
586 /*
587 * Class:     org_iotivity_base_OcRepresentation
588 * Method:    setValueString3DArray
589 * Signature: (Ljava/lang/String;[[[Ljava/lang/String;)V
590 */
591 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DArray
592 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
593 {
594     LOGD("OcRepresentation_setValueString3DArray");
595     if (!jKey)
596     {
597         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
598         return;
599     }
600     std::vector<std::vector<std::vector<std::string>>> value;
601     const jsize lenOuter = env->GetArrayLength(jValue);
602     for (jsize k = 0; k < lenOuter; ++k)
603     {
604         jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
605         const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
606         std::vector<std::vector<std::string>> middleArray;
607         for (jsize j = 0; j < lenMiddle; ++j)
608         {
609             jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
610             std::vector<std::string> innerVector;
611             JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
612             env->DeleteLocalRef(jInnerArray);
613             middleArray.push_back(innerVector);
614         }
615         env->DeleteLocalRef(jMiddleArray);
616         value.push_back(middleArray);
617     }
618
619     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
620     if (!rep) return;
621
622     std::string key = env->GetStringUTFChars(jKey, NULL);
623     rep->setValue(key, value);
624 }
625
626 /*
627 * Class:     org_iotivity_base_OcRepresentation
628 * Method:    setValueRepresentationArray
629 * Signature: (Ljava/lang/String;[Lorg/iotivity/base/OcRepresentation;)V
630 */
631 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentationArray
632 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
633 {
634     LOGD("OcRepresentation_setValueRepresentationArray");
635     if (!jKey)
636     {
637         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
638         return;
639     }
640
641     std::vector<OCRepresentation> value;
642     JniUtils::convertJavaRepresentationArrToVector(env, jValue, value);
643
644     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
645     if (!rep) return;
646
647     std::string key = env->GetStringUTFChars(jKey, NULL);
648     rep->setValue(key, value);
649 }
650
651 /*
652 * Class:     org_iotivity_base_OcRepresentation
653 * Method:    setValueRepresentation2DArray
654 * Signature: (Ljava/lang/String;[[Lorg/iotivity/base/OcRepresentation;)V
655 */
656 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation2DArray
657 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
658 {
659     LOGD("OcRepresentation_setValueRepresentation2DArray");
660     if (!jKey)
661     {
662         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
663         return;
664     }
665     std::vector<std::vector<OCRepresentation>> value;
666     const jsize lenOuter = env->GetArrayLength(jValue);
667     for (jsize j = 0; j < lenOuter; ++j)
668     {
669         jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
670         std::vector<OCRepresentation> innerVector;
671         JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
672         env->DeleteLocalRef(jInnerArray);
673         value.push_back(innerVector);
674     }
675
676     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
677     if (!rep) return;
678
679     std::string key = env->GetStringUTFChars(jKey, NULL);
680     rep->setValue(key, value);
681 }
682
683 /*
684 * Class:     org_iotivity_base_OcRepresentation
685 * Method:    setValueRepresentation3DArray
686 * Signature: (Ljava/lang/String;[[[Lorg/iotivity/base/OcRepresentation;)V
687 */
688 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation3DArray
689 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
690 {
691     LOGD("OcRepresentation_setValueRepresentation3DArray");
692     if (!jKey)
693     {
694         ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
695         return;
696     }
697     std::vector<std::vector<std::vector<OCRepresentation>>> value;
698     const jsize lenOuter = env->GetArrayLength(jValue);
699     for (jsize k = 0; k < lenOuter; ++k)
700     {
701         jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
702         const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
703         std::vector<std::vector<OCRepresentation>> middleArray;
704         for (jsize j = 0; j < lenMiddle; ++j)
705         {
706             jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
707             std::vector<OCRepresentation> innerVector;
708             JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
709             env->DeleteLocalRef(jInnerArray);
710             middleArray.push_back(innerVector);
711         }
712         env->DeleteLocalRef(jMiddleArray);
713         value.push_back(middleArray);
714     }
715
716     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
717     if (!rep) return;
718
719     std::string key = env->GetStringUTFChars(jKey, NULL);
720     rep->setValue(key, value);
721 }
722
723 /*
724 * Class:     org_iotivity_base_OcRepresentation
725 * Method:    addChild
726 * Signature: (Lorg/iotivity/base/OcRepresentation;)V
727 */
728 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
729 (JNIEnv *env, jobject thiz, jobject jOcRepresentation)
730 {
731     LOGD("OcRepresentation_addChild");
732     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
733     if (!rep) return;
734
735     OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
736     if (!child) return;
737
738     rep->addChild(*child);
739 }
740
741 /*
742 * Class:     org_iotivity_base_OcRepresentation
743 * Method:    clearChildren
744 * Signature: ()V
745 */
746 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren
747 (JNIEnv *env, jobject thiz)
748 {
749     LOGD("OcRepresentation_clearChildren");
750     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
751     if (!rep) return;
752
753     rep->clearChildren();
754 }
755
756 /*
757 * Class:     org_iotivity_base_OcRepresentation
758 * Method:    getChildrenArray
759 * Signature: ()[Lorg/iotivity/base/OcRepresentation;
760 */
761 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
762 (JNIEnv *env, jobject thiz)
763 {
764     LOGD("OcRepresentation_getChildrenArray");
765     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
766     if (!rep) return nullptr;
767
768     return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
769 }
770
771 /*
772 * Class:     org_iotivity_base_OcRepresentation
773 * Method:    getUri
774 * Signature: ()Ljava/lang/String;
775 */
776 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri
777 (JNIEnv *env, jobject thiz)
778 {
779     LOGD("OcRepresentation_getUri");
780     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
781     if (!rep) return nullptr;
782
783     std::string uri(rep->getUri());
784     return env->NewStringUTF(uri.c_str());
785 }
786
787 /*
788 * Class:     org_iotivity_base_OcRepresentation
789 * Method:    setUri
790 * Signature: (Ljava/lang/String;)V
791 */
792 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri
793 (JNIEnv *env, jobject thiz, jstring jUri)
794 {
795     LOGD("OcRepresentation_setUri");
796     if (!jUri)
797     {
798         ThrowOcException(OC_STACK_INVALID_PARAM, "uri cannot be null");
799         return;
800     }
801     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
802     if (!rep) return;
803
804     rep->setUri(env->GetStringUTFChars(jUri, NULL));
805 }
806
807 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute
808 (JNIEnv *env, jobject thiz, jstring jstr)
809 {
810     LOGD("OcRepresentation_hasAttribute");
811     if (!jstr)
812     {
813         ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
814         return false;
815     }
816     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
817     if (!rep) return false;
818
819     std::string str = env->GetStringUTFChars(jstr, NULL);
820     return rep->hasAttribute(str);
821 }
822
823 /*
824 * Class:     org_iotivity_base_OcRepresentation
825 * Method:    getResourceTypes
826 * Signature: ()Ljava/util/List;
827 */
828 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTypes
829 (JNIEnv *env, jobject thiz)
830 {
831     LOGD("OcRepresentation_getResourceTypes");
832     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
833     if (!rep) return nullptr;
834
835     std::vector<std::string> resourceTypes = rep->getResourceTypes();
836     return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
837 }
838
839 /*
840 * Class:     org_iotivity_base_OcRepresentation
841 * Method:    setResourceTypeArray
842 * Signature: ([Ljava/lang/String;)V
843 */
844 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeArray
845 (JNIEnv *env, jobject thiz, jobjectArray jResourceTypeArray)
846 {
847     LOGD("OcRepresentation_setResourceTypeArray");
848     if (!jResourceTypeArray)
849     {
850         ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");
851         return;
852     }
853     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
854     if (!rep) return;
855
856     std::vector<std::string> resourceTypes;
857     JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
858     rep->setResourceTypes(resourceTypes);
859 }
860 /*
861 * Class:     org_iotivity_base_OcRepresentation
862 * Method:    getResourceInterfaces
863 * Signature: ()Ljava/util/List;
864 */
865 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInterfaces
866 (JNIEnv *env, jobject thiz)
867 {
868     LOGD("OcRepresentation_getResourceInterfaces");
869     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
870     if (!rep) return nullptr;
871
872     std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
873     return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
874 }
875
876 /*
877 * Class:     org_iotivity_base_OcRepresentation
878 * Method:    setResourceInterfaceArray
879 * Signature: ([Ljava/lang/String;)V
880 */
881 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterfaceArray
882 (JNIEnv *env, jobject thiz, jobjectArray jResourceInterfaceArray)
883 {
884     LOGD("OcRepresentation_setResourceInterfaceArray");
885     if (!jResourceInterfaceArray)
886     {
887         ThrowOcException(OC_STACK_INVALID_PARAM, "resourceInterfaceList cannot be null");
888         return;
889     }
890     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
891     if (!rep) return;
892
893     std::vector<std::string> resourceInterfaces;
894     JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
895     rep->setResourceInterfaces(resourceInterfaces);
896 }
897
898 /*
899 * Class:     org_iotivity_base_OcRepresentation
900 * Method:    isEmpty
901 * Signature: ()Z
902 */
903 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty
904 (JNIEnv *env, jobject thiz)
905 {
906     LOGD("OcRepresentation_isEmpty");
907     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
908     if (!rep) return false;
909
910     return static_cast<jboolean>(rep->empty());
911 }
912
913 /*
914 * Class:     org_iotivity_base_OcRepresentation
915 * Method:    size
916 * Signature: ()I
917 */
918 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size
919 (JNIEnv *env, jobject thiz)
920 {
921     LOGD("OcRepresentation_size");
922     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
923     if (!rep) return -1;
924
925     return static_cast<jint>(rep->numberOfAttributes());
926 }
927
928 /*
929 * Class:     org_iotivity_base_OcRepresentation
930 * Method:    remove
931 * Signature: (Ljava/lang/String;)Z
932 */
933 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove
934 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
935 {
936     LOGD("OcRepresentation_remove");
937     if (!jAttributeKey)
938     {
939         ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
940         return false;
941     }
942     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
943     if (!rep) return false;
944
945     std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
946     return static_cast<jboolean>(rep->erase(attributeKey));
947 }
948
949 /*
950 * Class:     org_iotivity_base_OcRepresentation
951 * Method:    setNull
952 * Signature: (Ljava/lang/String;)V
953 */
954 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull
955 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
956 {
957     LOGD("OcRepresentation_setNull");
958     if (!jAttributeKey)
959     {
960         ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
961         return;
962     }
963     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
964     if (!rep) return;
965
966     std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
967     rep->setNULL(attributeKey);
968 }
969
970 /*
971 * Class:     org_iotivity_base_OcRepresentation
972 * Method:    isNull
973 * Signature: (Ljava/lang/String;)Z
974 */
975 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull
976 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
977 {
978     LOGD("OcRepresentation_isNull");
979     if (!jAttributeKey)
980     {
981         ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
982         return false;
983     }
984     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
985     if (!rep) return false;
986
987     std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
988     return static_cast<jboolean>(rep->isNULL(attributeKey));
989 }
990
991 /*
992 * Class:     org_iotivity_base_OcRepresentation
993 * Method:    create
994 * Signature: ()V
995 */
996 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_create
997 (JNIEnv *env, jobject thiz)
998 {
999     LOGD("OcRepresentation_create");
1000     OCRepresentation *rep = new OCRepresentation();
1001     SetHandle<OCRepresentation>(env, thiz, rep);
1002     if (env->ExceptionCheck())
1003     {
1004         LOGE("Failed to set native handle for OcRepresentation");
1005         delete rep;
1006     }
1007 }
1008
1009 /*
1010 * Class:     org_iotivity_base_OcRepresentation
1011 * Method:    dispose
1012 * Signature: ()V
1013 */
1014 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_dispose
1015 (JNIEnv *env, jobject thiz, jboolean jNeedsDelete)
1016 {
1017     LOGD("OcRepresentation_dispose");
1018     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1019
1020     if (jNeedsDelete)
1021     {
1022         delete rep;
1023     }
1024 }