throw new IllegalArgumentException( msg );
}
int newId = messageId.incrementAndGet();
ModifyDnResponse resp = new ModifyDnResponseImpl( newId );
LdapResult result = resp.getLdapResult();
result.setResultCode( ResultCodeEnum.SUCCESS );
if ( modDnRequest.getName().isEmpty() )
{
// it is not allowed to modify the name of the Root DSE
String msg = "Modify Dn is not allowed on Root DSE.";
result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
result.setDiagnosticMessage( msg );
return resp;
}
try
{
Dn newRdn = null;
if ( modDnRequest.getNewRdn() != null )
{
newRdn = new Dn( schemaManager, modDnRequest.getNewRdn().getName() );
}
Dn oldRdn = new Dn( schemaManager, modDnRequest.getName().getRdn().getName() );
boolean rdnChanged = modDnRequest.getNewRdn() != null
&& !newRdn.getNormName().equals( oldRdn.getNormName() );
if ( rdnChanged )
{
if ( modDnRequest.getNewSuperior() != null )
{
session.moveAndRename( modDnRequest );
}
else
{
session.rename( modDnRequest );
}
}
else if ( modDnRequest.getNewSuperior() != null )
{
modDnRequest.setNewRdn( null );
session.move( modDnRequest );
}
else
{
result.setDiagnosticMessage( "Attempt to move entry onto itself." );
result.setResultCode( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
result.setMatchedDn( modDnRequest.getName() );
}
}
catch ( LdapException e )
{
LOG.warn( e.getMessage(), e );
resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
resp.getLdapResult().setDiagnosticMessage( e.getMessage() );
}
addResponseControls( modDnRequest, resp );
return resp;
}