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 "JavaClasses.h"
23 #include "JNIEnvWrapper.h"
30 jclass g_cls_ArrayList;
33 jclass g_cls_MapEntry;
34 jclass g_cls_Iterator;
36 jmethodID g_method_Boolean_booleanValue;
37 jmethodID g_method_Integer_intValue;
38 jmethodID g_method_Double_doubleValue;
40 jmethodID g_method_Collection_add;
42 jmethodID g_method_Set_iterator;
44 jmethodID g_method_Map_entrySet;
45 jmethodID g_method_Map_put;
47 jmethodID g_method_MapEntry_getKey;
48 jmethodID g_method_MapEntry_getValue;
50 jmethodID g_method_Iterator_hasNext;
51 jmethodID g_method_Iterator_next;
53 jmethodID g_ctor_Boolean;
54 jmethodID g_ctor_Integer;
55 jmethodID g_ctor_Double;
57 jmethodID g_ctor_ArrayList;
61 inline void initPrimitiveTypes(JNIEnvWrapper *env)
63 g_cls_Boolean = env->FindClassAsGlobalRef(CLS_NAME_BOOLEAN);
64 g_ctor_Boolean = env->GetConstructorID(g_cls_Boolean, "(Z)V");
65 g_method_Boolean_booleanValue = env->GetMethodID(g_cls_Boolean, "booleanValue", "()Z");
67 g_cls_Integer = env->FindClassAsGlobalRef(CLS_NAME_INTEGER);
68 g_ctor_Integer = env->GetConstructorID(g_cls_Integer, "(I)V");
69 g_method_Integer_intValue = env->GetMethodID(g_cls_Integer, "intValue", "()I");
71 g_cls_Double = env->FindClassAsGlobalRef(CLS_NAME_DOUBLE);
72 g_ctor_Double = env->GetConstructorID(g_cls_Double, "(D)V");
73 g_method_Double_doubleValue = env->GetMethodID(g_cls_Double, "doubleValue", "()D");
75 g_cls_String = env->FindClassAsGlobalRef(CLS_NAME_STRING);
79 void initJavaClasses(JNIEnvWrapper *env)
81 initPrimitiveTypes(env);
83 auto clsCollection = env->FindClass(CLS_NAME_COLLECTION);
84 g_method_Collection_add = env->GetMethodID(clsCollection, "add",
85 "(" AS_SIG(CLS_NAME_OBJECT) ")Z");
87 g_cls_ArrayList = env->FindClassAsGlobalRef(CLS_NAME_ARRAY_LIST);
88 g_ctor_ArrayList = env->GetConstructorID(g_cls_ArrayList, "()V");
90 g_cls_Set = env->FindClassAsGlobalRef(CLS_NAME_SET);
91 g_method_Set_iterator = env->GetMethodID(g_cls_Set, "iterator", "()" AS_SIG(CLS_NAME_ITERATOR));
93 g_cls_Map = env->FindClassAsGlobalRef(CLS_NAME_MAP);
94 g_method_Map_entrySet = env->GetMethodID(g_cls_Map, "entrySet", "()" AS_SIG(CLS_NAME_SET));
95 g_method_Map_put = env->GetMethodID(g_cls_Map, "put",
96 "(" AS_SIG(CLS_NAME_OBJECT) AS_SIG(CLS_NAME_OBJECT) ")" AS_SIG(CLS_NAME_OBJECT));
98 g_cls_MapEntry = env->FindClassAsGlobalRef(CLS_NAME_MAP_ENTRY);
99 g_method_MapEntry_getKey = env->GetMethodID(g_cls_MapEntry, "getKey",
100 "()" AS_SIG(CLS_NAME_OBJECT));
101 g_method_MapEntry_getValue = env->GetMethodID(g_cls_MapEntry, "getValue",
102 "()" AS_SIG(CLS_NAME_OBJECT));
104 g_cls_Iterator = env->FindClassAsGlobalRef(CLS_NAME_ITERATOR);
105 g_method_Iterator_hasNext = env->GetMethodID(g_cls_Iterator, "hasNext", "()Z");
106 g_method_Iterator_next = env->GetMethodID(g_cls_Iterator, "next", "()" AS_SIG(CLS_NAME_OBJECT));
109 void clearJavaClasses(JNIEnvWrapper *env)
111 env->DeleteGlobalRef(g_cls_Boolean);
112 env->DeleteGlobalRef(g_cls_Integer);
113 env->DeleteGlobalRef(g_cls_Double);
114 env->DeleteGlobalRef(g_cls_String);
115 env->DeleteGlobalRef(g_cls_Set);
116 env->DeleteGlobalRef(g_cls_Map);
117 env->DeleteGlobalRef(g_cls_MapEntry);
118 env->DeleteGlobalRef(g_cls_Iterator);