// ---------------------------------------------------------
// CNSmlDsProvisioningAdapter::StoreAttributesL
// ---------------------------------------------------------
void CNSmlDsProvisioningAdapter::StoreAttributesL( const TDesC& aType )
    {
    _DBG_FILE("CNSmlDsProvisioningAdapter::StoreAttributesL(): begin");
    
    TInt iDataProvElementCount = iProfiles[iProfiles.Count()-1]->iDataProvElement.Count()-1;
	// Leave if aType cannot be assigned
    if( ( aType.Length() > 0 ) &&
        ( iProfiles[iProfiles.Count()-1]->iDataProvElement[iDataProvElementCount]->iRemoteDBUri ) )
        {
        TBool dataProvIdFoundInZ = FALSE;
        TSmlDataProviderId firstDataProvIdFound = 0;
        TSmlDataProviderId uidFound = 0;

        TBool doSearch = ETrue;
        if ( aType.FindF( KXVcardMimeType ) != KErrNotFound )
            {
            if ( IsOperatorProfile( *iProfiles[iProfiles.Count()-1] ) )
                {
                const CNSmlDsProfileElement& profile = *iProfiles[iProfiles.Count()-1];
                StoreOperatorUrlL( *profile.iHostAddress );
                
                // Do not make a search through adapter implementations
                doSearch = EFalse;
                uidFound = OperatorAdapterUid();
                if ( !uidFound )
                    {
                    // If OperatorAdapterUid returns 0, do a search
                    doSearch = ETrue;
                    }
                }
            }
		// look through every implementation adapter until one found
		// which supports MIME type in question
		
		// The first one located in ROM is chosen. If none found in ROM then
		// the first adapter found is chosen.

		HBufC8 *type = HBufC8::NewLC(aType.Size());
		TPtr8 typePtr = type->Des();
		CnvUtfConverter::ConvertFromUnicodeToUtf8( typePtr, aType);

		// get list of dataproviderIds
		RImplInfoPtrArray implArray;
		CleanupStack::PushL( PtrArrCleanupItemRArr( CImplementationInformation, &implArray ) );
		TUid ifUid = { KNSmlDSInterfaceUid };
		REComSession::ListImplementationsL( ifUid, implArray );
		
        if ( doSearch )
            {
            TInt countProviders = implArray.Count();
            for( TInt i = 0; i < countProviders; i++ )
                {
                CImplementationInformation* implInfo = implArray[i];

                RSyncMLDataProvider dataProvider;
                dataProvider.OpenL( iSession, implInfo->ImplementationUid().iUid );
                CleanupClosePushL( dataProvider );

                TInt mimeTypeCount = dataProvider.MimeTypeCount();
                for( TInt j = 0; j < mimeTypeCount; j++ )
                    {
                    HBufC* mimeType = dataProvider.MimeType( j ).AllocLC();
                    TPtrC8 convMimeType = ConvertTo8LC( *mimeType );
                    if( typePtr.Find( convMimeType ) == 0)
                        {
                        // MIME type in question was found
                        uidFound = implInfo->ImplementationUid().iUid;

                        if( firstDataProvIdFound == 0 )
                            {
                            // save the first in case of none found from ROM
                            firstDataProvIdFound = uidFound;
                            }
					
                        // check whether the provider is located in ROM (drive Z)
                        if( implInfo->Drive() == EDriveZ )
                            {
                            dataProvIdFoundInZ = TRUE;
                            }
                        }
				
                    CleanupStack::PopAndDestroy(2); // mimetype, ConvertTo8LC

                    if( uidFound )
                        {
                        break;
                        }
                    }
				
                CleanupStack::PopAndDestroy(); // dataProvider
			
                if ( dataProvIdFoundInZ )
                    {
                    break;
                    }
                else
                    {
                    uidFound = firstDataProvIdFound;
                    }
                }
            }
        
		REComSession::FinalClose();
		CleanupStack::PopAndDestroy( 2 ); // type, implArray

		if( uidFound )
			{
			iProfiles[iProfiles.Count()-1]->iDataProvElement[iDataProvElementCount]->iUid = uidFound;
			}		
        }
	
	_DBG_FILE("CNSmlDsProvisioningAdapter::StoreAttributesL(): end");
	}