metadataengine/server/src/mdsnamespacedef.cpp
changeset 0 c53acadfccc6
child 15 3cebc1a84278
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:  Class to hold description about one namespace and every object
       
    15 *                it holds.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "mdsnamespacedef.h"
       
    20 
       
    21 #include "mdcdef.h"
       
    22 #include "mdsobjectdef.h"
       
    23 #include "mdsrelationdef.h"
       
    24 #include "mdseventdef.h"
       
    25 #include "mdssqliteconnection.h"
       
    26 #include "mdsdbconnectionpool.h"
       
    27 #include "mdcserializationbuffer.h"
       
    28 #include "mdsschema.h"
       
    29 #include "mdsindexer.h"
       
    30 #include "mdeinternalerror.h"
       
    31 
       
    32 #include <uriutils.h>
       
    33 
       
    34 /**
       
    35  * NewLC
       
    36  */
       
    37 CMdsNamespaceDef* CMdsNamespaceDef::NewLC( TDefId aId,
       
    38     const TDesC& aName, TBool aReadOnly, TUint32 aVendorId )
       
    39 	{
       
    40 	CMdsNamespaceDef* ret = new( ELeave ) CMdsNamespaceDef( aId, aReadOnly, aVendorId );
       
    41 	CleanupStack::PushL( ret );
       
    42 	ret->ConstructL( aName );
       
    43 	return ret;
       
    44 	}
       
    45 	
       
    46 /**
       
    47  * NewL
       
    48  */
       
    49 CMdsNamespaceDef* CMdsNamespaceDef::NewL( TDefId aId, const TDesC& aName,
       
    50     TBool aReadOnly, TUint32 aVendorId )
       
    51 	{
       
    52 	CMdsNamespaceDef* ret = CMdsNamespaceDef::NewLC( aId, aName, aReadOnly, aVendorId );
       
    53 	CleanupStack::Pop( ret );
       
    54 	return ret;
       
    55 	}
       
    56 
       
    57 /**
       
    58  * ConstructL
       
    59  */
       
    60 void CMdsNamespaceDef::ConstructL( const TDesC& aName )
       
    61 	{
       
    62 	// validate the URI of namespace
       
    63 	TBool invalidChars = UriUtils::HasInvalidChars( aName );
       
    64 	if( invalidChars )
       
    65 		{
       
    66 		User::Leave( KErrGeneral );
       
    67 		}
       
    68 
       
    69 	CMdsItemDef::ConstructL( aName );
       
    70 	}
       
    71 
       
    72 /**
       
    73  * Destructor
       
    74  */
       
    75 CMdsNamespaceDef::~CMdsNamespaceDef()
       
    76 	{
       
    77 	// deleting objects
       
    78 	iObjectDefs.ResetAndDestroy();
       
    79 	iObjectDefs.Close();
       
    80 
       
    81 	// deleting relations...
       
    82 	iRelationDefs.ResetAndDestroy();
       
    83    	iRelationDefs.Close();
       
    84 
       
    85    	// deleting events...
       
    86     iEventDefs.ResetAndDestroy();
       
    87    	iEventDefs.Close();
       
    88 	}
       
    89 	
       
    90 /**
       
    91  * AddObjectDefL
       
    92  */
       
    93 CMdsObjectDef* CMdsNamespaceDef::AddObjectDefL( const TDesC& aObjectName, const TDesC& aParentName,
       
    94                                                 CMdsSchema* aDefaultSchema )
       
    95 	{
       
    96 	if ( GetObjectDef( aObjectName ) )
       
    97 		{
       
    98 		// duplicate object
       
    99 		User::Leave( KErrAlreadyExists );
       
   100 		}
       
   101 	CMdsObjectDef* parent = GetObjectDef( aParentName );
       
   102 	if ( !parent )
       
   103 		{
       
   104 		/* testing */
       
   105 		// found namespace in default schema
       
   106 		if ( aDefaultSchema )
       
   107 			{
       
   108 			CMdsNamespaceDef* namespaceDef = aDefaultSchema->GetNamespace( GetName() );
       
   109 			if ( !namespaceDef )
       
   110 				{
       
   111 				User::Leave( KErrMdEUnknownNamespaceDef );
       
   112 				}
       
   113 			parent = namespaceDef->GetObjectDef( aParentName );
       
   114 			}
       
   115 		if( !parent )
       
   116 			{
       
   117 			User::Leave( KErrNotFound );
       
   118 			}
       
   119 		}
       
   120 	CMdsObjectDef* object = CMdsObjectDef::NewLC( aObjectName, parent );
       
   121 	iObjectDefs.AppendL( object );
       
   122 	CleanupStack::Pop( object );
       
   123 	return object;
       
   124 	}
       
   125 
       
   126 /**
       
   127  * AddObjectDefL (private - add from DB)
       
   128  */
       
   129 void CMdsNamespaceDef::AddObjectDefL( TDefId aId, TDefId aParentId, TInt aFlags, const TDesC& aName )
       
   130 	{
       
   131 	const CMdsObjectDef* parent = GetObjectByIdL( aParentId );
       
   132 	if ( !parent )
       
   133 		{
       
   134 		User::Leave( KErrNotFound );
       
   135 		}
       
   136 	CMdsObjectDef* object = CMdsObjectDef::NewLC( aName, parent );
       
   137 	object->SetFlags( (CMdsObjectDef::TObjectDefFlags)aFlags );
       
   138 	iObjectDefs.AppendL( object );
       
   139 	object->SetId(aId);
       
   140 	object->SetStoredInDB();
       
   141 	CleanupStack::Pop( object );
       
   142 	}
       
   143 
       
   144 /**
       
   145  * FindObjectDefParent
       
   146  */
       
   147 CMdsObjectDef* CMdsNamespaceDef::GetObjectDef( const TDesC& aObjectName ) const
       
   148 	{
       
   149 	if ( iBaseObject->GetName().Compare( aObjectName ) == 0 )
       
   150 		{
       
   151 		return iBaseObject;
       
   152 		}
       
   153 
       
   154 	const TInt count = iObjectDefs.Count();
       
   155 	
       
   156 	for ( TInt i = 0; i < count; ++i )
       
   157 		{
       
   158 		if( iObjectDefs[i]->GetName().Compare( aObjectName ) == 0 )
       
   159 			{
       
   160 			return iObjectDefs[i];
       
   161 			}
       
   162 		}
       
   163 	return NULL;
       
   164 	}
       
   165 
       
   166 void CMdsNamespaceDef::AddRelationDefL( const TDesC& aRelationName )
       
   167 	{
       
   168 	if ( GetRelationDef( aRelationName ) )
       
   169 		{
       
   170 		User::Leave( KErrAlreadyExists );
       
   171 		}
       
   172 	CMdsRelationDef* relation = CMdsRelationDef::NewLC( aRelationName );
       
   173 	iRelationDefs.AppendL( relation );
       
   174 	CleanupStack::Pop( relation );
       
   175 	}
       
   176 
       
   177 
       
   178 void CMdsNamespaceDef::AddRelationDefL( TDefId aId, const TDesC& aRelationName )
       
   179 	{
       
   180 	CMdsRelationDef* relation = CMdsRelationDef::NewLC( aRelationName );
       
   181 	relation->SetId(aId);
       
   182 	iRelationDefs.AppendL( relation );
       
   183 	relation->SetStoredInDB();
       
   184 	CleanupStack::Pop( relation );
       
   185 	}
       
   186 
       
   187 
       
   188 CMdsRelationDef* CMdsNamespaceDef::GetRelationDef( const TDesC& aRelationName ) const
       
   189 	{
       
   190 	const TInt count = iRelationDefs.Count();
       
   191 	
       
   192 	for ( TInt i = 0; i < count; ++i )
       
   193 		{
       
   194 		if ( iRelationDefs[i]->GetName().Compare( aRelationName ) == 0 )
       
   195 			{
       
   196 			return iRelationDefs[i];
       
   197 			}
       
   198 		}
       
   199 	return NULL;
       
   200 	}
       
   201 
       
   202 void CMdsNamespaceDef::AddEventDefL( const TDesC& aEventName, TInt32 aPriority )
       
   203 	{
       
   204 	if ( GetEventDef( aEventName ) )
       
   205 		{
       
   206 		User::Leave( KErrAlreadyExists );
       
   207 		}
       
   208 	CMdsEventDef* event = CMdsEventDef::NewLC( aEventName, aPriority );
       
   209 	iEventDefs.AppendL( event );
       
   210 	CleanupStack::Pop( event );
       
   211 	}
       
   212 
       
   213 void CMdsNamespaceDef::AddEventDefL( TDefId aId, const TDesC& aEventName, TInt32 aPriority )
       
   214 	{
       
   215 	CMdsEventDef* event = CMdsEventDef::NewLC( aEventName, aPriority );
       
   216 	event->SetId(aId);
       
   217 	iEventDefs.AppendL( event );
       
   218 	event->SetStoredInDB();
       
   219 	CleanupStack::Pop( event );
       
   220 	}
       
   221 
       
   222 CMdsEventDef* CMdsNamespaceDef::GetEventDef( const TDesC& aEventName ) const
       
   223 	{
       
   224 	const TInt count = iEventDefs.Count();
       
   225 	
       
   226 	for ( TInt i = 0; i < count; ++i )
       
   227 		{
       
   228 		if ( iEventDefs[i]->GetName().Compare( aEventName ) == 0 )
       
   229 			{
       
   230 			return iEventDefs[i];
       
   231 			}
       
   232 		}
       
   233 	return NULL;
       
   234 	}
       
   235 
       
   236 const CMdsObjectDef* CMdsNamespaceDef::GetObjectByIdL( TDefId aId ) const
       
   237 	{
       
   238 	if ( aId == KBaseObjectDefId ) // BaseObject (hardcoded)
       
   239 		{
       
   240 		return iBaseObject;
       
   241 		}
       
   242 	
       
   243 	const TInt count = iObjectDefs.Count();
       
   244 	
       
   245 	for ( TInt i = 0; i < count; ++i )
       
   246 		{
       
   247 		if( iObjectDefs[i]->GetId() == aId )
       
   248 			{
       
   249 			return iObjectDefs[i];
       
   250 			}
       
   251 		}
       
   252 	return NULL;
       
   253 	}
       
   254 
       
   255 const CMdsEventDef* CMdsNamespaceDef::GetEventByIdL( TDefId aId ) const
       
   256 	{
       
   257 	const TInt count = iEventDefs.Count();
       
   258 	
       
   259 	for ( TInt i = 0; i < count; ++i )
       
   260 		{
       
   261 		if( iEventDefs[i]->GetId() == aId )
       
   262 			{
       
   263 			return iEventDefs[i];
       
   264 			}
       
   265 		}
       
   266 	return NULL;
       
   267 	}
       
   268 
       
   269 const CMdsRelationDef* CMdsNamespaceDef::GetRelationByIdL( TDefId aId ) const
       
   270 	{
       
   271 	const TInt count = iRelationDefs.Count();
       
   272 	
       
   273 	for ( TInt i = 0; i < count; ++i )
       
   274 		{
       
   275 		if( iRelationDefs[i]->GetId() == aId )
       
   276 			{
       
   277 			return iRelationDefs[i];
       
   278 			}
       
   279 		}
       
   280 	return NULL;
       
   281 	}
       
   282 
       
   283 void CMdsNamespaceDef::StoreToDBL( TBool aStoreOnlyNamespace )
       
   284 	{
       
   285 	_LIT( KMdsSqlClauseAddNamespaceDef, "INSERT INTO NamespaceDef(ReadOnly,VendorId,Name) Values(?,?,?);" );
       
   286     RRowData rowData;
       
   287     CleanupClosePushL( rowData );
       
   288 
       
   289 	if ( !GetStoredInDB() )
       
   290 		{
       
   291 		rowData.AppendL( TColumn( GetReadOnly() ) );
       
   292 		rowData.AppendL( TColumn( iVendorId ) );
       
   293 		rowData.AppendL( TColumn( GetName().AllocL() ) );
       
   294 
       
   295 		TDefId id = KNoDefId;
       
   296 		id = MMdSIndexer::ExecuteAndGetIndexL(KMdsSqlClauseAddNamespaceDef,rowData);
       
   297 		SetId( id );
       
   298 
       
   299 		SetStoredInDB();
       
   300 		}
       
   301 	
       
   302 	if (aStoreOnlyNamespace)
       
   303 		{
       
   304 		CleanupStack::PopAndDestroy( &rowData );
       
   305 		return;
       
   306 		}
       
   307 	
       
   308 	const TInt objectDefCount = iObjectDefs.Count();
       
   309 	
       
   310 	// add objectDef to DB
       
   311 	for( TInt i = 0; i < objectDefCount; ++i )
       
   312 		{
       
   313 		iObjectDefs[i]->StoreToDBL( GetId() );
       
   314 		}
       
   315 	
       
   316 	const TInt eventDefCount = iEventDefs.Count();
       
   317 	
       
   318 	// add relationDef to DB
       
   319 	for( TInt i = 0; i < eventDefCount; ++i )
       
   320 		{
       
   321 		iEventDefs[i]->StoreToDBL( GetId() );
       
   322 		}
       
   323 	
       
   324 	const TInt relationDefCount = iRelationDefs.Count();
       
   325 	
       
   326 	// add eventDef to DB
       
   327 	for( TInt i = 0; i < relationDefCount; ++i )
       
   328 		{
       
   329 		iRelationDefs[i]->StoreToDBL( GetId() );
       
   330 		}
       
   331 
       
   332 	CleanupStack::PopAndDestroy( &rowData );
       
   333 	}
       
   334 	
       
   335 
       
   336 void CMdsNamespaceDef::MergeObjectsL( CMdsNamespaceDef* aNamespace, const TBool& aDryRun )
       
   337 	{
       
   338 	const TInt count = aNamespace->iObjectDefs.Count();	
       
   339 	
       
   340 	for ( TInt i = 0; i < count; ++i )
       
   341 		{
       
   342 		CMdsObjectDef* lObjectDef = GetObjectDef( aNamespace->iObjectDefs[i]->GetName() );
       
   343 		if( lObjectDef )
       
   344 			{
       
   345 			lObjectDef->MergeL( aNamespace->iObjectDefs[i], aDryRun );
       
   346 			}
       
   347 		else if ( !aDryRun )
       
   348 			{
       
   349 			iObjectDefs.AppendL( aNamespace->iObjectDefs[i] );
       
   350 			aNamespace->iObjectDefs[i]->SetAllNotStoredInDB();
       
   351 			aNamespace->iObjectDefs[i] = NULL;
       
   352 			}
       
   353 		}
       
   354 	}
       
   355 	
       
   356 void CMdsNamespaceDef::MergeRelationsL( CMdsNamespaceDef* aNamespace, const TBool& aDryRun )
       
   357 	{
       
   358 	const TInt count = aNamespace->iRelationDefs.Count();	
       
   359 	
       
   360 	for ( TInt i = 0; i < count; ++i )
       
   361 		{
       
   362 		CMdsRelationDef* relation = GetRelationDef( aNamespace->iRelationDefs[i]->GetName() );
       
   363 		if ( relation )
       
   364 			{
       
   365 			if ( *aNamespace->iRelationDefs[i] != *relation )
       
   366 				{
       
   367 				User::Leave( KErrAlreadyExists );
       
   368 				}
       
   369 			}
       
   370 		else if ( !aDryRun )
       
   371 			{
       
   372 			iRelationDefs.AppendL( aNamespace->iRelationDefs[i] );
       
   373 			aNamespace->iRelationDefs[i]->SetAllNotStoredInDB();
       
   374 			aNamespace->iRelationDefs[i] = NULL;
       
   375 			}
       
   376 		}
       
   377 	}
       
   378 	
       
   379 void CMdsNamespaceDef::MergeEventsL( CMdsNamespaceDef* aNamespace, const TBool& aDryRun )
       
   380 	{
       
   381 	const TInt count = aNamespace->iEventDefs.Count();
       
   382 	
       
   383 	for ( TInt i = 0; i < count; ++i )
       
   384 		{
       
   385 		CMdsEventDef* event = GetEventDef( aNamespace->iEventDefs[i]->GetName() );
       
   386 		if ( event )
       
   387 			{
       
   388 			if ( *aNamespace->iEventDefs[i] != *event )
       
   389 				{
       
   390 				User::Leave( KErrAlreadyExists );
       
   391 				}
       
   392 			}
       
   393 		else if ( !aDryRun )
       
   394 			{
       
   395 			iEventDefs.AppendL( aNamespace->iEventDefs[i] );
       
   396 			aNamespace->iEventDefs[i]->SetAllNotStoredInDB();
       
   397 			aNamespace->iEventDefs[i] = NULL;
       
   398 			}
       
   399 		}
       
   400 	}
       
   401 
       
   402 void CMdsNamespaceDef::ImportFromDBL()
       
   403 	{
       
   404 	_LIT( KMdsQueryGetObjectDefs, "SELECT ObjectDefId,ParentDefId,Flags,Name FROM ObjectDef WHERE NamespaceDefId=?;" );
       
   405 	_LIT( KMdsQueryGetRelationDefs, "SELECT RelationDefId,Name FROM RelationDef WHERE NamespaceDefId=?;" );
       
   406 	_LIT( KMdsQueryGetEventDefs, "SELECT EventDefId,Priority,Name FROM EventDef WHERE NamespaceDefId=?;" );
       
   407 	TDefId eId = KNoDefId;
       
   408 	TInt32 objectParent = 0;
       
   409 	TInt32 flags = 0;
       
   410 	TPtrC name;
       
   411 
       
   412 	// importing namespaces
       
   413 	RRowData namespaceNumber;
       
   414 	CleanupClosePushL( namespaceNumber );
       
   415 	namespaceNumber.AppendL( TColumn( GetId() ) );
       
   416 	RRowData getData;
       
   417 	CleanupClosePushL( getData );
       
   418 
       
   419 	CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
       
   420 
       
   421 	// OBJECTS
       
   422 	RMdsStatement queryObject;
       
   423 	CleanupClosePushL( queryObject );
       
   424 	getData.AppendL( TColumn( eId ) );
       
   425 	getData.AppendL( TColumn( objectParent ) );
       
   426 	getData.AppendL( TColumn( flags ) );
       
   427 	getData.AppendL( TColumn( EColumnHBuf16 ) );
       
   428 	connection.ExecuteQueryL( KMdsQueryGetObjectDefs, queryObject, namespaceNumber );
       
   429 	while( connection.NextRowL( queryObject, getData ) )
       
   430 		{
       
   431 		getData.Column( 0 ).Get( eId );
       
   432 		getData.Column( 1 ).Get( objectParent );
       
   433 		getData.Column( 2 ).Get( flags );
       
   434 		getData.Column( 3 ).Get( name );
       
   435 		AddObjectDefL( eId, objectParent, flags, name );
       
   436 		getData.Column( 3 ).Free( );
       
   437 		}
       
   438 	CleanupStack::PopAndDestroy( &queryObject );
       
   439 	getData.Reset();
       
   440 	
       
   441 	// RELATIONS
       
   442 	RMdsStatement queryRelation;
       
   443 	CleanupClosePushL( queryRelation );
       
   444 	getData.AppendL( TColumn( eId ) );
       
   445 	getData.AppendL( TColumn( EColumnHBuf16 ) );
       
   446 	connection.ExecuteQueryL( KMdsQueryGetRelationDefs, queryRelation, namespaceNumber );
       
   447 	while( connection.NextRowL( queryRelation, getData ) )
       
   448 		{
       
   449 		getData.Column( 0 ).Get( eId );
       
   450 		getData.Column( 1 ).Get( name );
       
   451 		AddRelationDefL( eId, name );
       
   452 		getData.Column( 1 ).Free( );
       
   453 		}
       
   454 	CleanupStack::PopAndDestroy( &queryRelation );
       
   455 	getData.Reset();
       
   456 	
       
   457 	// EVENTS
       
   458 	TInt32 priority = 0;
       
   459 	RMdsStatement queryEvent;
       
   460 	CleanupClosePushL( queryEvent );
       
   461 	getData.AppendL( TColumn( eId ) );
       
   462 	getData.AppendL( TColumn( priority ) );
       
   463 	getData.AppendL( TColumn( EColumnHBuf16 ) );
       
   464 	connection.ExecuteQueryL( KMdsQueryGetEventDefs, queryEvent, namespaceNumber );
       
   465 	while( connection.NextRowL( queryEvent, getData ) )
       
   466 		{
       
   467 		getData.Column( 0 ).Get( eId );
       
   468 		getData.Column( 1 ).Get( priority );
       
   469 		getData.Column( 2 ).Get( name );
       
   470 		AddEventDefL( eId, name, priority );
       
   471 		getData.Column( 2 ).Free( );
       
   472 		}
       
   473 	CleanupStack::PopAndDestroy( &queryEvent );
       
   474 
       
   475 	CleanupStack::PopAndDestroy( 2, &namespaceNumber ); // getData, namespaceNumber
       
   476 	
       
   477 	const TInt count = iObjectDefs.Count();
       
   478 	
       
   479 	for ( TInt i = 0; i < count; ++i )
       
   480 		{
       
   481 		iObjectDefs[i]->ImportFromDBL();
       
   482 		}
       
   483 
       
   484 	// everything is ok, so set the flags
       
   485 	SetStoredInDB();
       
   486 	SetTableStoredInDB();
       
   487 	}
       
   488 	
       
   489 TUint32 CMdsNamespaceDef::RequiredBufferSize()
       
   490 	{
       
   491 	TUint32 bufferSize = sizeof(TMdCNamespaceDef) + CMdsItemDef::RequiredBufferSize();
       
   492 
       
   493 	const TInt objectDefsCount = iObjectDefs.Count();
       
   494 	bufferSize += (objectDefsCount + 1) * sizeof( TMdCObjectDef);
       
   495 	// base object def
       
   496 	bufferSize += iBaseObject->RequiredBufferSize();
       
   497 
       
   498 	// objectdefs
       
   499 	for ( TInt i = 0; i < objectDefsCount; ++i )
       
   500 		{
       
   501 		bufferSize += iObjectDefs[i]->RequiredBufferSize();
       
   502 		}
       
   503 
       
   504 	// eventdefs
       
   505 	const TInt eventDefsCount = iEventDefs.Count();
       
   506 	bufferSize += eventDefsCount * sizeof( TMdCEventDef );
       
   507 	for ( TInt i = 0; i < iEventDefs.Count(); ++i )
       
   508 		{
       
   509 		bufferSize += iEventDefs[i]->RequiredBufferSize();
       
   510 		}
       
   511 
       
   512 	// relationdefs
       
   513 	const TInt relationDefsCount = iRelationDefs.Count();
       
   514 	bufferSize += relationDefsCount * sizeof( TMdCRelationDef);
       
   515 	for ( TInt i = 0; i < iRelationDefs.Count(); ++i )
       
   516 		{
       
   517 		bufferSize += iRelationDefs[i]->RequiredBufferSize();
       
   518 		}
       
   519 
       
   520 	return bufferSize;
       
   521 	}
       
   522 
       
   523 TMdCOffset CMdsNamespaceDef::SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreeSpace)
       
   524 	{
       
   525 	const TMdCOffset namespaceDefOffset = aBuffer.Position();
       
   526 	TMdCNamespaceDef namespaceDef;
       
   527 	// get const data and store Name
       
   528 	namespaceDef.iDefId = GetId();
       
   529 	namespaceDef.iReadOnly = GetReadOnly();
       
   530 	namespaceDef.iName.iPtr.iCount = GetName().Length();
       
   531 	namespaceDef.iName.iPtr.iOffset = aFreeSpace;
       
   532 	aBuffer.PositionL( aFreeSpace );
       
   533 	aFreeSpace = CMdsItemDef::SerializeL( aBuffer );
       
   534 
       
   535 	// calculate necessary stuff for objectDefs
       
   536 	const TInt objectDefsCount = iObjectDefs.Count(); 
       
   537 	namespaceDef.iObjectDefs.iPtr.iCount = objectDefsCount + 1; // one extra for base object def
       
   538 	namespaceDef.iObjectDefs.iPtr.iOffset = aFreeSpace;
       
   539 
       
   540 	// create space for objectDefs
       
   541 	aFreeSpace += (objectDefsCount + 1) * sizeof(TMdCObjectDef);
       
   542 	
       
   543 	aBuffer.PositionL( namespaceDef.iObjectDefs.iPtr.iOffset ); // one extra for base object def
       
   544 	aFreeSpace = iBaseObject->SerializeL( aBuffer, aFreeSpace );
       
   545 
       
   546 	for ( TInt i = 0; i < objectDefsCount; ++i )
       
   547 		{
       
   548 		aBuffer.PositionL( namespaceDef.iObjectDefs.iPtr.iOffset
       
   549 				+ (i+1) * sizeof(TMdCObjectDef) ); // one extra for base object def
       
   550 		// write object
       
   551 		aFreeSpace = iObjectDefs[i]->SerializeL( aBuffer, aFreeSpace );
       
   552 		}
       
   553 
       
   554 	// calculate necessary stuff for eventDefs
       
   555 	const TInt eventDefsCount = iEventDefs.Count();
       
   556 	namespaceDef.iEventDefs.iPtr.iCount = eventDefsCount;
       
   557 	namespaceDef.iEventDefs.iPtr.iOffset = aFreeSpace;
       
   558 
       
   559 	// create space for eventDefs
       
   560 	aFreeSpace += eventDefsCount * sizeof(TMdCEventDef);
       
   561 
       
   562 	for ( TInt i = 0; i < eventDefsCount; ++i )
       
   563 		{
       
   564 		aBuffer.PositionL( namespaceDef.iEventDefs.iPtr.iOffset + i * sizeof(TMdCEventDef) );
       
   565 		// write event
       
   566 		aFreeSpace = iEventDefs[i]->SerializeL( aBuffer, aFreeSpace );
       
   567 		}
       
   568 
       
   569 	// calculate necessary stuff for relationDefs
       
   570 	const TInt relationDefsCount = iRelationDefs.Count();
       
   571 	namespaceDef.iRelationDefs.iPtr.iCount = relationDefsCount;
       
   572 	namespaceDef.iRelationDefs.iPtr.iOffset = aFreeSpace;
       
   573 
       
   574 	// create space for eventDefs
       
   575 	aFreeSpace += relationDefsCount * sizeof(TMdCRelationDef);
       
   576 
       
   577 	for ( TInt i = 0; i < relationDefsCount; ++i )
       
   578 		{
       
   579 		aBuffer.PositionL( namespaceDef.iRelationDefs.iPtr.iOffset + i * sizeof(TMdCRelationDef) );
       
   580 		// write relation
       
   581 		aFreeSpace = iRelationDefs[i]->SerializeL( aBuffer, aFreeSpace );
       
   582 		}
       
   583 	
       
   584 	// store namespaceDef itself
       
   585 	aBuffer.PositionL( namespaceDefOffset );
       
   586 	namespaceDef.SerializeL( aBuffer );
       
   587 
       
   588 	return aFreeSpace;
       
   589 	}
       
   590 	
       
   591 
       
   592 const CMdsPropertyDef* CMdsNamespaceDef::GetPropertyL( TDefId aId ) const
       
   593 	{
       
   594 	const CMdsPropertyDef* propertyDef = iBaseObject->GetPropertyByIdL( aId );
       
   595 
       
   596 	if ( propertyDef )
       
   597 		{
       
   598 		return propertyDef;
       
   599 		}
       
   600 
       
   601 	const TInt count = iObjectDefs.Count();
       
   602 	
       
   603 	for ( TInt i = 0; i < count; ++i )
       
   604 		{
       
   605 		const CMdsPropertyDef* objectPropertyDef = iObjectDefs[i]->GetPropertyByIdL( aId );
       
   606 		if ( objectPropertyDef )
       
   607 			{
       
   608 			return objectPropertyDef;
       
   609 			}
       
   610 		}
       
   611 
       
   612 	return NULL;
       
   613 	}
       
   614 
       
   615 /**
       
   616  * Initialize static variables
       
   617  */
       
   618 
       
   619 CMdsObjectDef* CMdsNamespaceDef::iBaseObject = NULL;