{
while ( !monitor.isCanceled() && entries.hasMore() )
{
// get next entry to copy
SearchResult sr = entries.next();
LdapDN oldLdapDn = JNDIUtils.getDn( sr );
Rdn oldRdn = oldLdapDn.getRdn();
// reuse attributes of the entry to copy
Attributes newAttributes = sr.getAttributes();
// compose new DN
Rdn newRdn = oldLdapDn.getRdn();
if ( forceNewRdn != null )
{
newRdn = forceNewRdn;
}
LdapDN newLdapDn = DnUtils.composeDn( newRdn, parentDn );
// apply new RDN to the attributes
applyNewRdn( newAttributes, oldRdn, newRdn );
// ManageDsaIT control
Control[] controls = null;
if ( newAttributes.get( SchemaConstants.OBJECT_CLASS_AT ) != null
&& newAttributes.get( SchemaConstants.OBJECT_CLASS_AT ).contains( SchemaConstants.REFERRAL_OC ) )
{
controls = new Control[]
{ new ManageReferralControl( false ) };
}
// create entry
targetBrowserConnection.getConnection().getJNDIConnectionWrapper().createEntry( newLdapDn.getUpName(),
newAttributes, controls, dummyMonitor, null );
while ( dummyMonitor.errorsReported() )
{
if ( dialog != null && dummyMonitor.getException() instanceof NameAlreadyBoundException )
{
// open dialog
dialog.setExistingEntry( targetBrowserConnection, newLdapDn );
dialog.open();
EntryExistsCopyStrategy strategy = dialog.getStrategy();
// boolean rememberSelection = dialog.isRememberSelection();
if ( strategy != null )
{
dummyMonitor.reset();
switch ( strategy )
{
case BREAK:
monitor.setCanceled( true );
break;
case IGNORE_AND_CONTINUE:
break;
case OVERWRITE_AND_CONTINUE:
// create modification items
List<ModificationItem> mis = new ArrayList<ModificationItem>();
NamingEnumeration<? extends Attribute> all = newAttributes.getAll();
while ( all.hasMore() )
{
Attribute attribute = all.next();
ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
attribute );
mis.add( mi );
}
// modify entry
targetBrowserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry(
newLdapDn.getUpName(), mis.toArray( new ModificationItem[mis.size()] ), null,
dummyMonitor, null );
// force reloading of attributes
IEntry newEntry = targetBrowserConnection.getEntryFromCache( newLdapDn );
if ( newEntry != null )
{
newEntry.setAttributesInitialized( false );
}
break;
case RENAME_AND_CONTINUE:
Rdn renamedRdn = dialog.getRdn();
// apply renamed RDN to the attributes
applyNewRdn( newAttributes, newRdn, renamedRdn );
// compose new DN
newLdapDn = DnUtils.composeDn( renamedRdn, parentDn );
// create entry
targetBrowserConnection.getConnection().getJNDIConnectionWrapper().createEntry(
newLdapDn.getUpName(), newAttributes, null, dummyMonitor, null );
break;
}
}
else