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, NULL);
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, NULL);
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, NULL);
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, NULL);
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, NULL);
150 std::string value = env->GetStringUTFChars(jValue, NULL);
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, NULL);
173 OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
176 rep->setValue(key, *value);
180 * Class: org_iotivity_base_OcRepresentation
181 * Method: setValueIntegerArray
182 * Signature: (Ljava/lang/String;[I)V
184 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerArray
185 (JNIEnv *env, jobject thiz, jstring jKey, jintArray jValue)
187 LOGD("OcRepresentation_setValueIntegerArray");
190 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
194 const jsize len = env->GetArrayLength(jValue);
195 jint* ints = env->GetIntArrayElements(jValue, NULL);
197 std::vector<int> value;
198 for (jsize i = 0; i < len; ++i)
200 value.push_back(static_cast<int>(ints[i]));
202 env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT);
204 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
207 std::string key = env->GetStringUTFChars(jKey, NULL);
208 rep->setValue(key, value);
212 * Class: org_iotivity_base_OcRepresentation
213 * Method: setValueInteger2DArray
214 * Signature: (Ljava/lang/String;[[I)V
216 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2DArray
217 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
219 LOGD("OcRepresentation__setValueInteger2DArray");
222 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
225 std::vector<std::vector<int>> value;
226 const jsize lenOuter = env->GetArrayLength(jValue);
227 for (jsize j = 0; j < lenOuter; ++j)
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)
235 innerVector.push_back(static_cast<int>(ints[i]));
237 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
238 env->DeleteLocalRef(jInnerArray);
239 value.push_back(innerVector);
242 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
245 std::string key = env->GetStringUTFChars(jKey, NULL);
246 rep->setValue(key, value);
250 * Class: org_iotivity_base_OcRepresentation
251 * Method: setValueInteger3DArray
252 * Signature: (Ljava/lang/String;[[[I)V
254 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3DArray
255 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
257 LOGD("OcRepresentation_setValueInteger3DArray");
260 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
263 std::vector<std::vector<std::vector<int>>> value;
264 const jsize lenOuter = env->GetArrayLength(jValue);
265 for (jsize k = 0; k < lenOuter; ++k)
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)
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)
278 innerVector.push_back(static_cast<int>(ints[i]));
280 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
281 env->DeleteLocalRef(jInnerArray);
282 middleArray.push_back(innerVector);
284 env->DeleteLocalRef(jMiddleArray);
285 value.push_back(middleArray);
288 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
291 std::string key = env->GetStringUTFChars(jKey, NULL);
292 rep->setValue(key, value);
296 * Class: org_iotivity_base_OcRepresentation
297 * Method: setValueDoubleArray
298 * Signature: (Ljava/lang/String;[D)V
300 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArray
301 (JNIEnv *env, jobject thiz, jstring jKey, jdoubleArray jValue)
303 LOGD("OcRepresentation_setValueDoubleArray");
306 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
310 const jsize len = env->GetArrayLength(jValue);
311 jdouble* doubles = env->GetDoubleArrayElements(jValue, NULL);
313 std::vector<double> value;
314 for (jsize i = 0; i < len; ++i)
316 value.push_back(static_cast<double>(doubles[i]));
318 env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT);
320 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
323 std::string key = env->GetStringUTFChars(jKey, NULL);
324 rep->setValue(key, value);
328 * Class: org_iotivity_base_OcRepresentation
329 * Method: setValueDouble2DArray
330 * Signature: (Ljava/lang/String;[[D)V
332 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DArray
333 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
335 LOGD("OcRepresentation_setValueDouble2DArray");
338 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
341 std::vector<std::vector<double>> value;
342 const jsize lenOuter = env->GetArrayLength(jValue);
343 for (jsize j = 0; j < lenOuter; ++j)
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)
351 innerVector.push_back(static_cast<double>(doubles[i]));
353 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
354 env->DeleteLocalRef(jInnerArray);
355 value.push_back(innerVector);
358 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
361 std::string key = env->GetStringUTFChars(jKey, NULL);
362 rep->setValue(key, value);
366 * Class: org_iotivity_base_OcRepresentation
367 * Method: setValueDouble3DArray
368 * Signature: (Ljava/lang/String;[[[D)V
370 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DArray
371 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
373 LOGD("OcRepresentation_setValueDouble3DArray");
376 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
379 std::vector<std::vector<std::vector<double>>> value;
380 const jsize lenOuter = env->GetArrayLength(jValue);
381 for (jsize k = 0; k < lenOuter; ++k)
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)
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)
394 innerVector.push_back(static_cast<double>(doubles[i]));
396 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
397 env->DeleteLocalRef(jInnerArray);
398 middleArray.push_back(innerVector);
400 env->DeleteLocalRef(jMiddleArray);
401 value.push_back(middleArray);
404 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
407 std::string key = env->GetStringUTFChars(jKey, NULL);
408 rep->setValue(key, value);
412 * Class: org_iotivity_base_OcRepresentation
413 * Method: setValueBooleanArray
414 * Signature: (Ljava/lang/String;[Z)V
416 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanArray
417 (JNIEnv *env, jobject thiz, jstring jKey, jbooleanArray jValue)
419 LOGD("OcRepresentation_setValueBooleanArray");
422 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
426 const jsize len = env->GetArrayLength(jValue);
427 jboolean* booleans = env->GetBooleanArrayElements(jValue, NULL);
429 std::vector<bool> value;
430 for (jsize i = 0; i < len; ++i)
432 value.push_back(static_cast<bool>(booleans[i]));
434 env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT);
436 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
439 std::string key = env->GetStringUTFChars(jKey, NULL);
440 rep->setValue(key, value);
444 * Class: org_iotivity_base_OcRepresentation
445 * Method: setValueBoolean2DArray
446 * Signature: (Ljava/lang/String;[[Z)V
448 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2DArray
449 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
451 LOGD("OcRepresentation_setValueBoolean2DArray");
454 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
457 std::vector<std::vector<bool>> value;
458 const jsize lenOuter = env->GetArrayLength(jValue);
459 for (jsize j = 0; j < lenOuter; ++j)
461 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jValue, j));
462 const jsize lenInner = env->GetArrayLength(jInnerArray);
463 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, NULL);
465 std::vector<bool> innerVector;
466 for (jsize i = 0; i < lenInner; ++i)
468 innerVector.push_back(static_cast<bool>(booleans[i]));
470 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
471 env->DeleteLocalRef(jInnerArray);
472 value.push_back(innerVector);
475 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
478 std::string key = env->GetStringUTFChars(jKey, NULL);
479 rep->setValue(key, value);
483 * Class: org_iotivity_base_OcRepresentation
484 * Method: setValueBoolean3DArray
485 * Signature: (Ljava/lang/String;[[[Z)V
487 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3DArray
488 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
490 LOGD("OcRepresentation_setValueBoolean3DArray");
493 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
496 std::vector<std::vector<std::vector<bool>>> value;
497 const jsize lenOuter = env->GetArrayLength(jValue);
498 for (jsize k = 0; k < lenOuter; ++k)
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)
505 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jMiddleArray, j));
506 const jsize lenInner = env->GetArrayLength(jInnerArray);
507 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, NULL);
509 std::vector<bool> innerVector;
510 for (jsize i = 0; i < lenInner; ++i)
512 innerVector.push_back(static_cast<bool>(booleans[i]));
514 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
515 env->DeleteLocalRef(jInnerArray);
516 middleArray.push_back(innerVector);
518 env->DeleteLocalRef(jMiddleArray);
519 value.push_back(middleArray);
522 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
525 std::string key = env->GetStringUTFChars(jKey, NULL);
526 rep->setValue(key, value);
530 * Class: org_iotivity_base_OcRepresentation
531 * Method: setValueStringArray
532 * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
534 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArray
535 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
537 LOGD("OcRepresentation_setValueStringArray");
540 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
544 std::vector<std::string> value;
545 JniUtils::convertJavaStrArrToStrVector(env, jValue, value);
547 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
550 std::string key = env->GetStringUTFChars(jKey, NULL);
551 rep->setValue(key, value);
555 * Class: org_iotivity_base_OcRepresentation
556 * Method: setValueString2DArray
557 * Signature: (Ljava/lang/String;[[Ljava/lang/String;)V
559 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DArray
560 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
562 LOGD("OcRepresentation_setValueString2DArray");
565 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
568 std::vector<std::vector<std::string>> value;
569 const jsize lenOuter = env->GetArrayLength(jValue);
570 for (jsize j = 0; j < lenOuter; ++j)
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);
579 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
582 std::string key = env->GetStringUTFChars(jKey, NULL);
583 rep->setValue(key, value);
587 * Class: org_iotivity_base_OcRepresentation
588 * Method: setValueString3DArray
589 * Signature: (Ljava/lang/String;[[[Ljava/lang/String;)V
591 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DArray
592 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
594 LOGD("OcRepresentation_setValueString3DArray");
597 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
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)
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)
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);
615 env->DeleteLocalRef(jMiddleArray);
616 value.push_back(middleArray);
619 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
622 std::string key = env->GetStringUTFChars(jKey, NULL);
623 rep->setValue(key, value);
627 * Class: org_iotivity_base_OcRepresentation
628 * Method: setValueRepresentationArray
629 * Signature: (Ljava/lang/String;[Lorg/iotivity/base/OcRepresentation;)V
631 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentationArray
632 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
634 LOGD("OcRepresentation_setValueRepresentationArray");
637 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
641 std::vector<OCRepresentation> value;
642 JniUtils::convertJavaRepresentationArrToVector(env, jValue, value);
644 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
647 std::string key = env->GetStringUTFChars(jKey, NULL);
648 rep->setValue(key, value);
652 * Class: org_iotivity_base_OcRepresentation
653 * Method: setValueRepresentation2DArray
654 * Signature: (Ljava/lang/String;[[Lorg/iotivity/base/OcRepresentation;)V
656 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation2DArray
657 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
659 LOGD("OcRepresentation_setValueRepresentation2DArray");
662 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
665 std::vector<std::vector<OCRepresentation>> value;
666 const jsize lenOuter = env->GetArrayLength(jValue);
667 for (jsize j = 0; j < lenOuter; ++j)
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);
676 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
679 std::string key = env->GetStringUTFChars(jKey, NULL);
680 rep->setValue(key, value);
684 * Class: org_iotivity_base_OcRepresentation
685 * Method: setValueRepresentation3DArray
686 * Signature: (Ljava/lang/String;[[[Lorg/iotivity/base/OcRepresentation;)V
688 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation3DArray
689 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
691 LOGD("OcRepresentation_setValueRepresentation3DArray");
694 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
697 std::vector<std::vector<std::vector<OCRepresentation>>> value;
698 const jsize lenOuter = env->GetArrayLength(jValue);
699 for (jsize k = 0; k < lenOuter; ++k)
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)
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);
712 env->DeleteLocalRef(jMiddleArray);
713 value.push_back(middleArray);
716 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
719 std::string key = env->GetStringUTFChars(jKey, NULL);
720 rep->setValue(key, value);
724 * Class: org_iotivity_base_OcRepresentation
726 * Signature: (Lorg/iotivity/base/OcRepresentation;)V
728 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
729 (JNIEnv *env, jobject thiz, jobject jOcRepresentation)
731 LOGD("OcRepresentation_addChild");
732 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
735 OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
738 rep->addChild(*child);
742 * Class: org_iotivity_base_OcRepresentation
743 * Method: clearChildren
746 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren
747 (JNIEnv *env, jobject thiz)
749 LOGD("OcRepresentation_clearChildren");
750 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
753 rep->clearChildren();
757 * Class: org_iotivity_base_OcRepresentation
758 * Method: getChildrenArray
759 * Signature: ()[Lorg/iotivity/base/OcRepresentation;
761 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
762 (JNIEnv *env, jobject thiz)
764 LOGD("OcRepresentation_getChildrenArray");
765 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
766 if (!rep) return nullptr;
768 return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
772 * Class: org_iotivity_base_OcRepresentation
774 * Signature: ()Ljava/lang/String;
776 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri
777 (JNIEnv *env, jobject thiz)
779 LOGD("OcRepresentation_getUri");
780 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
781 if (!rep) return nullptr;
783 std::string uri(rep->getUri());
784 return env->NewStringUTF(uri.c_str());
788 * Class: org_iotivity_base_OcRepresentation
790 * Signature: (Ljava/lang/String;)V
792 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri
793 (JNIEnv *env, jobject thiz, jstring jUri)
795 LOGD("OcRepresentation_setUri");
798 ThrowOcException(OC_STACK_INVALID_PARAM, "uri cannot be null");
801 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
804 rep->setUri(env->GetStringUTFChars(jUri, NULL));
807 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute
808 (JNIEnv *env, jobject thiz, jstring jstr)
810 LOGD("OcRepresentation_hasAttribute");
813 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
816 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
817 if (!rep) return false;
819 std::string str = env->GetStringUTFChars(jstr, NULL);
820 return rep->hasAttribute(str);
824 * Class: org_iotivity_base_OcRepresentation
825 * Method: getResourceTypes
826 * Signature: ()Ljava/util/List;
828 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTypes
829 (JNIEnv *env, jobject thiz)
831 LOGD("OcRepresentation_getResourceTypes");
832 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
833 if (!rep) return nullptr;
835 std::vector<std::string> resourceTypes = rep->getResourceTypes();
836 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
840 * Class: org_iotivity_base_OcRepresentation
841 * Method: setResourceTypeArray
842 * Signature: ([Ljava/lang/String;)V
844 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeArray
845 (JNIEnv *env, jobject thiz, jobjectArray jResourceTypeArray)
847 LOGD("OcRepresentation_setResourceTypeArray");
848 if (!jResourceTypeArray)
850 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");
853 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
856 std::vector<std::string> resourceTypes;
857 JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
858 rep->setResourceTypes(resourceTypes);
861 * Class: org_iotivity_base_OcRepresentation
862 * Method: getResourceInterfaces
863 * Signature: ()Ljava/util/List;
865 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInterfaces
866 (JNIEnv *env, jobject thiz)
868 LOGD("OcRepresentation_getResourceInterfaces");
869 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
870 if (!rep) return nullptr;
872 std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
873 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
877 * Class: org_iotivity_base_OcRepresentation
878 * Method: setResourceInterfaceArray
879 * Signature: ([Ljava/lang/String;)V
881 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterfaceArray
882 (JNIEnv *env, jobject thiz, jobjectArray jResourceInterfaceArray)
884 LOGD("OcRepresentation_setResourceInterfaceArray");
885 if (!jResourceInterfaceArray)
887 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceInterfaceList cannot be null");
890 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
893 std::vector<std::string> resourceInterfaces;
894 JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
895 rep->setResourceInterfaces(resourceInterfaces);
899 * Class: org_iotivity_base_OcRepresentation
903 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty
904 (JNIEnv *env, jobject thiz)
906 LOGD("OcRepresentation_isEmpty");
907 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
908 if (!rep) return false;
910 return static_cast<jboolean>(rep->empty());
914 * Class: org_iotivity_base_OcRepresentation
918 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size
919 (JNIEnv *env, jobject thiz)
921 LOGD("OcRepresentation_size");
922 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
925 return static_cast<jint>(rep->numberOfAttributes());
929 * Class: org_iotivity_base_OcRepresentation
931 * Signature: (Ljava/lang/String;)Z
933 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove
934 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
936 LOGD("OcRepresentation_remove");
939 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
942 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
943 if (!rep) return false;
945 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
946 return static_cast<jboolean>(rep->erase(attributeKey));
950 * Class: org_iotivity_base_OcRepresentation
952 * Signature: (Ljava/lang/String;)V
954 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull
955 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
957 LOGD("OcRepresentation_setNull");
960 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
963 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
966 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
967 rep->setNULL(attributeKey);
971 * Class: org_iotivity_base_OcRepresentation
973 * Signature: (Ljava/lang/String;)Z
975 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull
976 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
978 LOGD("OcRepresentation_isNull");
981 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
984 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
985 if (!rep) return false;
987 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
988 return static_cast<jboolean>(rep->isNULL(attributeKey));
992 * Class: org_iotivity_base_OcRepresentation
996 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_create
997 (JNIEnv *env, jobject thiz)
999 LOGD("OcRepresentation_create");
1000 OCRepresentation *rep = new OCRepresentation();
1001 SetHandle<OCRepresentation>(env, thiz, rep);
1002 if (env->ExceptionCheck())
1004 LOGE("Failed to set native handle for OcRepresentation");
1010 * Class: org_iotivity_base_OcRepresentation
1014 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_dispose
1015 (JNIEnv *env, jobject thiz, jboolean jNeedsDelete)
1017 LOGD("OcRepresentation_dispose");
1018 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);