]> git.proxmox.com Git - ceph.git/blob - ceph/src/java/native/JniConstants.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / java / native / JniConstants.cpp
1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "JniConstants.h"
18 #include "ScopedLocalRef.h"
19
20 #include <stdlib.h>
21
22 jclass JniConstants::inet6AddressClass;
23 jclass JniConstants::inetAddressClass;
24 jclass JniConstants::inetSocketAddressClass;
25 jclass JniConstants::stringClass;
26
27 static jclass findClass(JNIEnv* env, const char* name) {
28 ScopedLocalRef<jclass> localClass(env, env->FindClass(name));
29 jclass result = reinterpret_cast<jclass>(env->NewGlobalRef(localClass.get()));
30 if (result == NULL) {
31 fprintf(stderr, "failed to find class '%s'", name);
32 abort();
33 }
34 return result;
35 }
36
37 void JniConstants::init(JNIEnv* env) {
38 inet6AddressClass = findClass(env, "java/net/Inet6Address");
39 inetAddressClass = findClass(env, "java/net/InetAddress");
40 inetSocketAddressClass = findClass(env, "java/net/InetSocketAddress");
41 stringClass = findClass(env, "java/lang/String");
42 }