webservices/wsstar/wsstarpolicy/src/wspolicyregistry.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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 FILES
       
    26 
       
    27 #include "wspolicyregistry.h"
       
    28 #include <SenXmlElement.h> // check if this include is needed(?)
       
    29 #include "wspolicy.h"
       
    30 
       
    31 using namespace WSPolicy;
       
    32 
       
    33 
       
    34 EXPORT_C CPolicyRegistry* CPolicyRegistry::NewL()
       
    35 {
       
    36      CPolicyRegistry* pSelf =
       
    37         CPolicyRegistry::NewLC();
       
    38     CleanupStack::Pop(pSelf);
       
    39     return pSelf;
       
    40    
       
    41 }
       
    42 EXPORT_C CPolicyRegistry* CPolicyRegistry::NewLC()
       
    43 {
       
    44     CPolicyRegistry* pSelf =
       
    45                         new (ELeave) CPolicyRegistry();
       
    46     CleanupStack::PushL(pSelf);
       
    47     pSelf->ConstructL();
       
    48     return pSelf;
       
    49   
       
    50 }
       
    51 CPolicyRegistry::~CPolicyRegistry()
       
    52 {
       
    53    iRegistry.Reset(); // destroys
       
    54    delete iParent;
       
    55 }
       
    56 EXPORT_C void CPolicyRegistry::PopulateRegistryL(CSenElement* aServicePolicy)	//codescannerwarnings
       
    57 {
       
    58     RPointerArray<CSenElement> policies;
       
    59     CleanupClosePushL(policies);
       
    60     aServicePolicy->ElementsL(policies,WSPolicy::KWsPolicyNsUri,WSPolicy::KWsPolicy);
       
    61     
       
    62     CSenElement* pPolicy = NULL;
       
    63    
       
    64     TInt count(policies.Count());
       
    65 
       
    66     if(count > 0)
       
    67     {
       
    68         
       
    69     for(TInt i=0; i<count; i++)
       
    70         {
       
    71         pPolicy = policies[i];
       
    72         if(pPolicy)
       
    73             {
       
    74                 TPtrC8 id = PolicyIdL(pPolicy);
       
    75                 TPtrC8 name = PolicyNameL(pPolicy);
       
    76                 if(id != KNullDesC8() && name != KNullDesC8())
       
    77                 RegisterPolicy(id, pPolicy);
       
    78             }
       
    79         }
       
    80     }
       
    81     
       
    82     CleanupStack::PopAndDestroy(); // policies
       
    83 }
       
    84 EXPORT_C void CPolicyRegistry::ResetRegistry()
       
    85 {
       
    86     iRegistry.Reset();
       
    87 }
       
    88 
       
    89 TPtrC8 CPolicyRegistry::PolicyIdL(CSenElement* aPolicy)
       
    90 {
       
    91     RPointerArray<CSenBaseAttribute>& attrs = aPolicy->AttributesL();
       
    92 
       
    93     CSenBaseAttribute* bs = NULL;
       
    94     TInt ele_count = attrs.Count();
       
    95          
       
    96     for (TInt j=0; j < ele_count; j++)
       
    97         {
       
    98             
       
    99         bs = (attrs)[j];
       
   100         if(bs)
       
   101 
       
   102         if(bs->Name().Compare(WSPolicy::KWsuId) == 0)
       
   103             {
       
   104              return bs->Value();
       
   105             }
       
   106          }
       
   107 
       
   108     return KNullDesC8();
       
   109 }
       
   110 TPtrC8 CPolicyRegistry::PolicyNameL(CSenElement* aPolicy)
       
   111 {
       
   112     RPointerArray<CSenBaseAttribute>& attrs = aPolicy->AttributesL();
       
   113 
       
   114     CSenBaseAttribute* bs = NULL;
       
   115     TInt ele_count = attrs.Count();
       
   116          
       
   117     for (TInt j=0; j < ele_count; j++)
       
   118         {
       
   119             
       
   120         bs = (attrs)[j];
       
   121         if(bs)
       
   122 
       
   123         if(bs->Name().Compare(WSPolicy::KName) == 0)
       
   124             {
       
   125              return bs->Value();
       
   126             }
       
   127          }
       
   128 
       
   129     return KNullDesC8();
       
   130 }
       
   131 
       
   132 
       
   133 EXPORT_C void CPolicyRegistry::SetParent(CPolicyRegistry* aParent)
       
   134 {
       
   135     iParent = aParent;
       
   136 }
       
   137 EXPORT_C CPolicyRegistry* CPolicyRegistry::Parent()
       
   138 {
       
   139     return iParent;
       
   140 }
       
   141 
       
   142 EXPORT_C CSenElement* CPolicyRegistry::LookupPolicyByNameL(const TPtrC8& aPolicyName)	//codescannerwarnings
       
   143 {
       
   144     if(aPolicyName.Length() <1)
       
   145         return NULL;
       
   146     
       
   147     TInt count = iRegistry.Count();
       
   148     
       
   149     for (TInt i = 0; i< count; i++)
       
   150     {
       
   151       CSenElement* policy = (CSenElement*)iRegistry.ValueAt(i);
       
   152       
       
   153       if(policy)
       
   154       {
       
   155         TPtrC8 name = PolicyNameL(policy);
       
   156         TPtrC8 policyUri = CWSPolicyUtils::PolicyUriL(policy);
       
   157         if(name != KNullDesC8() && (name.Compare(aPolicyName) == 0 
       
   158                                 || policyUri.Compare(aPolicyName) == 0))
       
   159         {
       
   160             return  policy;  
       
   161         }
       
   162       }
       
   163         
       
   164     }
       
   165 
       
   166     return NULL;
       
   167 }
       
   168 EXPORT_C CSenElement* CPolicyRegistry::LookupPolicy(const TPtrC8& aPolicyID)
       
   169 {
       
   170 
       
   171     TInt index = iRegistry.Find(aPolicyID);
       
   172     if(index!=KErrNotFound)
       
   173     {
       
   174         CSenElement* policy = (CSenElement*)iRegistry.ValueAt(index);
       
   175         TDesC8* policyId(iRegistry.KeyAt(index));
       
   176 
       
   177         if (policy == NULL && iParent != NULL) 
       
   178         {//No recursive calls as it is a flat array of policies
       
   179 //            policy = iParent->LookupPolicy(aPolicyURI);
       
   180         }
       
   181         
       
   182         return policy;
       
   183     }
       
   184     else
       
   185     return NULL;
       
   186 }
       
   187 EXPORT_C void CPolicyRegistry::RegisterPolicy(TDesC8& aPolicyID, CSenElement* aPolicy)
       
   188 {
       
   189     
       
   190     TInt index = iRegistry.Find(aPolicyID);
       
   191     if(index == KErrNotFound)
       
   192     {
       
   193         TInt  append = iRegistry.Append(aPolicyID.Alloc(), aPolicy);    
       
   194 //        if(append==KErrNone) { }
       
   195     }
       
   196     
       
   197 }
       
   198 EXPORT_C void CPolicyRegistry::UnregisterPolicy(const TPtrC8& aPolicyID)
       
   199 {
       
   200     TInt  retVal = iRegistry.RemoveByKey(aPolicyID);
       
   201     if(retVal == KErrNone)
       
   202     {
       
   203         
       
   204     }
       
   205                 
       
   206 }
       
   207 CPolicyRegistry::CPolicyRegistry():
       
   208 iRegistry(ETrue,EFalse),
       
   209 iParent(NULL)
       
   210 {
       
   211     
       
   212 }
       
   213 void CPolicyRegistry::ConstructL()
       
   214 {
       
   215 //    if(aParent != NULL)
       
   216 //     iParent = aParent;       
       
   217 }