javacommons/javastorage/src/client/javastorageentry.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  JavaStorageEntry
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <stdio.h>
       
    20 
       
    21 #include "javastorageentry.h"
       
    22 #include "javastorageexception.h"
       
    23 
       
    24 using namespace java::storage;
       
    25 using namespace std;
       
    26 
       
    27 OS_EXPORT void JavaStorageEntry::setEntry(const std::wstring& aName,
       
    28         const std::wstring& aValue,
       
    29         JavaEntryColumnType aType)
       
    30 {
       
    31     if (aName.size() == 0)
       
    32     {
       
    33         throw JavaStorageException(
       
    34             EInvalidArgument,
       
    35             "Invalid entry name",
       
    36             __FILE__,
       
    37             __FUNCTION__,
       
    38             __LINE__);
       
    39     }
       
    40 
       
    41     if (aType < 1 || aType > NULL_TYPE)
       
    42     {
       
    43         throw JavaStorageException(
       
    44             EInvalidArgument,
       
    45             "Invalid entry type",
       
    46             __FILE__,
       
    47             __FUNCTION__,
       
    48             __LINE__);
       
    49     }
       
    50 
       
    51     mName = aName;
       
    52 
       
    53     if (aType == NULL_TYPE)
       
    54     {
       
    55         mValue = L"NULL";
       
    56         mType = aType;
       
    57     }
       
    58     else
       
    59     {
       
    60         mValue = aValue;
       
    61         mType = aType;
       
    62     }
       
    63 }
       
    64 
       
    65 OS_EXPORT wstring JavaStorageEntry::entryName() const
       
    66 {
       
    67     return mName;
       
    68 }
       
    69 
       
    70 OS_EXPORT wstring JavaStorageEntry::entryValue() const
       
    71 {
       
    72     if (mType != NULL_TYPE)
       
    73         return mValue;
       
    74     else
       
    75         return L"";
       
    76 }
       
    77 
       
    78 OS_EXPORT JavaStorageEntry::JavaEntryColumnType JavaStorageEntry::entryType() const
       
    79 {
       
    80     return mType;
       
    81 }
       
    82 
       
    83 OS_EXPORT bool JavaStorageEntry::operator< (const JavaStorageEntry& jse) const
       
    84 {
       
    85     if (mName == jse.entryName())
       
    86     {
       
    87         // Comparison is done only by the name
       
    88         if (mValue == L"")
       
    89         {
       
    90             return mName < jse.entryName();
       
    91         }
       
    92         else  // By the name and value
       
    93         {
       
    94             return mValue < jse.entryValue();
       
    95         }
       
    96     }
       
    97     else
       
    98     {
       
    99         return mName < jse.entryName();
       
   100     }
       
   101 }