throw new IOException(message.toString());
}
while (true)
{
ChangeRecordEntry entry = null;
try
{
entry = reader.readChangeRecord(modifyOptions.getDefaultAdd());
} catch (LDIFException le)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, le);
}
if (!modifyOptions.continueOnError())
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_LDIF_FILE_INVALID_LDIF_ENTRY.get(
le.getLineNumber(), fileName, String.valueOf(le));
throw new IOException(message.toString());
}
else
{
Message message = ERR_LDIF_FILE_INVALID_LDIF_ENTRY.get(
le.getLineNumber(), fileName, String.valueOf(le));
err.println(wrapText(message, MAX_LINE_WIDTH));
continue;
}
} catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
if (!modifyOptions.continueOnError())
{
try
{
reader.close();
}
catch (Exception e2)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e2);
}
}
Message message =
ERR_LDIF_FILE_READ_ERROR.get(fileName, String.valueOf(e));
throw new IOException(message.toString());
}
else
{
Message message = ERR_LDIF_FILE_READ_ERROR.get(
fileName, String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
continue;
}
}
// If the entry is null, then we have reached the end of the config file.
if(entry == null)
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
break;
}
ProtocolOp protocolOp = null;
ByteString asn1OctetStr =
ByteString.valueOf(entry.getDN().toString());
String operationType = "";
switch(entry.getChangeOperationType())
{
case ADD:
operationType = "ADD";
AddChangeRecordEntry addEntry = (AddChangeRecordEntry) entry;
List<Attribute> attrs = addEntry.getAttributes();
ArrayList<RawAttribute> attributes =
new ArrayList<RawAttribute>(attrs.size());
for(Attribute a : attrs)
{
attributes.add(new LDAPAttribute(a));
}
protocolOp = new AddRequestProtocolOp(asn1OctetStr, attributes);
out.println(INFO_PROCESSING_OPERATION.get(
operationType, asn1OctetStr.toString()));
break;
case DELETE:
operationType = "DELETE";
protocolOp = new DeleteRequestProtocolOp(asn1OctetStr);
out.println(INFO_PROCESSING_OPERATION.get(
operationType, asn1OctetStr.toString()));
break;
case MODIFY:
operationType = "MODIFY";
ModifyChangeRecordEntry modEntry = (ModifyChangeRecordEntry) entry;
ArrayList<RawModification> mods =
new ArrayList<RawModification>(modEntry.getModifications());
protocolOp = new ModifyRequestProtocolOp(asn1OctetStr, mods);
out.println(INFO_PROCESSING_OPERATION.get(
operationType, asn1OctetStr.toString()));
break;
case MODIFY_DN:
operationType = "MODIFY DN";
ModifyDNChangeRecordEntry modDNEntry =
(ModifyDNChangeRecordEntry) entry;
if(modDNEntry.getNewSuperiorDN() != null)
{
protocolOp = new ModifyDNRequestProtocolOp(asn1OctetStr,
ByteString.valueOf(modDNEntry.getNewRDN().toString()),
modDNEntry.deleteOldRDN(),
ByteString.valueOf(
modDNEntry.getNewSuperiorDN().toString()));
} else
{
protocolOp = new ModifyDNRequestProtocolOp(asn1OctetStr,
ByteString.valueOf(modDNEntry.getNewRDN().toString()),
modDNEntry.deleteOldRDN());
}
out.println(INFO_PROCESSING_OPERATION.get(
operationType, asn1OctetStr.toString()));
break;
default:
break;
}
if(!modifyOptions.showOperations())
{
LDAPMessage responseMessage = null;
try
{
LDAPMessage message =
new LDAPMessage(nextMessageID.getAndIncrement(), protocolOp,
controls);
connection.getLDAPWriter().writeMessage(message);
responseMessage = connection.getLDAPReader().readMessage();
} catch(ASN1Exception ae)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, ae);
}
Message message = INFO_OPERATION_FAILED.get(operationType);
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(wrapText(ae.getMessage(), MAX_LINE_WIDTH));
if (!modifyOptions.continueOnError())
{
String msg = LDAPToolUtils.getMessageForConnectionException(ae);
throw new IOException(msg, ae);
}
return;
}
int resultCode = 0;
Message errorMessage = null;
DN matchedDN = null;
List<String> referralURLs = null;
try
{
switch(entry.getChangeOperationType())
{
case ADD:
AddResponseProtocolOp addOp =
responseMessage.getAddResponseProtocolOp();
resultCode = addOp.getResultCode();