webservices/wsdescription/src/senfacet.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-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 
       
    26 
       
    27 // INCLUDE FILES 
       
    28 #include "SenFacet.h"
       
    29 
       
    30 EXPORT_C CSenFacet* CSenFacet::NewL()
       
    31     {
       
    32     CSenFacet* pNew = new (ELeave) CSenFacet;
       
    33     CleanupStack::PushL(pNew);
       
    34     pNew->ConstructL(KSenFacet);
       
    35     CleanupStack::Pop(); // pNew
       
    36     return pNew;
       
    37     }
       
    38 
       
    39 EXPORT_C CSenFacet* CSenFacet::NewL(
       
    40     const TDesC8& aNsUri,
       
    41     const TDesC8& aLocalName,
       
    42     const TDesC8& aQName,
       
    43     const RAttributeArray& aAttributes
       
    44     )
       
    45     {
       
    46     CSenFacet* pNew = new (ELeave) CSenFacet;
       
    47     CleanupStack::PushL(pNew);
       
    48     pNew->ConstructL(aNsUri, aLocalName, aQName, aAttributes);
       
    49     CleanupStack::Pop(); // pNew
       
    50     return pNew;
       
    51     }
       
    52 
       
    53 EXPORT_C CSenFacet* CSenFacet::NewL(CSenElement& aCopiedSource)
       
    54     {
       
    55     CSenFacet* pNew = new (ELeave) CSenFacet;
       
    56     CleanupStack::PushL(pNew);
       
    57     pNew->ConstructL(aCopiedSource);
       
    58     CleanupStack::Pop(); // pNew;
       
    59     return pNew;
       
    60     }
       
    61 
       
    62 
       
    63 EXPORT_C CSenFacet::~CSenFacet()
       
    64     {
       
    65     }
       
    66 
       
    67 EXPORT_C CSenFacet::CSenFacet()
       
    68     {
       
    69     }
       
    70 
       
    71 EXPORT_C void CSenFacet::ConstructL(const TDesC8& aLocalName)
       
    72     {
       
    73     BaseConstructL(aLocalName);
       
    74     }
       
    75 
       
    76 EXPORT_C void CSenFacet::ConstructL(CSenElement& aCopiedSource)
       
    77     {
       
    78     BaseConstructL(aCopiedSource.LocalName());
       
    79     CopyFromL(aCopiedSource);
       
    80     }
       
    81 
       
    82 EXPORT_C void CSenFacet::ConstructL(const TDesC8& aNsUri,
       
    83                              const TDesC8& aLocalName,
       
    84                              const TDesC8& aQName,
       
    85                              const RAttributeArray& aAttributes)
       
    86     {
       
    87     BaseConstructL(aNsUri, aLocalName, aQName, aAttributes);
       
    88     }
       
    89 
       
    90 EXPORT_C void CSenFacet::SetNameL(const TDesC8& aName)
       
    91     {
       
    92     AddAttributeL(KFacetAttrName,aName);
       
    93     }
       
    94 
       
    95 EXPORT_C void CSenFacet::SetTypeL(const TDesC8& aType)
       
    96     {
       
    97     AddAttributeL(KFacetAttrType,aType);
       
    98     }
       
    99 
       
   100 EXPORT_C void CSenFacet::SetValueL(const TDesC8& aValue)
       
   101     {
       
   102     SetContentL(aValue);
       
   103     }
       
   104 
       
   105 EXPORT_C TPtrC8 CSenFacet::Name()
       
   106     {
       
   107     const TDesC8* pAttrValue = AttrValue(KFacetAttrName);
       
   108     if (pAttrValue) return TPtrC8(*pAttrValue);
       
   109     else return KNullDesC8();
       
   110     }
       
   111 
       
   112 EXPORT_C TPtrC8 CSenFacet::Type()
       
   113     {
       
   114     const TDesC8* pAttrValue = AttrValue(KFacetAttrType);
       
   115     if (pAttrValue) return TPtrC8(*pAttrValue);
       
   116     else return KNullDesC8();
       
   117     }
       
   118 
       
   119 EXPORT_C TPtrC8 CSenFacet::Value()
       
   120     {
       
   121     return this->Content();
       
   122     }
       
   123     
       
   124 void CSenFacet::CopyFromL(CSenElement& aSource)
       
   125     {
       
   126     TPtrC8 sourceContent = aSource.Content();
       
   127     if (sourceContent.Length() > 0)
       
   128         {
       
   129         if ( ! HasContent() )
       
   130             {
       
   131             SetContentL(sourceContent);
       
   132             }
       
   133         else
       
   134             {
       
   135             RWriteStream& ws = ContentWriteStreamL();
       
   136             ws.WriteL(sourceContent);
       
   137             }
       
   138         }
       
   139 
       
   140     RPointerArray<CSenBaseAttribute> sourceAttributes = aSource.AttributesL();
       
   141     if (sourceAttributes.Count() > 0)
       
   142         {
       
   143         for (TInt i=0;i<sourceAttributes.Count(); i++)
       
   144             {
       
   145             CSenBaseAttribute* pBaseAttribute = sourceAttributes[i];
       
   146 
       
   147             // duplicate check. Now overrides the original value
       
   148             CSenBaseAttribute* pOriginal = FindAttr(pBaseAttribute->Name());
       
   149             if (pOriginal)
       
   150                 {
       
   151                 pOriginal->SetValueL(pBaseAttribute->Value());
       
   152                 continue;
       
   153                 }
       
   154 
       
   155             CSenBaseAttribute* pNewBaseAttribute =
       
   156                 CSenBaseAttribute::NewL(pBaseAttribute->Name(),
       
   157                                         pBaseAttribute->Value());
       
   158             CleanupStack::PushL(pNewBaseAttribute);
       
   159             
       
   160             RPointerArray<CSenBaseAttribute>& attributes = AttributesL();
       
   161 #ifdef EKA2
       
   162             attributes.AppendL(pNewBaseAttribute);
       
   163 #else
       
   164             User::LeaveIfError(attributes.Append(pNewBaseAttribute));
       
   165 #endif
       
   166             CleanupStack::Pop(pNewBaseAttribute);
       
   167             }
       
   168         }
       
   169 
       
   170     RPointerArray<CSenElement> sourceElements = aSource.ElementsL();
       
   171     if (sourceElements.Count() > 0)
       
   172         {
       
   173         for (TInt i=0;i<sourceElements.Count(); i++)
       
   174             {
       
   175             CSenElement* pElement = sourceElements[i];
       
   176             CSenElement* pNewElement =
       
   177                                 CSenBaseElement::NewL(pElement->LocalName());
       
   178             pNewElement->SetParent(this);
       
   179             CleanupStack::PushL(pNewElement);
       
   180             pNewElement->CopyFromL(*pElement);
       
   181             
       
   182             RPointerArray<CSenElement>& elements = ElementsL();
       
   183 #ifdef EKA2
       
   184             elements.AppendL(pNewElement);
       
   185 #else
       
   186             User::LeaveIfError(elements.Append(pNewElement));
       
   187 #endif // EKA2
       
   188             CleanupStack::Pop(pNewElement);
       
   189             }
       
   190         }
       
   191     }
       
   192     
       
   193 // End of File