2 * //******************************************************************
4 * // Copyright 2015 Intel Corporation.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "JniOcRepresentation.h"
27 OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobject thiz)
29 OCRepresentation *rep = GetHandle<OCRepresentation>(env, thiz);
30 if (env->ExceptionCheck())
32 LOGE("Failed to get native handle from OcRepresentation");
36 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
42 * Class: org_iotivity_base_OcRepresentation
44 * Signature: (Ljava/lang/String;)Ljava/lang/Object;
46 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN
47 (JNIEnv *env, jobject thiz, jstring jKey)
49 LOGD("OcRepresentation_getValue");
52 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
55 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
56 if (!rep) return nullptr;
58 std::string key = env->GetStringUTFChars(jKey, nullptr);
60 AttributeValue attrValue;
61 if (!rep->getAttributeValue(key.c_str(), attrValue))
63 ThrowOcException(JNI_NO_SUCH_KEY, " attribute key does not exist");
66 return boost::apply_visitor(JObjectConverter(env), attrValue);
70 * Class: org_iotivity_base_OcRepresentation
71 * Method: setValueInteger
72 * Signature: (Ljava/lang/String;I)V
74 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
75 (JNIEnv *env, jobject thiz, jstring jKey, jint jValue)
77 LOGD("OcRepresentation_setValueInteger");
80 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
83 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
86 std::string str = env->GetStringUTFChars(jKey, nullptr);
87 rep->setValue(str, static_cast<int>(jValue));
91 * Class: org_iotivity_base_OcRepresentation
92 * Method: setValueDouble
93 * Signature: (Ljava/lang/String;D)V
95 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble
96 (JNIEnv *env, jobject thiz, jstring jKey, jdouble jValue)
98 LOGD("OcRepresentation_setValueDouble");
101 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
104 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
107 std::string str = env->GetStringUTFChars(jKey, nullptr);
108 rep->setValue(str, static_cast<double>(jValue));
112 * Class: org_iotivity_base_OcRepresentation
113 * Method: setValueBoolean
114 * Signature: (Ljava/lang/String;Z)V
116 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean
117 (JNIEnv *env, jobject thiz, jstring jKey, jboolean jValue)
119 LOGD("OcRepresentation_setValueBoolean");
122 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
125 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
128 std::string str = env->GetStringUTFChars(jKey, nullptr);
129 rep->setValue(str, static_cast<bool>(jValue));
133 * Class: org_iotivity_base_OcRepresentation
134 * Method: setValueStringN
135 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
137 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringN
138 (JNIEnv *env, jobject thiz, jstring jKey, jstring jValue)
140 LOGD("OcRepresentation_setValueString");
143 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
146 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
149 std::string key = env->GetStringUTFChars(jKey, nullptr);
150 std::string value = env->GetStringUTFChars(jValue, nullptr);
152 rep->setValue(key, value);
156 * Class: org_iotivity_base_OcRepresentation
157 * Method: setValueRepresentation
158 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;)V
160 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation
161 (JNIEnv *env, jobject thiz, jstring jKey, jobject jValue)
163 LOGD("OcRepresentation_setValueRepresentation");
166 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
169 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
172 std::string key = env->GetStringUTFChars(jKey, nullptr);
176 OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
178 rep->setValue(key, *value);
187 * Class: org_iotivity_base_OcRepresentation
188 * Method: setValueIntegerArray
189 * Signature: (Ljava/lang/String;[I)V
191 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerArray
192 (JNIEnv *env, jobject thiz, jstring jKey, jintArray jValue)
194 LOGD("OcRepresentation_setValueIntegerArray");
197 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
201 const jsize len = env->GetArrayLength(jValue);
202 jint* ints = env->GetIntArrayElements(jValue, nullptr);
204 std::vector<int> value;
205 for (jsize i = 0; i < len; ++i)
207 value.push_back(static_cast<int>(ints[i]));
209 env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT);
211 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
214 std::string key = env->GetStringUTFChars(jKey, nullptr);
215 rep->setValue(key, value);
219 * Class: org_iotivity_base_OcRepresentation
220 * Method: setValueInteger2DArray
221 * Signature: (Ljava/lang/String;[[I)V
223 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2DArray
224 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
226 LOGD("OcRepresentation__setValueInteger2DArray");
229 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
232 std::vector<std::vector<int>> value;
233 const jsize lenOuter = env->GetArrayLength(jValue);
234 for (jsize j = 0; j < lenOuter; ++j)
236 jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jValue, j));
237 jint* ints = env->GetIntArrayElements(jInnerArray, nullptr);
238 std::vector<int> innerVector;
239 const jsize lenInner = env->GetArrayLength(jInnerArray);
240 for (jsize i = 0; i < lenInner; ++i)
242 innerVector.push_back(static_cast<int>(ints[i]));
244 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
245 env->DeleteLocalRef(jInnerArray);
246 value.push_back(innerVector);
249 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
252 std::string key = env->GetStringUTFChars(jKey, nullptr);
253 rep->setValue(key, value);
257 * Class: org_iotivity_base_OcRepresentation
258 * Method: setValueInteger3DArray
259 * Signature: (Ljava/lang/String;[[[I)V
261 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3DArray
262 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
264 LOGD("OcRepresentation_setValueInteger3DArray");
267 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
270 std::vector<std::vector<std::vector<int>>> value;
271 const jsize lenOuter = env->GetArrayLength(jValue);
272 for (jsize k = 0; k < lenOuter; ++k)
274 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
275 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
276 std::vector<std::vector<int>> middleArray;
277 for (jsize j = 0; j < lenMiddle; ++j)
279 jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jMiddleArray, j));
280 jint* ints = env->GetIntArrayElements(jInnerArray, nullptr);
281 std::vector<int> innerVector;
282 const jsize lenInner = env->GetArrayLength(jInnerArray);
283 for (jsize i = 0; i < lenInner; ++i)
285 innerVector.push_back(static_cast<int>(ints[i]));
287 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
288 env->DeleteLocalRef(jInnerArray);
289 middleArray.push_back(innerVector);
291 env->DeleteLocalRef(jMiddleArray);
292 value.push_back(middleArray);
295 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
298 std::string key = env->GetStringUTFChars(jKey, nullptr);
299 rep->setValue(key, value);
303 * Class: org_iotivity_base_OcRepresentation
304 * Method: setValueDoubleArray
305 * Signature: (Ljava/lang/String;[D)V
307 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArray
308 (JNIEnv *env, jobject thiz, jstring jKey, jdoubleArray jValue)
310 LOGD("OcRepresentation_setValueDoubleArray");
313 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
317 const jsize len = env->GetArrayLength(jValue);
318 jdouble* doubles = env->GetDoubleArrayElements(jValue, nullptr);
320 std::vector<double> value;
321 for (jsize i = 0; i < len; ++i)
323 value.push_back(static_cast<double>(doubles[i]));
325 env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT);
327 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
330 std::string key = env->GetStringUTFChars(jKey, nullptr);
331 rep->setValue(key, value);
335 * Class: org_iotivity_base_OcRepresentation
336 * Method: setValueDouble2DArray
337 * Signature: (Ljava/lang/String;[[D)V
339 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DArray
340 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
342 LOGD("OcRepresentation_setValueDouble2DArray");
345 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
348 std::vector<std::vector<double>> value;
349 const jsize lenOuter = env->GetArrayLength(jValue);
350 for (jsize j = 0; j < lenOuter; ++j)
352 jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jValue, j));
353 jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, nullptr);
354 std::vector<double> innerVector;
355 const jsize lenInner = env->GetArrayLength(jInnerArray);
356 for (jsize i = 0; i < lenInner; ++i)
358 innerVector.push_back(static_cast<double>(doubles[i]));
360 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
361 env->DeleteLocalRef(jInnerArray);
362 value.push_back(innerVector);
365 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
368 std::string key = env->GetStringUTFChars(jKey, nullptr);
369 rep->setValue(key, value);
373 * Class: org_iotivity_base_OcRepresentation
374 * Method: setValueDouble3DArray
375 * Signature: (Ljava/lang/String;[[[D)V
377 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DArray
378 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
380 LOGD("OcRepresentation_setValueDouble3DArray");
383 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
386 std::vector<std::vector<std::vector<double>>> value;
387 const jsize lenOuter = env->GetArrayLength(jValue);
388 for (jsize k = 0; k < lenOuter; ++k)
390 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
391 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
392 std::vector<std::vector<double>> middleArray;
393 for (jsize j = 0; j < lenMiddle; ++j)
395 jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jMiddleArray, j));
396 jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, nullptr);
397 std::vector<double> innerVector;
398 const jsize lenInner = env->GetArrayLength(jInnerArray);
399 for (jsize i = 0; i < lenInner; ++i)
401 innerVector.push_back(static_cast<double>(doubles[i]));
403 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
404 env->DeleteLocalRef(jInnerArray);
405 middleArray.push_back(innerVector);
407 env->DeleteLocalRef(jMiddleArray);
408 value.push_back(middleArray);
411 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
414 std::string key = env->GetStringUTFChars(jKey, nullptr);
415 rep->setValue(key, value);
419 * Class: org_iotivity_base_OcRepresentation
420 * Method: setValueBooleanArray
421 * Signature: (Ljava/lang/String;[Z)V
423 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanArray
424 (JNIEnv *env, jobject thiz, jstring jKey, jbooleanArray jValue)
426 LOGD("OcRepresentation_setValueBooleanArray");
429 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
433 const jsize len = env->GetArrayLength(jValue);
434 jboolean* booleans = env->GetBooleanArrayElements(jValue, nullptr);
436 std::vector<bool> value;
437 for (jsize i = 0; i < len; ++i)
439 value.push_back(static_cast<bool>(booleans[i]));
441 env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT);
443 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
446 std::string key = env->GetStringUTFChars(jKey, nullptr);
447 rep->setValue(key, value);
451 * Class: org_iotivity_base_OcRepresentation
452 * Method: setValueBoolean2DArray
453 * Signature: (Ljava/lang/String;[[Z)V
455 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2DArray
456 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
458 LOGD("OcRepresentation_setValueBoolean2DArray");
461 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
464 std::vector<std::vector<bool>> value;
465 const jsize lenOuter = env->GetArrayLength(jValue);
466 for (jsize j = 0; j < lenOuter; ++j)
468 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jValue, j));
469 const jsize lenInner = env->GetArrayLength(jInnerArray);
470 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, nullptr);
472 std::vector<bool> innerVector;
473 for (jsize i = 0; i < lenInner; ++i)
475 innerVector.push_back(static_cast<bool>(booleans[i]));
477 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
478 env->DeleteLocalRef(jInnerArray);
479 value.push_back(innerVector);
482 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
485 std::string key = env->GetStringUTFChars(jKey, nullptr);
486 rep->setValue(key, value);
490 * Class: org_iotivity_base_OcRepresentation
491 * Method: setValueBoolean3DArray
492 * Signature: (Ljava/lang/String;[[[Z)V
494 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3DArray
495 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
497 LOGD("OcRepresentation_setValueBoolean3DArray");
500 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
503 std::vector<std::vector<std::vector<bool>>> value;
504 const jsize lenOuter = env->GetArrayLength(jValue);
505 for (jsize k = 0; k < lenOuter; ++k)
507 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
508 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
509 std::vector<std::vector<bool>> middleArray;
510 for (jsize j = 0; j < lenMiddle; ++j)
512 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jMiddleArray, j));
513 const jsize lenInner = env->GetArrayLength(jInnerArray);
514 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, nullptr);
516 std::vector<bool> innerVector;
517 for (jsize i = 0; i < lenInner; ++i)
519 innerVector.push_back(static_cast<bool>(booleans[i]));
521 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
522 env->DeleteLocalRef(jInnerArray);
523 middleArray.push_back(innerVector);
525 env->DeleteLocalRef(jMiddleArray);
526 value.push_back(middleArray);
529 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
532 std::string key = env->GetStringUTFChars(jKey, nullptr);
533 rep->setValue(key, value);
537 * Class: org_iotivity_base_OcRepresentation
538 * Method: setValueStringArray
539 * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
541 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArray
542 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
544 LOGD("OcRepresentation_setValueStringArray");
547 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
551 std::vector<std::string> value;
552 JniUtils::convertJavaStrArrToStrVector(env, jValue, value);
554 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
557 std::string key = env->GetStringUTFChars(jKey, nullptr);
558 rep->setValue(key, value);
562 * Class: org_iotivity_base_OcRepresentation
563 * Method: setValueString2DArray
564 * Signature: (Ljava/lang/String;[[Ljava/lang/String;)V
566 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DArray
567 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
569 LOGD("OcRepresentation_setValueString2DArray");
572 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
575 std::vector<std::vector<std::string>> value;
576 const jsize lenOuter = env->GetArrayLength(jValue);
577 for (jsize j = 0; j < lenOuter; ++j)
579 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
580 std::vector<std::string> innerVector;
581 JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
582 env->DeleteLocalRef(jInnerArray);
583 value.push_back(innerVector);
586 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
589 std::string key = env->GetStringUTFChars(jKey, nullptr);
590 rep->setValue(key, value);
594 * Class: org_iotivity_base_OcRepresentation
595 * Method: setValueString3DArray
596 * Signature: (Ljava/lang/String;[[[Ljava/lang/String;)V
598 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DArray
599 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
601 LOGD("OcRepresentation_setValueString3DArray");
604 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
607 std::vector<std::vector<std::vector<std::string>>> value;
608 const jsize lenOuter = env->GetArrayLength(jValue);
609 for (jsize k = 0; k < lenOuter; ++k)
611 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
612 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
613 std::vector<std::vector<std::string>> middleArray;
614 for (jsize j = 0; j < lenMiddle; ++j)
616 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
617 std::vector<std::string> innerVector;
618 JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
619 env->DeleteLocalRef(jInnerArray);
620 middleArray.push_back(innerVector);
622 env->DeleteLocalRef(jMiddleArray);
623 value.push_back(middleArray);
626 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
629 std::string key = env->GetStringUTFChars(jKey, nullptr);
630 rep->setValue(key, value);
634 * Class: org_iotivity_base_OcRepresentation
635 * Method: setValueRepresentationArray
636 * Signature: (Ljava/lang/String;[Lorg/iotivity/base/OcRepresentation;)V
638 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentationArray
639 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
641 LOGD("OcRepresentation_setValueRepresentationArray");
644 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
648 std::vector<OCRepresentation> value;
649 JniUtils::convertJavaRepresentationArrToVector(env, jValue, value);
651 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
654 std::string key = env->GetStringUTFChars(jKey, nullptr);
655 rep->setValue(key, value);
659 * Class: org_iotivity_base_OcRepresentation
660 * Method: setValueRepresentation2DArray
661 * Signature: (Ljava/lang/String;[[Lorg/iotivity/base/OcRepresentation;)V
663 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation2DArray
664 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
666 LOGD("OcRepresentation_setValueRepresentation2DArray");
669 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
672 std::vector<std::vector<OCRepresentation>> value;
673 const jsize lenOuter = env->GetArrayLength(jValue);
674 for (jsize j = 0; j < lenOuter; ++j)
676 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
677 std::vector<OCRepresentation> innerVector;
678 JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
679 env->DeleteLocalRef(jInnerArray);
680 value.push_back(innerVector);
683 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
686 std::string key = env->GetStringUTFChars(jKey, nullptr);
687 rep->setValue(key, value);
691 * Class: org_iotivity_base_OcRepresentation
692 * Method: setValueRepresentation3DArray
693 * Signature: (Ljava/lang/String;[[[Lorg/iotivity/base/OcRepresentation;)V
695 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation3DArray
696 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
698 LOGD("OcRepresentation_setValueRepresentation3DArray");
701 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
704 std::vector<std::vector<std::vector<OCRepresentation>>> value;
705 const jsize lenOuter = env->GetArrayLength(jValue);
706 for (jsize k = 0; k < lenOuter; ++k)
708 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
709 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
710 std::vector<std::vector<OCRepresentation>> middleArray;
711 for (jsize j = 0; j < lenMiddle; ++j)
713 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
714 std::vector<OCRepresentation> innerVector;
715 JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
716 env->DeleteLocalRef(jInnerArray);
717 middleArray.push_back(innerVector);
719 env->DeleteLocalRef(jMiddleArray);
720 value.push_back(middleArray);
723 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
726 std::string key = env->GetStringUTFChars(jKey, nullptr);
727 rep->setValue(key, value);
731 * Class: org_iotivity_base_OcRepresentation
733 * Signature: (Lorg/iotivity/base/OcRepresentation;)V
735 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
736 (JNIEnv *env, jobject thiz, jobject jOcRepresentation)
738 LOGD("OcRepresentation_addChild");
739 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
742 OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
745 rep->addChild(*child);
749 * Class: org_iotivity_base_OcRepresentation
750 * Method: clearChildren
753 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren
754 (JNIEnv *env, jobject thiz)
756 LOGD("OcRepresentation_clearChildren");
757 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
760 rep->clearChildren();
764 * Class: org_iotivity_base_OcRepresentation
765 * Method: getChildrenArray
766 * Signature: ()[Lorg/iotivity/base/OcRepresentation;
768 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
769 (JNIEnv *env, jobject thiz)
771 LOGD("OcRepresentation_getChildrenArray");
772 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
773 if (!rep) return nullptr;
775 return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
779 * Class: org_iotivity_base_OcRepresentation
781 * Signature: ()Ljava/lang/String;
783 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri
784 (JNIEnv *env, jobject thiz)
786 LOGD("OcRepresentation_getUri");
787 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
788 if (!rep) return nullptr;
790 std::string uri(rep->getUri());
791 return env->NewStringUTF(uri.c_str());
795 * Class: org_iotivity_base_OcRepresentation
797 * Signature: ()Ljava/lang/String;
799 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getHost
800 (JNIEnv *env, jobject thiz)
802 LOGD("OcRepresentation_getHost");
803 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
804 if (!rep) return nullptr;
806 std::string uri(rep->getHost());
807 return env->NewStringUTF(uri.c_str());
811 * Class: org_iotivity_base_OcRepresentation
813 * Signature: (Ljava/lang/String;)V
815 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri
816 (JNIEnv *env, jobject thiz, jstring jUri)
818 LOGD("OcRepresentation_setUri");
821 ThrowOcException(OC_STACK_INVALID_PARAM, "uri cannot be null");
824 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
827 rep->setUri(env->GetStringUTFChars(jUri, nullptr));
830 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute
831 (JNIEnv *env, jobject thiz, jstring jstr)
833 LOGD("OcRepresentation_hasAttribute");
836 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
839 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
840 if (!rep) return false;
842 std::string str = env->GetStringUTFChars(jstr, nullptr);
843 return rep->hasAttribute(str);
847 * Class: org_iotivity_base_OcRepresentation
848 * Method: getResourceTypes
849 * Signature: ()Ljava/util/List;
851 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTypes
852 (JNIEnv *env, jobject thiz)
854 LOGD("OcRepresentation_getResourceTypes");
855 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
856 if (!rep) return nullptr;
858 std::vector<std::string> resourceTypes = rep->getResourceTypes();
859 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
863 * Class: org_iotivity_base_OcRepresentation
864 * Method: setResourceTypeArray
865 * Signature: ([Ljava/lang/String;)V
867 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeArray
868 (JNIEnv *env, jobject thiz, jobjectArray jResourceTypeArray)
870 LOGD("OcRepresentation_setResourceTypeArray");
871 if (!jResourceTypeArray)
873 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");
876 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
879 std::vector<std::string> resourceTypes;
880 JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
881 rep->setResourceTypes(resourceTypes);
884 * Class: org_iotivity_base_OcRepresentation
885 * Method: getResourceInterfaces
886 * Signature: ()Ljava/util/List;
888 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInterfaces
889 (JNIEnv *env, jobject thiz)
891 LOGD("OcRepresentation_getResourceInterfaces");
892 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
893 if (!rep) return nullptr;
895 std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
896 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
900 * Class: org_iotivity_base_OcRepresentation
901 * Method: setResourceInterfaceArray
902 * Signature: ([Ljava/lang/String;)V
904 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterfaceArray
905 (JNIEnv *env, jobject thiz, jobjectArray jResourceInterfaceArray)
907 LOGD("OcRepresentation_setResourceInterfaceArray");
908 if (!jResourceInterfaceArray)
910 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceInterfaceList cannot be null");
913 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
916 std::vector<std::string> resourceInterfaces;
917 JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
918 rep->setResourceInterfaces(resourceInterfaces);
922 * Class: org_iotivity_base_OcRepresentation
926 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty
927 (JNIEnv *env, jobject thiz)
929 LOGD("OcRepresentation_isEmpty");
930 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
931 if (!rep) return false;
933 return static_cast<jboolean>(rep->empty());
937 * Class: org_iotivity_base_OcRepresentation
941 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size
942 (JNIEnv *env, jobject thiz)
944 LOGD("OcRepresentation_size");
945 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
948 return static_cast<jint>(rep->numberOfAttributes());
952 * Class: org_iotivity_base_OcRepresentation
954 * Signature: (Ljava/lang/String;)Z
956 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove
957 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
959 LOGD("OcRepresentation_remove");
962 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
965 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
966 if (!rep) return false;
968 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
969 return static_cast<jboolean>(rep->erase(attributeKey));
973 * Class: org_iotivity_base_OcRepresentation
975 * Signature: (Ljava/lang/String;)V
977 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull
978 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
980 LOGD("OcRepresentation_setNull");
983 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
986 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
989 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
990 rep->setNULL(attributeKey);
994 * Class: org_iotivity_base_OcRepresentation
996 * Signature: (Ljava/lang/String;)Z
998 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull
999 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
1001 LOGD("OcRepresentation_isNull");
1004 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
1007 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1008 if (!rep) return false;
1010 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
1011 return static_cast<jboolean>(rep->isNULL(attributeKey));
1015 * Class: org_iotivity_base_OcRepresentation
1019 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_create
1020 (JNIEnv *env, jobject thiz)
1022 LOGD("OcRepresentation_create");
1023 OCRepresentation *rep = new OCRepresentation();
1024 SetHandle<OCRepresentation>(env, thiz, rep);
1025 if (env->ExceptionCheck())
1027 LOGE("Failed to set native handle for OcRepresentation");
1033 * Class: org_iotivity_base_OcRepresentation
1037 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_dispose
1038 (JNIEnv *env, jobject thiz, jboolean jNeedsDelete)
1040 LOGD("OcRepresentation_dispose");
1041 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);