public static void apply( DirectoryService service, LdifEntry entry ) throws Exception
{
DN dn = new DN( entry.getDn() );
CoreSession session = service.getAdminSession();
switch( entry.getChangeType().getChangeType() )
{
case( ChangeType.ADD_ORDINAL ):
session.add(
new DefaultServerEntry( service.getSchemaManager(), entry.getEntry() ) );
break;
case( ChangeType.DELETE_ORDINAL ):
session.delete( dn );
break;
case( ChangeType.MODDN_ORDINAL ):
case( ChangeType.MODRDN_ORDINAL ):
RDN newRdn = new RDN( entry.getNewRdn() );
if ( entry.getNewSuperior() != null )
{
// It's a move. The superior have changed
// Let's see if it's a rename too
RDN oldRdn = dn.getRdn();
DN newSuperior = new DN( entry.getNewSuperior() );
if ( dn.size() == 0 )
{
throw new IllegalStateException( I18n.err( I18n.ERR_475 ) );
}
else if ( oldRdn.equals( newRdn ) )
{
// Same rdn : it's a move
session.move( dn, newSuperior );
}
else
{
// it's a move and rename
session.moveAndRename( dn, newSuperior, newRdn, entry.isDeleteOldRdn() );
}
}
else
{
// it's a rename
session.rename( dn, newRdn, entry.isDeleteOldRdn() );
}
break;
case( ChangeType.MODIFY_ORDINAL ):
session.modify( dn, entry.getModificationItems() );
break;
default:
throw new IllegalStateException( I18n.err( I18n.ERR_476, entry.getChangeType() ) );
}