TRACER.debugInfo("Creating applied file " + outputPath);
}
LDIFReader reader = null;
LDIFWriter writer = null;
try
{
reader = new LDIFReader(importConfig);
writer = new LDIFWriter(exportConfig);
while (true)
{
ChangeRecordEntry changeRecord;
try
{
changeRecord = reader.readChangeRecord(false);
if (debugEnabled())
{
TRACER.debugInfo("Read change record entry " +
String.valueOf(changeRecord));
}
}
catch (LDIFException le)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, le);
}
errorEncountered = true;
if (le.canContinueReading())
{
Message m =
ERR_LDIF_CONNHANDLER_CANNOT_READ_CHANGE_RECORD_NONFATAL.get(
le.getMessageObject());
writer.writeComment(m, 78);
continue;
}
else
{
Message m =
ERR_LDIF_CONNHANDLER_CANNOT_READ_CHANGE_RECORD_FATAL.get(
le.getMessageObject());
writer.writeComment(m, 78);
DirectoryConfig.sendAlertNotification(this,
ALERT_TYPE_LDIF_CONNHANDLER_PARSE_ERROR, m);
break;
}
}
Operation operation = null;
if (changeRecord == null)
{
fullyProcessed = true;
break;
}
if (changeRecord instanceof AddChangeRecordEntry)
{
operation = conn.processAdd((AddChangeRecordEntry) changeRecord);
}
else if (changeRecord instanceof DeleteChangeRecordEntry)
{
operation = conn.processDelete(
(DeleteChangeRecordEntry) changeRecord);
}
else if (changeRecord instanceof ModifyChangeRecordEntry)
{
operation = conn.processModify(
(ModifyChangeRecordEntry) changeRecord);
}
else if (changeRecord instanceof ModifyDNChangeRecordEntry)
{
operation = conn.processModifyDN(
(ModifyDNChangeRecordEntry) changeRecord);
}
if (operation == null)
{
Message m = INFO_LDIF_CONNHANDLER_UNKNOWN_CHANGETYPE.get(
changeRecord.getChangeOperationType().getLDIFChangeType());
writer.writeComment(m, 78);
}
else
{
if (debugEnabled())
{
TRACER.debugInfo("Result Code: " +
operation.getResultCode().toString());
}
Message m = INFO_LDIF_CONNHANDLER_RESULT_CODE.get(
operation.getResultCode().getIntValue(),
operation.getResultCode().toString());
writer.writeComment(m, 78);
MessageBuilder errorMessage = operation.getErrorMessage();
if ((errorMessage != null) && (errorMessage.length() > 0))
{
m = INFO_LDIF_CONNHANDLER_ERROR_MESSAGE.get(errorMessage);
writer.writeComment(m, 78);
}
DN matchedDN = operation.getMatchedDN();
if (matchedDN != null)
{
m = INFO_LDIF_CONNHANDLER_MATCHED_DN.get(matchedDN.toString());
writer.writeComment(m, 78);
}
List<String> referralURLs = operation.getReferralURLs();
if ((referralURLs != null) && (! referralURLs.isEmpty()))
{
for (String url : referralURLs)
{
m = INFO_LDIF_CONNHANDLER_REFERRAL_URL.get(url);
writer.writeComment(m, 78);
}
}
}
writer.writeChangeRecord(changeRecord);
}
}
catch (IOException ioe)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, ioe);
}
fullyProcessed = false;
Message m = ERR_LDIF_CONNHANDLER_IO_ERROR.get(inputPath,
getExceptionMessage(ioe));
logError(m);
DirectoryConfig.sendAlertNotification(this,
ALERT_TYPE_LDIF_CONNHANDLER_PARSE_ERROR, m);
}
finally
{
if (reader != null)
{
try
{
reader.close();
} catch (Exception e) {}
}
if (writer != null)
{
try
{
writer.close();
} catch (Exception e) {}
}
}
if (errorEncountered || (! fullyProcessed))