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 "JavaExceptions.h"
23 #include "JNIEnvWrapper.h"
26 #include "RCSException.h"
30 jclass g_cls_PlatformException;
32 jmethodID g_ctor_PlatformException;
35 void initJavaExceptions(JNIEnvWrapper* env)
37 g_cls_PlatformException = env->FindClassAsGlobalRef(EXC_NAME_PLATFORM);
38 g_ctor_PlatformException = env->GetConstructorID(g_cls_PlatformException,
39 "(" AS_SIG(CLS_NAME_STRING) "I)V");
42 void clearJavaExceptions(JNIEnvWrapper* env)
44 env->DeleteGlobalRef(g_cls_PlatformException);
47 void throwPlatformException(JNIEnv* env, const OIC::Service::RCSPlatformException& e)
49 auto msg = newStringObject(env, e.getReason());
52 auto exObj = env->NewObject(g_cls_PlatformException, g_ctor_PlatformException,
53 msg, e.getReasonCode());
56 env->Throw(static_cast< jthrowable >(exObj));