webservices/wsstar/wsstarpolicy/src/assertion.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 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:      
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include "assertion.h"
       
    26 #include "andcompositeassertion.h"
       
    27 #include "xorcompositeassertion.h"
       
    28 #include "wspolicywriter.h"
       
    29 #include "policyreferenceassertion.h"
       
    30 #include "sendebug.h"                 // internal Utils\inc - logging MACROs
       
    31 
       
    32 CAssertion* CAssertion::NewL()
       
    33 {
       
    34     CAssertion* pSelf = CAssertion::NewLC();
       
    35     CleanupStack::Pop(pSelf);
       
    36     return pSelf;
       
    37 
       
    38 }
       
    39 CAssertion* CAssertion::NewLC()
       
    40 {
       
    41     CAssertion* pSelf = new (ELeave) CAssertion();
       
    42     CleanupStack::PushL(pSelf);
       
    43     pSelf->ConstructL();
       
    44     return pSelf;
       
    45 }
       
    46 CAssertion::~CAssertion()
       
    47 {
       
    48     if(iChildterms.Count() > 0)
       
    49         {
       
    50         for(TInt i=0; i< iChildterms.Count(); i++) 
       
    51             {
       
    52             MAssertion* assert = iChildterms[i];
       
    53             DeleteAssertion(assert);
       
    54             }
       
    55         }
       
    56     iChildterms.Reset();
       
    57 }
       
    58     
       
    59 CAssertion::CAssertion() :
       
    60 iParent(NULL),
       
    61 iNormalized(EFalse)
       
    62 {    
       
    63 }
       
    64 
       
    65 void CAssertion::ConstructL()
       
    66 {
       
    67 }
       
    68 
       
    69 void CAssertion::AddTerm(MAssertion* aAssertion)
       
    70 {
       
    71     if(aAssertion)
       
    72     {
       
    73         iChildterms.Append(aAssertion);    
       
    74     }
       
    75 }
       
    76 
       
    77 void 	CAssertion::AddTerms(RPolicyTerms& aAssertions)
       
    78 {
       
    79   for(TInt i = 0; i<aAssertions.Count(); i++ )  
       
    80   {
       
    81     MAssertion* assertion  = aAssertions[i];
       
    82     AddTerm(assertion);
       
    83   }
       
    84 }
       
    85 
       
    86 void CAssertion::AddTermCopyL(MAssertion* aAssertion)
       
    87 {
       
    88     MAssertion* eleToAdd = NULL;
       
    89     if (aAssertion->Type() == EPrimitiveType)
       
    90     {
       
    91     
       
    92 		eleToAdd = CPrimitiveAssertion::NewL((CPrimitiveAssertion*)aAssertion);
       
    93 
       
    94 	}
       
    95 	else if (aAssertion->Type() == ECompositeXorType)
       
    96 	{
       
    97 		eleToAdd = CXorCompositeAssertion::NewL((CXorCompositeAssertion*)aAssertion);
       
    98 	}
       
    99     else if (aAssertion->Type() == EPolicyReferenceType) 
       
   100     {
       
   101 	    eleToAdd = CPolicyReferenceAssertion::NewL((CPolicyReferenceAssertion*)aAssertion);
       
   102     }
       
   103 	else if (aAssertion->Type() == ECompositePolicyType)
       
   104 	{
       
   105         eleToAdd = CPolicyAssertion::NewL((CPolicyAssertion*)aAssertion);
       
   106 	
       
   107 	} 
       
   108 	else if (aAssertion->Type() == ECompositeAndType)
       
   109 	{
       
   110 		eleToAdd = CAndCompositeAssertion::NewL((CAndCompositeAssertion*)aAssertion);
       
   111 
       
   112 	} 
       
   113 	else
       
   114 	{
       
   115 	}
       
   116 	
       
   117 	
       
   118     if(eleToAdd)
       
   119     {
       
   120         iChildterms.Append(eleToAdd);    	
       
   121     }
       
   122     
       
   123 }
       
   124 void CAssertion::AddTermsCopyL(RPolicyTerms& aAssertions)
       
   125 {
       
   126   for(TInt i = 0; i<aAssertions.Count(); i++ )  
       
   127   {
       
   128     MAssertion* assertion  = aAssertions[i];
       
   129     AddTermCopyL(assertion);
       
   130   }
       
   131     
       
   132 }
       
   133 void CAssertion::MoveTermL(RPolicyTerms& /*aAssertions*/)
       
   134 {
       
   135     
       
   136 }
       
   137 void CAssertion::MoveTermsL(RPolicyTerms& aAssertions)
       
   138 {
       
   139 
       
   140   for(TInt i = 0; i<aAssertions.Count(); i++ )  
       
   141   {
       
   142     MAssertion* assertion  = aAssertions[i];
       
   143     
       
   144     if(assertion)
       
   145     {
       
   146         iChildterms.Append(assertion);
       
   147     }
       
   148         
       
   149   }
       
   150     aAssertions.Reset();
       
   151 }
       
   152 
       
   153 MAssertion* CAssertion::GetParent()
       
   154 {
       
   155     if(iParent)
       
   156         return  iParent;
       
   157     else
       
   158         return NULL;
       
   159    
       
   160 }
       
   161 RPolicyTerms& CAssertion::GetTerms()
       
   162 {
       
   163     return iChildterms;
       
   164 }
       
   165 TBool CAssertion::HasParent()
       
   166 {
       
   167     if(iParent)
       
   168         return  ETrue;
       
   169     else
       
   170         return EFalse;
       
   171 }
       
   172 MAssertion*	CAssertion::IntersectL(MAssertion* aAssertion)
       
   173 {
       
   174     return IntersectL(aAssertion, NULL);    
       
   175 }
       
   176 TBool CAssertion::IsEmpty()
       
   177 {
       
   178     if(iChildterms.Count() < 1)
       
   179         return ETrue;
       
   180     else
       
   181         return EFalse;
       
   182 }
       
   183 TBool CAssertion::IsNormalized()
       
   184 {
       
   185     return iNormalized;
       
   186 }
       
   187 MAssertion* CAssertion::MergeL(MAssertion* aAssertion)
       
   188 {
       
   189     return MergeL(aAssertion, NULL);
       
   190 }
       
   191 MAssertion* CAssertion::NormalizeL()
       
   192 {
       
   193     return NormalizeL(NULL);
       
   194 }
       
   195 TBool CAssertion::Remove(MAssertion* aAssertion)
       
   196 {
       
   197     if(Size() > 0)
       
   198     {
       
   199         TInt indx = iChildterms.Find(aAssertion);
       
   200         if(indx != KErrNotFound)
       
   201         {
       
   202             iChildterms.Remove(indx);
       
   203             return ETrue;
       
   204         }
       
   205     }
       
   206     
       
   207     return EFalse;
       
   208 }
       
   209 
       
   210 void CAssertion::SetNormalized(TBool aFlag)
       
   211 {
       
   212     iNormalized = aFlag;
       
   213     for (TInt i = 0; i < iChildterms.Count(); i++)
       
   214 	{
       
   215     	((MAssertion*)iChildterms[i])->SetNormalized(aFlag);
       
   216 	}
       
   217 }
       
   218 void CAssertion::SetParent(MAssertion* aParent)
       
   219 {
       
   220     iParent = aParent;
       
   221 }
       
   222 TInt CAssertion::Size()
       
   223 {
       
   224     return iChildterms.Count();    
       
   225 }
       
   226 
       
   227 MAssertion* CAssertion::IntersectL(MAssertion* /*aAssertion*/, CPolicyRegistry* /*aRegistry*/)
       
   228 {
       
   229     return NULL;   
       
   230 }
       
   231 MAssertion* CAssertion::MergeL(MAssertion* /*aAssertion*/, CPolicyRegistry* /*aRegistry*/)
       
   232 {
       
   233     return NULL;   
       
   234 }
       
   235 MAssertion* CAssertion::NormalizeL(CPolicyRegistry* /*aRegistry*/)
       
   236 {
       
   237     return NULL;    
       
   238 }
       
   239 
       
   240 TAssertionType CAssertion::Type()
       
   241 {
       
   242     return EInvalidType;   
       
   243 }
       
   244 TInt CAssertion::DeleteAssertion(MAssertion* aAssertion)
       
   245 {
       
   246     if(aAssertion == NULL)
       
   247         return KErrNone;
       
   248     
       
   249     
       
   250     if (dynamic_cast<CPrimitiveAssertion*>(aAssertion))
       
   251     {
       
   252 		CPrimitiveAssertion* ele = (CPrimitiveAssertion*)aAssertion;
       
   253         delete ele;
       
   254         ele = NULL;    
       
   255 	} 
       
   256 	else if (dynamic_cast<CXorCompositeAssertion*>(aAssertion))
       
   257 	{
       
   258 		CAssertion* ele = (CAssertion*)aAssertion;
       
   259         delete ele;
       
   260         ele = NULL;    
       
   261 	} 
       
   262     else if (dynamic_cast<CPolicyReferenceAssertion*>(aAssertion)) 
       
   263     {
       
   264 		CPolicyReferenceAssertion* ele = (CPolicyReferenceAssertion*)aAssertion;
       
   265         delete ele;
       
   266         ele = NULL;    
       
   267 	} 
       
   268 	else if (dynamic_cast<CPolicyAssertion*>(aAssertion))
       
   269 	{
       
   270         CPolicyAssertion* ele = (CPolicyAssertion*)aAssertion;
       
   271         delete ele;
       
   272         ele = NULL;    
       
   273 	}
       
   274 	else if (dynamic_cast<CAndCompositeAssertion*>(aAssertion))
       
   275 	{
       
   276 		CAssertion* ele = (CAssertion*)aAssertion;
       
   277         delete ele;
       
   278         ele = NULL;    
       
   279 	}
       
   280     return KErrNone;
       
   281 }
       
   282 
       
   283 // End of File