}
catch (Exception e)
{
Message m = ERR_LDIF_BACKEND_CANNOT_CREATE_LDIF_READER.get(
stackTraceToSingleLineString(e));
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
m, e);
}
entryMap.clear();
childDNs.clear();
try
{
while (true)
{
Entry e = null;
try
{
e = reader.readEntry();
if (e == null)
{
break;
}
}
catch (LDIFException le)
{
if (! le.canContinueReading())
{
Message m = ERR_LDIF_BACKEND_ERROR_READING_LDIF.get(
stackTraceToSingleLineString(le));
throw new DirectoryException(
DirectoryServer.getServerErrorResultCode(), m, le);
}
else
{
continue;
}
}
// Make sure that we don't already have an entry with the same DN. If
// a duplicate is encountered, then log a message and continue.
DN entryDN = e.getDN();
if (entryMap.containsKey(entryDN))
{
Message m = ERR_LDIF_BACKEND_DUPLICATE_ENTRY.get(ldifFilePath,
currentConfig.dn().toString(), entryDN.toString());
logError(m);
reader.rejectLastEntry(m);
continue;
}
// If the entry DN is a base DN, then add it with no more processing.
if (baseDNSet.contains(entryDN))
{
entryMap.put(entryDN, e);
continue;
}
// Make sure that the parent exists. If not, then reject the entry.
boolean isBelowBaseDN = false;
for (DN baseDN : baseDNs)
{
if (baseDN.isAncestorOf(entryDN))
{
isBelowBaseDN = true;
break;
}
}
if (! isBelowBaseDN)
{
Message m = ERR_LDIF_BACKEND_ENTRY_OUT_OF_SCOPE.get(ldifFilePath,
currentConfig.dn().toString(), entryDN.toString());
logError(m);
reader.rejectLastEntry(m);
continue;
}
DN parentDN = entryDN.getParentDNInSuffix();
if ((parentDN == null) || (! entryMap.containsKey(parentDN)))
{
Message m = ERR_LDIF_BACKEND_MISSING_PARENT.get(ldifFilePath,
currentConfig.dn().toString(), entryDN.toString());
logError(m);
reader.rejectLastEntry(m);
continue;
}
// The entry does not exist but its parent does, so add it and update
// the set of children for the parent.
entryMap.put(entryDN, e);
HashSet<DN> childDNSet = childDNs.get(parentDN);
if (childDNSet == null)
{
childDNSet = new HashSet<DN>();
childDNs.put(parentDN, childDNSet);
}
childDNSet.add(entryDN);
}
if (writeLDIF)
{
writeLDIF();
}
return new LDIFImportResult(reader.getEntriesRead(),
reader.getEntriesRejected(),
reader.getEntriesIgnored());
}
catch (DirectoryException de)
{
throw de;
}
catch (Exception e)
{
Message m = ERR_LDIF_BACKEND_ERROR_READING_LDIF.get(
stackTraceToSingleLineString(e));
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
m, e);
}
finally
{
reader.close();