record.setChangeType( LdifChangeTypeLine.createModify() );
for ( ModificationItem item : modificationItems )
{
Attribute attribute = item.getAttribute();
String attributeDescription = attribute.getID();
LdifModSpec modSpec;
switch ( item.getModificationOp() )
{
case DirContext.ADD_ATTRIBUTE:
modSpec = LdifModSpec.createAdd( attributeDescription );
break;
case DirContext.REMOVE_ATTRIBUTE:
modSpec = LdifModSpec.createDelete( attributeDescription );
break;
case DirContext.REPLACE_ATTRIBUTE:
modSpec = LdifModSpec.createReplace( attributeDescription );
break;
default:
continue;
}
NamingEnumeration<?> valueEnumeration = attribute.getAll();
while ( valueEnumeration.hasMore() )
{
Object o = valueEnumeration.next();
if ( o instanceof String )
{
modSpec.addAttrVal( LdifAttrValLine.create( attributeDescription, ( String ) o ) );
}
if ( o instanceof byte[] )
{
modSpec.addAttrVal( LdifAttrValLine.create( attributeDescription, ( byte[] ) o ) );
}
}
modSpec.finish( LdifModSpecSepLine.create() );
record.addModSpec( modSpec );
}
record.finish( LdifSepLine.create() );