void FieldTraits<AttachmentMap>::copyFromBin(BinaryDataHandler &pMem,
                                             AttachmentMap     &aMap )
{
    Attachment *attPtr;
    UInt32      key;
    UInt16      binding;
    UInt32      fcId;
    UInt32      size;
        
    pMem.getValue(size);


    AttachmentMap::const_iterator mapIt  = aMap.begin();
    AttachmentMap::const_iterator mapEnd = aMap.end  ();

    for(; mapIt != mapEnd; ++mapIt)
    {
        if((*mapIt).second != NULL)
        {
            Thread::getCurrentChangeList()->addDelayedSubRef<
            UnrecordedRefCountPolicy>((*mapIt).second);
        }
    }
        
    aMap.clear();

        
    for(UInt32 i = 0; i < size; ++i)
    {
        pMem.getValue(binding);
        pMem.getValue(fcId   );
        
        attPtr = dynamic_cast<Attachment *>(
            FieldContainerFactory::the()->getMappedContainer(fcId));

        if(attPtr != NULL)
        {
            key = (static_cast<UInt32>(attPtr->getGroupId()) << 16) | binding;

            UnrecordedRefCountPolicy::addRef(attPtr);

            aMap.insert(AttachmentMap::value_type(key, attPtr));
        }
    }
}
void AttachmentContainer::copyFromBin(BinaryDataHandler &pMem, 
                                      ConstFieldMaskArg  whichField)
{
    Inherited::copyFromBin(pMem, whichField);

    if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
    {
        // _sfAttachments.copyFromBin(pMem);

        editSField(AttachmentsFieldMask);

        UInt32 size;

        pMem.getValue(size);

        AttachmentMap::const_iterator mapIt  = _sfAttachments.getValue().begin();
        AttachmentMap::const_iterator mapEnd = _sfAttachments.getValue().end  ();

        for(; mapIt != mapEnd; ++mapIt)
        {
            if((*mapIt).second != NULL)
            {
                if(this->isMTLocal())
                {
                    Thread::getCurrentChangeList()->addDelayedSubRef<
                        RecordedRefCountPolicy>((*mapIt).second);
                }
                else
                {
                    Thread::getCurrentChangeList()->addDelayedSubRef<
                        UnrecordedRefCountPolicy>((*mapIt).second);
                }
            }
        }

        _sfAttachments.getValue().clear();

        for(UInt32 i = 0; i < size; ++i)
        {
            UInt16 binding;
            UInt32 fcId;

            pMem.getValue(binding);
            pMem.getValue(fcId   );

            Attachment *att = dynamic_cast<Attachment *>(
                FieldContainerFactory::the()->getMappedContainer(fcId));

            if(att != NULL)
            {
                UInt32 key = (static_cast<UInt32>(att->getGroupId()) << 16) | binding;

                if(this->isMTLocal())
                {
                    RecordedRefCountPolicy::addRef(att);
                }
                else
                {
                    UnrecordedRefCountPolicy::addRef(att);
                }

                _sfAttachments.getValue().insert(
                    AttachmentMap::value_type(key, att));
            }
        }
    }
}