javamanager/javasettings/appmngrplugin/src/appmngr2midletstorageutil.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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:  MidletAppInfo implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2midletstorageutil.h"
       
    20 #include "exceptionbase.h"
       
    21 #include "javastoragenames.h"
       
    22 #include "javasymbianoslayer.h"
       
    23 #include "javauid.h"
       
    24 #include "logger.h"                          // LOG
       
    25 
       
    26 using namespace java::storage;
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CAppMngr2MidletAppInfo::AppMngr2MidletStorageUtil()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 AppMngr2MidletStorageUtil::AppMngr2MidletStorageUtil()
       
    35 {
       
    36     mStorage.reset(JavaStorage::createInstance());
       
    37     mIsOpen = false;
       
    38 }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CAppMngr2MidletAppInfo::~AppMngr2MidletStorageUtil()
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 AppMngr2MidletStorageUtil::~AppMngr2MidletStorageUtil()
       
    45 {
       
    46     if (mIsOpen)
       
    47     {
       
    48         try
       
    49         {
       
    50             mStorage->close();
       
    51         }
       
    52         catch (JavaStorageException& aJse)
       
    53         {
       
    54             // No can do.
       
    55             //LOG(EJavaAppMngrPlugin, EInfo, "Storage connection close failed.");
       
    56         }
       
    57     }
       
    58 }
       
    59 
       
    60 void AppMngr2MidletStorageUtil::populateSuiteInformation(const TUid aUid)
       
    61 {
       
    62     mPopulatedEntry.clear();
       
    63 
       
    64     checkConnection();
       
    65     java::util::Uid javaUid;
       
    66 
       
    67     try
       
    68     {
       
    69         mStorage->read(APPLICATION_PACKAGE_TABLE,
       
    70                        TUidToUid(aUid, javaUid),
       
    71                        mPopulatedEntry);
       
    72     }
       
    73     catch (JavaStorageException& aJse)
       
    74     {
       
    75         WLOG(EJavaAppMngrPlugin, "Suite information population failed.");
       
    76     }
       
    77 }
       
    78 
       
    79 HBufC* AppMngr2MidletStorageUtil::attribute(const TDesC& aName)
       
    80 {
       
    81     std::auto_ptr<HBufC16> nameBuf(HBufC16::New(aName.Size() + 1));
       
    82 
       
    83     if (!nameBuf.get())
       
    84     {
       
    85         ELOG(EJavaAppMngrPlugin, "Cannot allocate name buffer.");
       
    86         throw java::util::ExceptionBase(
       
    87             "Out of memory", __FILE__, __FUNCTION__, __LINE__);
       
    88     }
       
    89 
       
    90     TPtr16 namePtr(nameBuf->Des());
       
    91     namePtr.Copy(aName);
       
    92     std::wstring name(desToWstring(namePtr));
       
    93 
       
    94     JavaStorageEntry attr;
       
    95     attr.setEntry(name, L"");
       
    96 
       
    97     JavaStorageApplicationEntry_t::const_iterator finder =
       
    98         mPopulatedEntry.find(attr);
       
    99 
       
   100     std::wstring value = L"";
       
   101     if (finder != mPopulatedEntry.end())
       
   102     {
       
   103         value = (*finder).entryValue();
       
   104     }
       
   105     else
       
   106     {
       
   107         ILOG1(EJavaAppMngrPlugin, "Attribute '%S' not found.", name.c_str());
       
   108         return NULL;
       
   109     }
       
   110 
       
   111     HBufC* valueBuf(HBufC16::New(value.size() + 1));
       
   112 
       
   113     if (!valueBuf)
       
   114     {
       
   115         ELOG(EJavaAppMngrPlugin, "Cannot allocate value buffer.");
       
   116         throw java::util::ExceptionBase(
       
   117             "Out of memory", __FILE__, __FUNCTION__, __LINE__);
       
   118     }
       
   119 
       
   120     TPtr16 valuePtr(valueBuf->Des());
       
   121     valuePtr = (const TUint16*)value.c_str();
       
   122     return valueBuf;    // Ownership is transfered.
       
   123 }
       
   124 
       
   125 void AppMngr2MidletStorageUtil::checkConnection()
       
   126 {
       
   127     if (!mIsOpen)
       
   128     {
       
   129         try
       
   130         {
       
   131             mStorage->open();
       
   132             mIsOpen = true;
       
   133         }
       
   134         catch (JavaStorageException& aJse)
       
   135         {
       
   136             WLOG(EJavaAppMngrPlugin, "Cannot open storage connection.");
       
   137         }
       
   138     }
       
   139 }