int errorCount = 0;
try
{
while ( !monitor.isCanceled() && enumeration.hasNext() )
{
LdifContainer container = enumeration.next();
if ( container instanceof LdifRecord )
{
LdifRecord record = ( LdifRecord ) container;
try
{
dummyMonitor.reset();
importLdifRecord( browserConnection, record, dummyMonitor );
if ( dummyMonitor.errorsReported() )
{
errorCount++;
logModificationError( browserConnection, logWriter, record, dummyMonitor.getException(),
monitor );
if ( !continueOnError )
{
monitor.reportError( dummyMonitor.getException() );
return;
}
}
else
{
importedCount++;
logModification( browserConnection, logWriter, record, monitor );
// update cache and adjust attribute/children initialization flags
LdapDN dn = new LdapDN( record.getDnLine().getValueAsString() );
IEntry entry = browserConnection.getEntryFromCache( dn );
LdapDN parentDn = DnUtils.getParent( dn );
IEntry parentEntry = parentDn != null ? browserConnection.getEntryFromCache( parentDn )
: null;
if ( record instanceof LdifChangeDeleteRecord )
{
if ( entry != null )
{
entry.setAttributesInitialized( false );
browserConnection.uncacheEntryRecursive( entry );
}
if ( parentEntry != null )
{
parentEntry.setChildrenInitialized( false );
}
}
else if ( record instanceof LdifChangeModDnRecord )
{
if ( entry != null )
{
entry.setAttributesInitialized( false );
browserConnection.uncacheEntryRecursive( entry );
}
if ( parentEntry != null )
{
parentEntry.setChildrenInitialized( false );
}
LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
if ( modDnRecord.getNewsuperiorLine() != null )
{
LdapDN newSuperiorDn = new LdapDN( modDnRecord.getNewsuperiorLine()
.getValueAsString() );
IEntry newSuperiorEntry = browserConnection.getEntryFromCache( newSuperiorDn );
if ( newSuperiorEntry != null )
{
newSuperiorEntry.setChildrenInitialized( false );
}
}
}
else if ( record instanceof LdifChangeAddRecord || record instanceof LdifContentRecord )
{
if ( parentEntry != null )
{
parentEntry.setChildrenInitialized( false );
}
}
else
{
if ( entry != null )
{
entry.setAttributesInitialized( false );
}
}
}
}
catch ( Exception e )
{
logModificationError( browserConnection, logWriter, record, e, monitor );
errorCount++;
if ( !continueOnError )
{
monitor.reportError( e );
return;
}
}
monitor.reportProgress( BrowserCoreMessages.bind(
BrowserCoreMessages.ldif__imported_n_entries_m_errors, new String[]
{ "" + importedCount, "" + errorCount } ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
else
{
logWriter.write( container.toRawString() );
}
}
if ( errorCount > 0 )
{