webservices/wsutils/src/senidentifier.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2005 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 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include "senidentifier.h"
       
    26 #include "sencertutils.h"
       
    27 
       
    28 #include "senlogger.h"
       
    29 
       
    30 EXPORT_C CSenIdentifier* CSenIdentifier::NewL()
       
    31     {
       
    32     CSenIdentifier* self = NewLC();
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35     }
       
    36 
       
    37 EXPORT_C CSenIdentifier* CSenIdentifier::NewLC()
       
    38     {
       
    39     CSenIdentifier* self = new (ELeave) CSenIdentifier();
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL(SenIdentifier::EUnknown, KNullDesC8(), KNullDesC8());
       
    42     return self;
       
    43     }
       
    44 
       
    45 EXPORT_C CSenIdentifier* CSenIdentifier::NewL(const CSenIdentifier& aParent)
       
    46     {
       
    47     CSenIdentifier* self = NewLC(aParent);
       
    48     CleanupStack::Pop(self);
       
    49     return self;
       
    50     }
       
    51 
       
    52 EXPORT_C CSenIdentifier* CSenIdentifier::NewLC(const CSenIdentifier& aParent)
       
    53     {
       
    54     CSenIdentifier* self = new (ELeave) CSenIdentifier();
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL(aParent);
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 EXPORT_C CSenIdentifier* CSenIdentifier::NewL(SenIdentifier::TIdentifierType aIdentifierType, 
       
    62                                               const TDesC8& aIdentifierValue)
       
    63     {
       
    64     CSenIdentifier* self = NewLC(aIdentifierType, aIdentifierValue);
       
    65     CleanupStack::Pop(self);
       
    66     return self;
       
    67     }
       
    68 
       
    69 EXPORT_C CSenIdentifier* CSenIdentifier::NewLC(SenIdentifier::TIdentifierType aIdentifierType, 
       
    70                                                const TDesC8& aIdentifierValue)
       
    71     {
       
    72     CSenIdentifier* self = new (ELeave) CSenIdentifier();
       
    73     CleanupStack::PushL(self);
       
    74     self->ConstructL(aIdentifierType, aIdentifierValue, KNullDesC8());
       
    75     return self;
       
    76     }
       
    77 
       
    78 
       
    79 EXPORT_C CSenIdentifier* CSenIdentifier::NewL(SenIdentifier::TIdentifierType aIdentifierType, 
       
    80                                               const TCertInfo& aCertInfo)
       
    81     {
       
    82     CSenIdentifier* self = NewLC(aIdentifierType, aCertInfo);
       
    83     CleanupStack::Pop(self);
       
    84     return self;
       
    85     }
       
    86 
       
    87 EXPORT_C CSenIdentifier* CSenIdentifier::NewLC(SenIdentifier::TIdentifierType aIdentifierType, 
       
    88                                                const TCertInfo& aCertInfo)
       
    89     {
       
    90     CSenIdentifier* self = new (ELeave) CSenIdentifier();
       
    91     CleanupStack::PushL(self);
       
    92     HBufC8* pCertInfo = SenCertUtils::CertInfoToStringLC(aCertInfo);
       
    93     self->ConstructL(aIdentifierType, *pCertInfo, KNullDesC8);
       
    94     CleanupStack::PopAndDestroy(); // CertInfoToStringLC
       
    95     return self;
       
    96     }
       
    97 
       
    98 
       
    99 EXPORT_C CSenIdentifier* CSenIdentifier::NewL(SenIdentifier::TIdentifierType aIdentifierType, 
       
   100                                               const TDesC8& aIdentifierValue, 
       
   101                                               const TDesC8& aFriendlyName)
       
   102     {
       
   103     CSenIdentifier* self = NewLC(aIdentifierType, aIdentifierValue, aFriendlyName);
       
   104     CleanupStack::Pop(self);
       
   105     return self;
       
   106     }
       
   107 
       
   108 EXPORT_C CSenIdentifier* CSenIdentifier::NewLC(SenIdentifier::TIdentifierType aIdentifierType, 
       
   109                                                const TDesC8& aIdentifierValue, 
       
   110                                                const TDesC8& aFriendlyName)
       
   111     {
       
   112     CSenIdentifier* self = new (ELeave) CSenIdentifier();
       
   113     CleanupStack::PushL(self);
       
   114     self->ConstructL(aIdentifierType, aIdentifierValue, aFriendlyName);
       
   115     return self;
       
   116     }
       
   117 
       
   118 
       
   119 void CSenIdentifier::ConstructL(SenIdentifier::TIdentifierType aIdentifierType, 
       
   120                                 const TDesC8& aIdentifierValue, 
       
   121                                 const TDesC8& aFriendlyName)
       
   122     {
       
   123     TLSLOG_L(KSenUtilsLogChannel, KMinLogLevel, "CSenIdentifier::ConstructL - Start");
       
   124 
       
   125     iType = aIdentifierType;
       
   126     ipValue = aIdentifierValue.AllocL();
       
   127     ipFriendlyName = aFriendlyName.AllocL();
       
   128     ipStatements = CSenAttributes::NewL();
       
   129     ipParent = this;
       
   130     TLSLOG_L(KSenUtilsLogChannel, KMinLogLevel, "CSenIdentifier::ConstructL - End");
       
   131     }
       
   132 
       
   133 void CSenIdentifier::ConstructL(const CSenIdentifier& aParent)
       
   134     {
       
   135     TLSLOG_L(KSenUtilsLogChannel, KMinLogLevel, "CSenIdentifier::ConstructL - Start");
       
   136     iType = aParent.iType;
       
   137     ipValue = aParent.Value().AllocL();
       
   138     ipFriendlyName = aParent.ipFriendlyName->AllocL();
       
   139     ipStatements = CSenAttributes::NewL(aParent.Statements());
       
   140 
       
   141     // Note that all childs in chain get the root as their parent(!):
       
   142     ipParent = CSenIdentifier::NewL(aParent.Parent()); 
       
   143     TLSLOG_L(KSenUtilsLogChannel, KMinLogLevel, "CSenIdentifier::ConstructL - End");
       
   144     }
       
   145 
       
   146 CSenIdentifier::CSenIdentifier() : 
       
   147     ipValue(NULL),
       
   148     ipFriendlyName(NULL),
       
   149     ipStatements(NULL)
       
   150     {
       
   151 
       
   152     iType = SenIdentifier::EUnknown;
       
   153     }
       
   154 
       
   155 
       
   156 EXPORT_C CSenIdentifier::~CSenIdentifier()
       
   157     {
       
   158     delete ipValue;         // it is safe to delete NULL in Symbian C++
       
   159     delete ipFriendlyName;
       
   160     delete ipStatements;
       
   161 
       
   162     delete Proxy(); // destroy the parent (proxy), if such is owned 
       
   163     /*
       
   164     if ( IsProxy() )  // atm equal to: delete Proxy();
       
   165         {   
       
   166         delete ipParent; // mm: was identifier ment to take ownership of its parent?
       
   167         }
       
   168     */
       
   169     }
       
   170 
       
   171 
       
   172 EXPORT_C TPtrC8 CSenIdentifier::Value() const
       
   173     {
       
   174     return *ipValue;
       
   175     }
       
   176 
       
   177 
       
   178 EXPORT_C SenIdentifier::TIdentifierType CSenIdentifier::Type() const
       
   179     {
       
   180     return iType;
       
   181     }
       
   182 
       
   183 
       
   184 EXPORT_C TBool CSenIdentifier::Equals(const CSenIdentifier& otherIdentifier)
       
   185     {
       
   186     TBool result = EFalse;
       
   187     result = (iType == otherIdentifier.Type()) && (0 == ipValue->Compare(otherIdentifier.Value()));
       
   188     return(result);
       
   189     }
       
   190 
       
   191 // == ParentFor
       
   192 EXPORT_C void CSenIdentifier::ProxyFor( CSenIdentifier* aIdentifier )
       
   193     {
       
   194     ipParent = aIdentifier;
       
   195     }
       
   196 
       
   197 /*
       
   198 
       
   199 EXPORT_C TBool CSenIdentifier::IsProxy() const
       
   200     {
       
   201     // if parent is NULL, then this is the root
       
   202     // and is thus not a proxy for another identifier
       
   203 
       
   204     return(!(ipParent == NULL));
       
   205     }
       
   206 
       
   207 // == Parent()
       
   208 EXPORT_C const CSenIdentifier* CSenIdentifier::Proxy() const
       
   209     {
       
   210     return(ipParent);    
       
   211     }
       
   212 
       
   213 
       
   214 EXPORT_C const CSenIdentifier* CSenIdentifier::Root() const
       
   215     {
       
   216     return( (IsProxy()) ? ipParent : this );   
       
   217     }
       
   218 */
       
   219 
       
   220 EXPORT_C TBool CSenIdentifier::IsProxy() const
       
   221     {
       
   222     // If parent is this, then this is the root
       
   223     // and thus not a proxy for another identifier
       
   224     return(!(ipParent == this));
       
   225     }
       
   226 
       
   227 // return the parent (or this, if this is not a proxy)
       
   228 EXPORT_C const CSenIdentifier* CSenIdentifier::Proxy() const
       
   229     {
       
   230     return( IsProxy() ? ipParent : NULL );    
       
   231     }
       
   232 
       
   233 // return the root of (possible parent) 
       
   234 EXPORT_C const CSenIdentifier* CSenIdentifier::Root() const
       
   235     {
       
   236     return( IsProxy() ? ipParent->Root() : this );   
       
   237     }
       
   238 
       
   239 EXPORT_C void CSenIdentifier::AddAttributeL( CSenAttribute& aAttribute )	//codescannerwarnings
       
   240     {
       
   241     ipStatements->AddAttributeL(aAttribute);	//codescannerwarnings
       
   242     }
       
   243 
       
   244 
       
   245 EXPORT_C const CSenAttributes* CSenIdentifier::Attributes() const
       
   246     {
       
   247     return ipStatements;
       
   248     }
       
   249 
       
   250 EXPORT_C TBool CSenIdentifier::operator==(const CSenIdentifier& a)
       
   251     {
       
   252     return (this==&a);
       
   253     }
       
   254 
       
   255 const CSenIdentifier& CSenIdentifier::Parent() const
       
   256     {
       
   257     // if(!ipParent) User::Leave( <define leave code >
       
   258     return *ipParent;
       
   259     }
       
   260 
       
   261 const CSenAttributes& CSenIdentifier::Statements() const
       
   262     {
       
   263     // if(!ipStatements) User::Leave( <define leave code >
       
   264     return *ipStatements;
       
   265     }
       
   266 
       
   267 // End of file
       
   268 
       
   269 
       
   270 
       
   271 
       
   272