Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / things-manager / sdk / java / jni / jniutil / src / jni_string.cpp
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #include "jni_string.h"
22
23 #define LOG_TAG "TM_JString"
24
25 JString::JString(JNIEnv *env, jstring value) : JObject(env, value)
26 {
27     const char *buff = env->GetStringUTFChars(value, 0);
28
29     m_cstr = buff;
30
31     env->ReleaseStringUTFChars(value, buff);
32 }
33
34 JString::JString(JNIEnv *env, const char *value) : JObject(env)
35 {
36     m_cstr = value;
37
38     if (env)
39     {
40         m_pObject = env->NewStringUTF( value );
41     }
42 }
43
44 JString::JString(JNIEnv *env, const std::string &value) : JObject(env)
45 {
46     m_cstr = value;
47
48     if (env)
49     {
50         m_pObject = env->NewStringUTF( value.c_str() );
51     }
52 }
53
54 JString::~JString()
55 {
56 }
57
58 bool JString::getValue(std::string &value)
59 {
60     value = m_cstr;
61     return true;
62 }
63
64 const char *JString::c_str()
65 {
66     return m_cstr.c_str();
67 }
68
69