for ( int i = 0; i < oldEntries.length; i++ )
{
dummyMonitor.reset();
IEntry oldEntry = oldEntries[i];
LdapDN oldDn = oldEntry.getDn();
LdapDN newDn = DnUtils.composeDn( oldDn.getRdn(), parentDn );
// try to move entry
RenameEntryJob.renameEntry( browserConnection, oldEntry, newDn, dummyMonitor );
// do a simulated rename, if renaming of a non-leaf entry is not supported.
if ( dummyMonitor.errorsReported() )
{
if ( dialog != null && dummyMonitor.getException() instanceof ContextNotEmptyException )
{
// open dialog
if ( numAdd == 0 )
{
dialog.setEntryInfo( browserConnection, oldDn, newDn );
dialog.open();
isSimulatedRename = dialog.isSimulateRename();
}
if ( isSimulatedRename )
{
// do simulated rename operation
dummyMonitor.reset();
numAdd = CopyEntriesJob.copyEntry( oldEntry, newParent, null, SearchControls.SUBTREE_SCOPE,
numAdd, null, dummyMonitor, monitor );
if ( !dummyMonitor.errorsReported() )
{
dummyMonitor.reset();
numDel = DeleteEntriesJob.optimisticDeleteEntryRecursive( browserConnection, oldDn,
oldEntry.isReferral(), false, numDel, dummyMonitor, monitor );
}
}
else
{
// no simulated rename operation
// report the exception to the real monitor
Exception exception = dummyMonitor.getException();
monitor.reportError( exception );
}
}
else
{
// we have another exception
// report it to the real monitor
Exception exception = dummyMonitor.getException();
monitor.reportError( exception );
}
}
// update model
if ( !dummyMonitor.errorsReported() )
{
// uncache old entry
browserConnection.uncacheEntryRecursive( oldEntry );
// remove old entry from old parent
oldEntry.getParententry().deleteChild( oldEntry );
// add new entry to new parent
boolean hasMoreChildren = newParent.hasMoreChildren() || !newParent.isChildrenInitialized();
List<StudioControl> controls = new ArrayList<StudioControl>();
if ( oldEntry.isReferral() )
{
controls.add( StudioControl.MANAGEDSAIT_CONTROL );
}
IEntry newEntry = ReadEntryRunnable.getEntry( browserConnection, newDn, controls, monitor );
newEntries[i] = newEntry;
newParent.addChild( newEntry );
newParent.setHasMoreChildren( hasMoreChildren );
// reset searches, if the moved entry is a result of a search