1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "jni_queryparam.h"
22 #include "jni_string.h"
23 #include "simulator_utils_jni.h"
25 JniQueryParameter::JniQueryParameter(JNIEnv *env) : m_env(env) {}
27 std::map<std::string, std::string> JniQueryParameter::toCpp(jobject jQueryParams)
29 std::map<std::string, std::string> result;
33 static jmethodID entrySetMethodID = m_env->GetMethodID(gSimulatorClassRefs.mapCls, "entrySet",
35 static jmethodID iteratorMethodID = m_env->GetMethodID(gSimulatorClassRefs.setCls, "iterator",
36 "()Ljava/util/Iterator;");
37 static jmethodID hasNextMethodID = m_env->GetMethodID(gSimulatorClassRefs.iteratorCls, "hasNext",
39 static jmethodID nextMethodID = m_env->GetMethodID(gSimulatorClassRefs.iteratorCls, "next",
40 "()Ljava/lang/Object;");
41 static jmethodID getKeyMethodID = m_env->GetMethodID(gSimulatorClassRefs.mapEntryCls, "getKey",
42 "()Ljava/lang/Object;");
43 static jmethodID getValueMethodID = m_env->GetMethodID(gSimulatorClassRefs.mapEntryCls, "getValue",
44 "()Ljava/lang/Object;");
46 jobject entrySet = m_env->CallObjectMethod(jQueryParams, entrySetMethodID);
47 jobject iterator = m_env->CallObjectMethod(entrySet, iteratorMethodID);
48 if (!entrySet || !iterator || m_env->ExceptionCheck())
51 while (m_env->CallBooleanMethod(iterator, hasNextMethodID))
53 jobject entry = m_env->CallObjectMethod(iterator, nextMethodID);
54 jstring key = (jstring) m_env->CallObjectMethod(entry, getKeyMethodID);
55 jstring value = (jstring) m_env->CallObjectMethod(entry, getValueMethodID);
57 JniString jniKey(m_env, key);
58 JniString jniValue(m_env, key);
60 result[jniKey.get()] = jniValue.get();
62 m_env->DeleteLocalRef(entry);
63 m_env->DeleteLocalRef(key);
64 m_env->DeleteLocalRef(value);