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 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 #include "JniOcRepresentation.h"
30 OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobject thiz)
32 OCRepresentation *rep = GetHandle<OCRepresentation>(env, thiz);
33 if (env->ExceptionCheck())
35 LOGE("Failed to get native handle from OcRepresentation");
39 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
45 * Class: org_iotivity_base_OcRepresentation
47 * Signature: ()Ljava/util/Map;
49 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
50 (JNIEnv *env, jobject thiz)
52 LOGD("OcRepresentation_getValues");
53 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
59 std::map<std::string, AttributeValue> values = rep->getValues();
60 jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor);
66 for (std::map<std::string, AttributeValue>::const_iterator it = values.begin(); it != values.end(); it++)
68 jobject key = static_cast<jobject>(env->NewStringUTF(it->first.c_str()));
69 jobject val = boost::apply_visitor(JObjectConverter(env), it->second);
70 env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val);
76 * Class: org_iotivity_base_OcRepresentation
78 * Signature: (Ljava/lang/String;)Ljava/lang/Object;
80 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN
81 (JNIEnv *env, jobject thiz, jstring jKey)
83 LOGD("OcRepresentation_getValue");
86 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
89 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
95 std::string key = env->GetStringUTFChars(jKey, nullptr);
97 AttributeValue attrValue;
98 if (!rep->getAttributeValue(key.c_str(), attrValue))
100 ThrowOcException(JNI_NO_SUCH_KEY, " attribute key does not exist");
103 return boost::apply_visitor(JObjectConverter(env), attrValue);
107 * Class: org_iotivity_base_OcRepresentation
108 * Method: setValueInteger
109 * Signature: (Ljava/lang/String;I)V
111 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
112 (JNIEnv *env, jobject thiz, jstring jKey, jint jValue)
114 LOGD("OcRepresentation_setValueInteger");
117 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
120 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
126 std::string str = env->GetStringUTFChars(jKey, nullptr);
127 rep->setValue(str, static_cast<int>(jValue));
131 * Class: org_iotivity_base_OcRepresentation
132 * Method: setValueDouble
133 * Signature: (Ljava/lang/String;D)V
135 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble
136 (JNIEnv *env, jobject thiz, jstring jKey, jdouble jValue)
138 LOGD("OcRepresentation_setValueDouble");
141 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
144 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
150 std::string str = env->GetStringUTFChars(jKey, nullptr);
151 rep->setValue(str, static_cast<double>(jValue));
155 * Class: org_iotivity_base_OcRepresentation
156 * Method: setValueBoolean
157 * Signature: (Ljava/lang/String;Z)V
159 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean
160 (JNIEnv *env, jobject thiz, jstring jKey, jboolean jValue)
162 LOGD("OcRepresentation_setValueBoolean");
165 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
168 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
174 std::string str = env->GetStringUTFChars(jKey, nullptr);
175 rep->setValue(str, static_cast<bool>(jValue));
179 * Class: org_iotivity_base_OcRepresentation
180 * Method: setValueStringN
181 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
183 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringN
184 (JNIEnv *env, jobject thiz, jstring jKey, jstring jValue)
186 LOGD("OcRepresentation_setValueString");
189 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
192 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
198 std::string key = env->GetStringUTFChars(jKey, nullptr);
199 std::string value = env->GetStringUTFChars(jValue, nullptr);
201 rep->setValue(key, value);
205 * Class: org_iotivity_base_OcRepresentation
206 * Method: setValueRepresentation
207 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;)V
209 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation
210 (JNIEnv *env, jobject thiz, jstring jKey, jobject jValue)
212 LOGD("OcRepresentation_setValueRepresentation");
215 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
218 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
224 std::string key = env->GetStringUTFChars(jKey, nullptr);
228 OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
233 rep->setValue(key, *value);
242 * Class: org_iotivity_base_OcRepresentation
243 * Method: setValueIntegerArray
244 * Signature: (Ljava/lang/String;[I)V
246 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerArray
247 (JNIEnv *env, jobject thiz, jstring jKey, jintArray jValue)
249 LOGD("OcRepresentation_setValueIntegerArray");
252 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
256 const jsize len = env->GetArrayLength(jValue);
257 jint* ints = env->GetIntArrayElements(jValue, nullptr);
259 std::vector<int> value;
260 for (jsize i = 0; i < len; ++i)
262 value.push_back(static_cast<int>(ints[i]));
264 env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT);
266 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
272 std::string key = env->GetStringUTFChars(jKey, nullptr);
273 rep->setValue(key, value);
277 * Class: org_iotivity_base_OcRepresentation
278 * Method: setValueInteger2DArray
279 * Signature: (Ljava/lang/String;[[I)V
281 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2DArray
282 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
284 LOGD("OcRepresentation__setValueInteger2DArray");
287 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
290 std::vector<std::vector<int>> value;
291 const jsize lenOuter = env->GetArrayLength(jValue);
292 for (jsize j = 0; j < lenOuter; ++j)
294 jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jValue, j));
295 jint* ints = env->GetIntArrayElements(jInnerArray, nullptr);
296 std::vector<int> innerVector;
297 const jsize lenInner = env->GetArrayLength(jInnerArray);
298 for (jsize i = 0; i < lenInner; ++i)
300 innerVector.push_back(static_cast<int>(ints[i]));
302 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
303 env->DeleteLocalRef(jInnerArray);
304 value.push_back(innerVector);
307 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
313 std::string key = env->GetStringUTFChars(jKey, nullptr);
314 rep->setValue(key, value);
318 * Class: org_iotivity_base_OcRepresentation
319 * Method: setValueInteger3DArray
320 * Signature: (Ljava/lang/String;[[[I)V
322 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3DArray
323 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
325 LOGD("OcRepresentation_setValueInteger3DArray");
328 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
331 std::vector<std::vector<std::vector<int>>> value;
332 const jsize lenOuter = env->GetArrayLength(jValue);
333 for (jsize k = 0; k < lenOuter; ++k)
335 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
336 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
337 std::vector<std::vector<int>> middleArray;
338 for (jsize j = 0; j < lenMiddle; ++j)
340 jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jMiddleArray, j));
341 jint* ints = env->GetIntArrayElements(jInnerArray, nullptr);
342 std::vector<int> innerVector;
343 const jsize lenInner = env->GetArrayLength(jInnerArray);
344 for (jsize i = 0; i < lenInner; ++i)
346 innerVector.push_back(static_cast<int>(ints[i]));
348 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
349 env->DeleteLocalRef(jInnerArray);
350 middleArray.push_back(innerVector);
352 env->DeleteLocalRef(jMiddleArray);
353 value.push_back(middleArray);
356 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
362 std::string key = env->GetStringUTFChars(jKey, nullptr);
363 rep->setValue(key, value);
367 * Class: org_iotivity_base_OcRepresentation
368 * Method: setValueDoubleArray
369 * Signature: (Ljava/lang/String;[D)V
371 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArray
372 (JNIEnv *env, jobject thiz, jstring jKey, jdoubleArray jValue)
374 LOGD("OcRepresentation_setValueDoubleArray");
377 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
381 const jsize len = env->GetArrayLength(jValue);
382 jdouble* doubles = env->GetDoubleArrayElements(jValue, nullptr);
384 std::vector<double> value;
385 for (jsize i = 0; i < len; ++i)
387 value.push_back(static_cast<double>(doubles[i]));
389 env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT);
391 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
397 std::string key = env->GetStringUTFChars(jKey, nullptr);
398 rep->setValue(key, value);
402 * Class: org_iotivity_base_OcRepresentation
403 * Method: setValueDouble2DArray
404 * Signature: (Ljava/lang/String;[[D)V
406 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DArray
407 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
409 LOGD("OcRepresentation_setValueDouble2DArray");
412 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
415 std::vector<std::vector<double>> value;
416 const jsize lenOuter = env->GetArrayLength(jValue);
417 for (jsize j = 0; j < lenOuter; ++j)
419 jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jValue, j));
420 jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, nullptr);
421 std::vector<double> innerVector;
422 const jsize lenInner = env->GetArrayLength(jInnerArray);
423 for (jsize i = 0; i < lenInner; ++i)
425 innerVector.push_back(static_cast<double>(doubles[i]));
427 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
428 env->DeleteLocalRef(jInnerArray);
429 value.push_back(innerVector);
432 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
438 std::string key = env->GetStringUTFChars(jKey, nullptr);
439 rep->setValue(key, value);
443 * Class: org_iotivity_base_OcRepresentation
444 * Method: setValueDouble3DArray
445 * Signature: (Ljava/lang/String;[[[D)V
447 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DArray
448 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
450 LOGD("OcRepresentation_setValueDouble3DArray");
453 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
456 std::vector<std::vector<std::vector<double>>> value;
457 const jsize lenOuter = env->GetArrayLength(jValue);
458 for (jsize k = 0; k < lenOuter; ++k)
460 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
461 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
462 std::vector<std::vector<double>> middleArray;
463 for (jsize j = 0; j < lenMiddle; ++j)
465 jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jMiddleArray, j));
466 jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, nullptr);
467 std::vector<double> innerVector;
468 const jsize lenInner = env->GetArrayLength(jInnerArray);
469 for (jsize i = 0; i < lenInner; ++i)
471 innerVector.push_back(static_cast<double>(doubles[i]));
473 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
474 env->DeleteLocalRef(jInnerArray);
475 middleArray.push_back(innerVector);
477 env->DeleteLocalRef(jMiddleArray);
478 value.push_back(middleArray);
481 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
487 std::string key = env->GetStringUTFChars(jKey, nullptr);
488 rep->setValue(key, value);
492 * Class: org_iotivity_base_OcRepresentation
493 * Method: setValueBooleanArray
494 * Signature: (Ljava/lang/String;[Z)V
496 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanArray
497 (JNIEnv *env, jobject thiz, jstring jKey, jbooleanArray jValue)
499 LOGD("OcRepresentation_setValueBooleanArray");
502 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
506 const jsize len = env->GetArrayLength(jValue);
507 jboolean* booleans = env->GetBooleanArrayElements(jValue, nullptr);
509 std::vector<bool> value;
510 for (jsize i = 0; i < len; ++i)
512 value.push_back(static_cast<bool>(booleans[i]));
514 env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT);
516 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
522 std::string key = env->GetStringUTFChars(jKey, nullptr);
523 rep->setValue(key, value);
527 * Class: org_iotivity_base_OcRepresentation
528 * Method: setValueBoolean2DArray
529 * Signature: (Ljava/lang/String;[[Z)V
531 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2DArray
532 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
534 LOGD("OcRepresentation_setValueBoolean2DArray");
537 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
540 std::vector<std::vector<bool>> value;
541 const jsize lenOuter = env->GetArrayLength(jValue);
542 for (jsize j = 0; j < lenOuter; ++j)
544 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jValue, j));
545 const jsize lenInner = env->GetArrayLength(jInnerArray);
546 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, nullptr);
548 std::vector<bool> innerVector;
549 for (jsize i = 0; i < lenInner; ++i)
551 innerVector.push_back(static_cast<bool>(booleans[i]));
553 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
554 env->DeleteLocalRef(jInnerArray);
555 value.push_back(innerVector);
558 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
564 std::string key = env->GetStringUTFChars(jKey, nullptr);
565 rep->setValue(key, value);
569 * Class: org_iotivity_base_OcRepresentation
570 * Method: setValueBoolean3DArray
571 * Signature: (Ljava/lang/String;[[[Z)V
573 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3DArray
574 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
576 LOGD("OcRepresentation_setValueBoolean3DArray");
579 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
582 std::vector<std::vector<std::vector<bool>>> value;
583 const jsize lenOuter = env->GetArrayLength(jValue);
584 for (jsize k = 0; k < lenOuter; ++k)
586 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
587 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
588 std::vector<std::vector<bool>> middleArray;
589 for (jsize j = 0; j < lenMiddle; ++j)
591 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jMiddleArray, j));
592 const jsize lenInner = env->GetArrayLength(jInnerArray);
593 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, nullptr);
595 std::vector<bool> innerVector;
596 for (jsize i = 0; i < lenInner; ++i)
598 innerVector.push_back(static_cast<bool>(booleans[i]));
600 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
601 env->DeleteLocalRef(jInnerArray);
602 middleArray.push_back(innerVector);
604 env->DeleteLocalRef(jMiddleArray);
605 value.push_back(middleArray);
608 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
614 std::string key = env->GetStringUTFChars(jKey, nullptr);
615 rep->setValue(key, value);
619 * Class: org_iotivity_base_OcRepresentation
620 * Method: setValueStringArray
621 * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
623 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArray
624 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
626 LOGD("OcRepresentation_setValueStringArray");
629 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
633 std::vector<std::string> value;
634 JniUtils::convertJavaStrArrToStrVector(env, jValue, value);
636 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
642 std::string key = env->GetStringUTFChars(jKey, nullptr);
643 rep->setValue(key, value);
647 * Class: org_iotivity_base_OcRepresentation
648 * Method: setValueString2DArray
649 * Signature: (Ljava/lang/String;[[Ljava/lang/String;)V
651 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DArray
652 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
654 LOGD("OcRepresentation_setValueString2DArray");
657 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
660 std::vector<std::vector<std::string>> value;
661 const jsize lenOuter = env->GetArrayLength(jValue);
662 for (jsize j = 0; j < lenOuter; ++j)
664 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
665 std::vector<std::string> innerVector;
666 JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
667 env->DeleteLocalRef(jInnerArray);
668 value.push_back(innerVector);
671 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
677 std::string key = env->GetStringUTFChars(jKey, nullptr);
678 rep->setValue(key, value);
682 * Class: org_iotivity_base_OcRepresentation
683 * Method: setValueString3DArray
684 * Signature: (Ljava/lang/String;[[[Ljava/lang/String;)V
686 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DArray
687 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
689 LOGD("OcRepresentation_setValueString3DArray");
692 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
695 std::vector<std::vector<std::vector<std::string>>> value;
696 const jsize lenOuter = env->GetArrayLength(jValue);
697 for (jsize k = 0; k < lenOuter; ++k)
699 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
700 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
701 std::vector<std::vector<std::string>> middleArray;
702 for (jsize j = 0; j < lenMiddle; ++j)
704 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
705 std::vector<std::string> innerVector;
706 JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
707 env->DeleteLocalRef(jInnerArray);
708 middleArray.push_back(innerVector);
710 env->DeleteLocalRef(jMiddleArray);
711 value.push_back(middleArray);
714 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
719 std::string key = env->GetStringUTFChars(jKey, nullptr);
720 rep->setValue(key, value);
724 * Class: org_iotivity_base_OcRepresentation
725 * Method: setValueRepresentationArray
726 * Signature: (Ljava/lang/String;[Lorg/iotivity/base/OcRepresentation;)V
728 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentationArray
729 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
731 LOGD("OcRepresentation_setValueRepresentationArray");
734 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
738 std::vector<OCRepresentation> value;
739 JniUtils::convertJavaRepresentationArrToVector(env, jValue, value);
741 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
747 std::string key = env->GetStringUTFChars(jKey, nullptr);
748 rep->setValue(key, value);
752 * Class: org_iotivity_base_OcRepresentation
753 * Method: setValueRepresentation2DArray
754 * Signature: (Ljava/lang/String;[[Lorg/iotivity/base/OcRepresentation;)V
756 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation2DArray
757 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
759 LOGD("OcRepresentation_setValueRepresentation2DArray");
762 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
765 std::vector<std::vector<OCRepresentation>> value;
766 const jsize lenOuter = env->GetArrayLength(jValue);
767 for (jsize j = 0; j < lenOuter; ++j)
769 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
770 std::vector<OCRepresentation> innerVector;
771 JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
772 env->DeleteLocalRef(jInnerArray);
773 value.push_back(innerVector);
776 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
782 std::string key = env->GetStringUTFChars(jKey, nullptr);
783 rep->setValue(key, value);
787 * Class: org_iotivity_base_OcRepresentation
788 * Method: setValueRepresentation3DArray
789 * Signature: (Ljava/lang/String;[[[Lorg/iotivity/base/OcRepresentation;)V
791 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation3DArray
792 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
794 LOGD("OcRepresentation_setValueRepresentation3DArray");
797 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
800 std::vector<std::vector<std::vector<OCRepresentation>>> value;
801 const jsize lenOuter = env->GetArrayLength(jValue);
802 for (jsize k = 0; k < lenOuter; ++k)
804 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
805 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
806 std::vector<std::vector<OCRepresentation>> middleArray;
807 for (jsize j = 0; j < lenMiddle; ++j)
809 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
810 std::vector<OCRepresentation> innerVector;
811 JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
812 env->DeleteLocalRef(jInnerArray);
813 middleArray.push_back(innerVector);
815 env->DeleteLocalRef(jMiddleArray);
816 value.push_back(middleArray);
819 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
825 std::string key = env->GetStringUTFChars(jKey, nullptr);
826 rep->setValue(key, value);
830 * Class: org_iotivity_base_OcRepresentation
831 * Method: setValueByteArray
832 * Signature: (Ljava/lang/String;[B)V
834 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray
835 (JNIEnv *env, jobject thiz, jstring jKey, jbyteArray jValue)
837 LOGD("OcRepresentation_setValueByteArray");
840 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
844 const jsize len = env->GetArrayLength(jValue);
845 jbyte* bytes = env->GetByteArrayElements(jValue, nullptr);
847 std::vector<uint8_t> value;
848 for (jsize i = 0; i < len; ++i)
850 value.push_back(static_cast<uint8_t>(bytes[i]));
852 env->ReleaseByteArrayElements(jValue, bytes, JNI_ABORT);
854 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
860 std::string key = env->GetStringUTFChars(jKey, nullptr);
861 rep->setValue(key, value);
865 * Class: org_iotivity_base_OcRepresentation
867 * Signature: (Lorg/iotivity/base/OcRepresentation;)V
869 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
870 (JNIEnv *env, jobject thiz, jobject jOcRepresentation)
872 LOGD("OcRepresentation_addChild");
873 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
879 OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
885 rep->addChild(*child);
889 * Class: org_iotivity_base_OcRepresentation
890 * Method: clearChildren
893 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren
894 (JNIEnv *env, jobject thiz)
896 LOGD("OcRepresentation_clearChildren");
897 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
903 rep->clearChildren();
907 * Class: org_iotivity_base_OcRepresentation
908 * Method: getChildrenArray
909 * Signature: ()[Lorg/iotivity/base/OcRepresentation;
911 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
912 (JNIEnv *env, jobject thiz)
914 LOGD("OcRepresentation_getChildrenArray");
915 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
921 return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
925 * Class: org_iotivity_base_OcRepresentation
927 * Signature: ()Ljava/lang/String;
929 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri
930 (JNIEnv *env, jobject thiz)
932 LOGD("OcRepresentation_getUri");
933 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
939 std::string uri(rep->getUri());
940 return env->NewStringUTF(uri.c_str());
944 * Class: org_iotivity_base_OcRepresentation
946 * Signature: ()Ljava/lang/String;
948 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getHost
949 (JNIEnv *env, jobject thiz)
951 LOGD("OcRepresentation_getHost");
952 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
958 std::string uri(rep->getHost());
959 return env->NewStringUTF(uri.c_str());
963 * Class: org_iotivity_base_OcRepresentation
965 * Signature: (Ljava/lang/String;)V
967 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri
968 (JNIEnv *env, jobject thiz, jstring jUri)
970 LOGD("OcRepresentation_setUri");
973 ThrowOcException(OC_STACK_INVALID_PARAM, "uri cannot be null");
976 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
982 rep->setUri(env->GetStringUTFChars(jUri, nullptr));
985 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute
986 (JNIEnv *env, jobject thiz, jstring jstr)
988 LOGD("OcRepresentation_hasAttribute");
991 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
994 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1000 std::string str = env->GetStringUTFChars(jstr, nullptr);
1001 return rep->hasAttribute(str);
1005 * Class: org_iotivity_base_OcRepresentation
1006 * Method: getResourceTypes
1007 * Signature: ()Ljava/util/List;
1009 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTypes
1010 (JNIEnv *env, jobject thiz)
1012 LOGD("OcRepresentation_getResourceTypes");
1013 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1019 std::vector<std::string> resourceTypes = rep->getResourceTypes();
1020 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
1024 * Class: org_iotivity_base_OcRepresentation
1025 * Method: setResourceTypeArray
1026 * Signature: ([Ljava/lang/String;)V
1028 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeArray
1029 (JNIEnv *env, jobject thiz, jobjectArray jResourceTypeArray)
1031 LOGD("OcRepresentation_setResourceTypeArray");
1032 if (!jResourceTypeArray)
1034 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");
1037 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1043 std::vector<std::string> resourceTypes;
1044 JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
1045 rep->setResourceTypes(resourceTypes);
1048 * Class: org_iotivity_base_OcRepresentation
1049 * Method: getResourceInterfaces
1050 * Signature: ()Ljava/util/List;
1052 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInterfaces
1053 (JNIEnv *env, jobject thiz)
1055 LOGD("OcRepresentation_getResourceInterfaces");
1056 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1062 std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
1063 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
1067 * Class: org_iotivity_base_OcRepresentation
1068 * Method: setResourceInterfaceArray
1069 * Signature: ([Ljava/lang/String;)V
1071 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterfaceArray
1072 (JNIEnv *env, jobject thiz, jobjectArray jResourceInterfaceArray)
1074 LOGD("OcRepresentation_setResourceInterfaceArray");
1075 if (!jResourceInterfaceArray)
1077 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceInterfaceList cannot be null");
1080 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1086 std::vector<std::string> resourceInterfaces;
1087 JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
1088 rep->setResourceInterfaces(resourceInterfaces);
1092 * Class: org_iotivity_base_OcRepresentation
1096 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty
1097 (JNIEnv *env, jobject thiz)
1099 LOGD("OcRepresentation_isEmpty");
1100 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1106 return static_cast<jboolean>(rep->empty());
1110 * Class: org_iotivity_base_OcRepresentation
1114 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size
1115 (JNIEnv *env, jobject thiz)
1117 LOGD("OcRepresentation_size");
1118 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1124 return static_cast<jint>(rep->numberOfAttributes());
1128 * Class: org_iotivity_base_OcRepresentation
1130 * Signature: (Ljava/lang/String;)Z
1132 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove
1133 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
1135 LOGD("OcRepresentation_remove");
1138 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
1141 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1147 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
1148 return static_cast<jboolean>(rep->erase(attributeKey));
1152 * Class: org_iotivity_base_OcRepresentation
1154 * Signature: (Ljava/lang/String;)V
1156 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull
1157 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
1159 LOGD("OcRepresentation_setNull");
1162 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
1165 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1171 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
1172 rep->setNULL(attributeKey);
1176 * Class: org_iotivity_base_OcRepresentation
1178 * Signature: (Ljava/lang/String;)Z
1180 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull
1181 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
1183 LOGD("OcRepresentation_isNull");
1186 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
1189 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
1195 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
1196 return static_cast<jboolean>(rep->isNULL(attributeKey));
1200 * Class: org_iotivity_base_OcRepresentation
1204 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_create
1205 (JNIEnv *env, jobject thiz)
1207 LOGD("OcRepresentation_create");
1208 OCRepresentation *rep = new OCRepresentation();
1209 SetHandle<OCRepresentation>(env, thiz, rep);
1210 if (env->ExceptionCheck())
1212 LOGE("Failed to set native handle for OcRepresentation");
1218 * Class: org_iotivity_base_OcRepresentation
1222 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_dispose
1223 (JNIEnv *env, jobject thiz, jboolean jNeedsDelete)
1225 LOGD("OcRepresentation_dispose");
1226 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);