while (true)
{
LinkedList<StringBuilder> lines;
DN entryDN;
EntryID entryID;
Suffix suffix;
synchronized (this)
{
// Read the set of lines that make up the next entry.
lines = readEntryLines();
if (lines == null)
{
return null;
}
lastEntryBodyLines = lines;
lastEntryHeaderLines = new LinkedList<StringBuilder>();
// Read the DN of the entry and see if it is one that should be included
// in the import.
try
{
entryDN = readDN(lines);
} catch (LDIFException le) {
entriesIgnored.incrementAndGet();
continue;
}
if (entryDN == null)
{
// This should only happen if the LDIF starts with the "version:" line
// and has a blank line immediately after that. In that case, simply
// read and return the next entry.
continue;
}
else if (!importConfig.includeEntry(entryDN))
{
if (debugEnabled())
{
TRACER.debugInfo("Skipping entry %s because the DN isn't" +
"one that should be included based on the include and " +
"exclude branches.", entryDN);
}
entriesRead.incrementAndGet();
Message message = ERR_LDIF_SKIP.get(String.valueOf(entryDN));
logToSkipWriter(lines, message);
entriesIgnored.incrementAndGet();
continue;
}
entryID = rootContainer.getNextEntryID();
suffix = Importer.getMatchSuffix(entryDN, map);
if(suffix == null)
{
if (debugEnabled())
{
TRACER.debugInfo("Skipping entry %s because the DN isn't" +
"one that should be included based on a suffix match" +
"check." ,entryDN);
}
entriesRead.incrementAndGet();
Message message = ERR_LDIF_SKIP.get(String.valueOf(entryDN));
logToSkipWriter(lines, message);
entriesIgnored.incrementAndGet();
continue;
}
entriesRead.incrementAndGet();
suffix.addPending(entryDN);
}
// Read the set of attributes from the entry.
HashMap<ObjectClass,String> objectClasses =
new HashMap<ObjectClass,String>();
HashMap<AttributeType,List<Attribute>> userAttributes =
new HashMap<AttributeType,List<Attribute>>();
HashMap<AttributeType,List<Attribute>> operationalAttributes =
new HashMap<AttributeType,List<Attribute>>();
try
{
for (StringBuilder line : lines)
{
readAttribute(lines, line, entryDN, objectClasses, userAttributes,
operationalAttributes, checkSchema);
}
}
catch (LDIFException e)
{
if (debugEnabled())
{
TRACER.debugInfo("Skipping entry %s because the it reading" +
"its attributes failed.", entryDN);
}
Message message =
ERR_LDIF_READ_ATTR_SKIP.get(String.valueOf(entryDN),
e.getMessage());
logToSkipWriter(lines, message);
entriesIgnored.incrementAndGet();
suffix.removePending(entryDN);
continue;
}
// Create the entry and see if it is one that should be included in the
// import.
Entry entry = new Entry(entryDN, objectClasses, userAttributes,
operationalAttributes);
TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, entry.toString());
try
{
if (! importConfig.includeEntry(entry))
{
if (debugEnabled())
{
TRACER.debugInfo("Skipping entry %s because the DN is not one " +
"that should be included based on the include and exclude " +
"filters.", entryDN);
}
Message message = ERR_LDIF_SKIP.get(String.valueOf(entryDN));
logToSkipWriter(lines, message);
entriesIgnored.incrementAndGet();
suffix.removePending(entryDN);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
suffix.removePending(entryDN);
Message message = ERR_LDIF_COULD_NOT_EVALUATE_FILTERS_FOR_IMPORT.
get(String.valueOf(entry.getDN()), lastEntryLineNumber,
String.valueOf(e));
logToSkipWriter(lines, message);
entriesIgnored.incrementAndGet();
suffix.removePending(entryDN);
continue;
}
// If we should invoke import plugins, then do so.
if (importConfig.invokeImportPlugins())
{
PluginResult.ImportLDIF pluginResult =
pluginConfigManager.invokeLDIFImportPlugins(importConfig, entry);
if (! pluginResult.continueProcessing())
{
Message m;
Message rejectMessage = pluginResult.getErrorMessage();
if (rejectMessage == null)
{
m = ERR_LDIF_REJECTED_BY_PLUGIN_NOMESSAGE.get(
String.valueOf(entryDN));
}
else
{
m = ERR_LDIF_REJECTED_BY_PLUGIN.get(String.valueOf(entryDN),
rejectMessage);
}
logToRejectWriter(lines, m);
entriesRejected.incrementAndGet();
suffix.removePending(entryDN);
continue;
}
}
// Make sure that the entry is valid as per the server schema if it is
// appropriate to do so.
if (checkSchema)
{
//Add the RDN attributes.
addRDNAttributesIfNecessary(entryDN,userAttributes,
operationalAttributes);
//Add any superior objectclass(s) missing in the objectclass map.
addSuperiorObjectClasses(objectClasses);
MessageBuilder invalidReason = new MessageBuilder();
if (! entry.conformsToSchema(null, false, true, false, invalidReason))
{
Message message = ERR_LDIF_SCHEMA_VIOLATION.get(
String.valueOf(entryDN),
lastEntryLineNumber,
invalidReason.toString());
logToRejectWriter(lines, message);
entriesRejected.incrementAndGet();
suffix.removePending(entryDN);
continue;
}
}
entryInfo.setEntryID(entryID);
entryInfo.setSuffix(suffix);