javaextensions/satsa/pki/src.s60/rjstring.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "jutils.h"
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25 * Constuctor taking a Java JNI string and converting it to an EPOC .
       
    26 */
       
    27 OS_EXPORT  RJString::RJString(JNIEnv& aJni, jstring aString)
       
    28         : iJni(aJni), iString(aString)
       
    29 {
       
    30     // Potential for a string to be NULL, but NULL cannot be passed into
       
    31     // JNI methods, so must check. If string is NULL, will result in empty string
       
    32     if (iString != NULL)
       
    33     {
       
    34         const jchar* ptr = aJni.GetStringChars(iString, NULL);
       
    35         const jint   len = aJni.GetStringLength(iString);
       
    36         if (ptr)
       
    37         {
       
    38             Set(ptr, len);
       
    39         }
       
    40     }
       
    41 }
       
    42 
       
    43 
       
    44 
       
    45 /**
       
    46 * Frees up the JNI string resources, if they need to be freed.
       
    47 */
       
    48 OS_EXPORT  RJString::~RJString()
       
    49 {
       
    50     if (iString != NULL)
       
    51     {
       
    52         iJni.ReleaseStringChars(iString, this->Ptr());
       
    53     }
       
    54 }
       
    55 
       
    56