metadataengine/client/src/mdeobjectdef.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2005-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 #include "mdeobjectdef.h"
       
    19 
       
    20 #include "mdcdef.h"
       
    21 #include "mdenamespacedef.h"
       
    22 #include "mdepropertydef.h"
       
    23 #include "mdcserializationbuffer.h"
       
    24 #include "mdscommoninternal.h"
       
    25 
       
    26 
       
    27 CMdEObjectDef::CMdEObjectDef( const TMdCObjectDef& aObjectDef, CMdENamespaceDef& aNamespaceDef )
       
    28     : iObjectDef( aObjectDef ), iNamespaceDef(aNamespaceDef)
       
    29     {
       
    30     }
       
    31 
       
    32 CMdEObjectDef* CMdEObjectDef::NewL( const TMdCObjectDef& aObjectDef,
       
    33 		CMdCSerializationBuffer& aSchemaBuffer, CMdENamespaceDef& aNamespaceDef )
       
    34     {
       
    35     CMdEObjectDef* def = CMdEObjectDef::NewLC( aObjectDef, aSchemaBuffer, aNamespaceDef );
       
    36     CleanupStack::Pop( def );
       
    37     return def;
       
    38     }
       
    39 
       
    40 CMdEObjectDef* CMdEObjectDef::NewLC( const TMdCObjectDef& aObjectDef,
       
    41 		CMdCSerializationBuffer& aSchemaBuffer, CMdENamespaceDef& aNamespaceDef )
       
    42     {
       
    43     CMdEObjectDef* def = new( ELeave ) CMdEObjectDef( aObjectDef, aNamespaceDef );
       
    44     CleanupStack::PushL( def );
       
    45     def->ConstructL(aSchemaBuffer);
       
    46     return def;
       
    47     }
       
    48 
       
    49 void CMdEObjectDef::ConstructL(CMdCSerializationBuffer& aSchemaBuffer)
       
    50     {
       
    51     const TUint32 propertyCount = iObjectDef.iPropertyDefs.iPtr.iCount;
       
    52     const TUint32 propertyOffset = iObjectDef.iPropertyDefs.iPtr.iOffset;
       
    53 
       
    54 	aSchemaBuffer.PositionL( iObjectDef.iName.iPtr.iOffset );
       
    55 	iName.Set( aSchemaBuffer.ReceivePtr16L() );
       
    56 
       
    57     iPropertyDefs.ReserveL( propertyCount );
       
    58     for ( TUint32 i = 0; i < propertyCount; ++i )
       
    59         {
       
    60 		aSchemaBuffer.PositionL( propertyOffset + i * sizeof(TMdCPropertyDef) );
       
    61 		const TMdCPropertyDef& propertyDef = TMdCPropertyDef::GetFromBufferL(aSchemaBuffer);
       
    62 		iPropertyDefs.AppendL( CMdEPropertyDef::NewL( propertyDef, aSchemaBuffer, *this ) );
       
    63         }
       
    64     }
       
    65 
       
    66 CMdEObjectDef::~CMdEObjectDef()
       
    67     {
       
    68     iPropertyDefs.ResetAndDestroy();
       
    69     iPropertyDefs.Close();
       
    70     }
       
    71 
       
    72 TDefId CMdEObjectDef::Id() const
       
    73     {
       
    74     return iObjectDef.iDefId;
       
    75     }
       
    76 
       
    77 EXPORT_C CMdENamespaceDef& CMdEObjectDef::NamespaceDef() const
       
    78     {
       
    79     return iNamespaceDef;
       
    80     }
       
    81 
       
    82 EXPORT_C CMdEObjectDef* CMdEObjectDef::ParentL()
       
    83     {
       
    84     if ( iObjectDef.iParentId == KNoDefId )
       
    85         {
       
    86         return NULL;
       
    87         }
       
    88     return iNamespaceDef.GetObjectDefL( iObjectDef.iParentId );
       
    89     }
       
    90 
       
    91 EXPORT_C const TDesC& CMdEObjectDef::Name() const
       
    92     {
       
    93     return iName;
       
    94     }
       
    95 
       
    96 EXPORT_C TInt CMdEObjectDef::Compare( const CMdEObjectDef& aObjectDef ) const
       
    97     {
       
    98     TInt result = iNamespaceDef.Compare( aObjectDef.iNamespaceDef );
       
    99     if ( result == 0 )
       
   100         {
       
   101         result = iObjectDef.iDefId - aObjectDef.Id();
       
   102         }
       
   103     return result;
       
   104     }
       
   105 
       
   106 EXPORT_C TInt CMdEObjectDef::PropertyDefCount() const
       
   107     {
       
   108     return iPropertyDefs.Count();
       
   109     }
       
   110 
       
   111 EXPORT_C CMdEPropertyDef& CMdEObjectDef::PropertyDefL(TInt aIndex)
       
   112 	{
       
   113 	CMdEPropertyDef* propertyDef = PropertyDefL(aIndex, NULL);
       
   114 	if (!propertyDef)
       
   115 		{
       
   116 		User::Leave( KErrNotFound );
       
   117 		}
       
   118 	return *propertyDef;
       
   119 	}
       
   120 
       
   121 EXPORT_C CMdEPropertyDef& CMdEObjectDef::GetPropertyDefL( const TDesC& aName )
       
   122 	{
       
   123 	CMdEPropertyDef* propertyDef = GetPropertyDefL(aName, NULL);
       
   124 	if (!propertyDef)
       
   125 		{
       
   126 		User::Leave( KErrNotFound );
       
   127 		}
       
   128 	return *propertyDef;
       
   129 	}
       
   130 
       
   131 CMdEPropertyDef* CMdEObjectDef::GetPropertyDefL( const TDesC& aName, CMdEObjectDef* aChild )
       
   132     {
       
   133     const TInt propertyDefCount = iPropertyDefs.Count();
       
   134     for ( TInt i = 0; i < propertyDefCount; ++i )
       
   135         {
       
   136         if( aName.Compare( iPropertyDefs[i]->Name() ) == 0 )
       
   137         	{
       
   138         	return &PropertyDefL(i);
       
   139         	}
       
   140         }
       
   141 
       
   142     CMdEObjectDef* parent = ParentL();
       
   143     if ( parent ) 
       
   144         {
       
   145         if( !aChild )
       
   146             {
       
   147             return parent->GetPropertyDefL( aName, this );
       
   148             }
       
   149         else
       
   150             {
       
   151             return parent->GetPropertyDefL( aName, aChild );
       
   152             }
       
   153         }
       
   154     return NULL;
       
   155     }
       
   156 
       
   157 CMdEPropertyDef* CMdEObjectDef::GetPropertyDefL(TDefId aId, CMdEObjectDef* aChild)
       
   158     {
       
   159     const TInt count = iPropertyDefs.Count();
       
   160     
       
   161     for ( TInt i = 0; i < count; ++i )
       
   162         {
       
   163         CMdEPropertyDef* propDef = iPropertyDefs[i];
       
   164         
       
   165         if( propDef && propDef->Id() == aId )
       
   166         	{
       
   167         	return propDef;
       
   168         	}
       
   169         }
       
   170 
       
   171     CMdEObjectDef* parent = ParentL();
       
   172     if ( parent ) 
       
   173         {
       
   174         if ( !aChild )
       
   175             {                
       
   176             return parent->GetPropertyDefL( aId, this );
       
   177             }
       
   178         else
       
   179             {
       
   180             return parent->GetPropertyDefL( aId, aChild );
       
   181             }
       
   182         }
       
   183     return NULL;
       
   184     }
       
   185 
       
   186 CMdEPropertyDef* CMdEObjectDef::PropertyDefL(TInt aIndex, CMdEObjectDef* /*aChild*/)
       
   187 	{
       
   188 	if ( aIndex < 0 || aIndex > iPropertyDefs.Count())
       
   189 	    {
       
   190 	    User::Leave( KErrArgument );
       
   191 	    }
       
   192 
       
   193 	return iPropertyDefs[aIndex];
       
   194 	}