try
{
// Make sure that the original entry exists and that the new entry doesn't
// exist but its parent does.
DN newDN = entry.getDN();
if (! entryMap.containsKey(currentDN))
{
DN matchedDN = null;
DN parentDN = currentDN.getParentDNInSuffix();
while (parentDN != null)
{
if (entryMap.containsKey(parentDN))
{
matchedDN = parentDN;
break;
}
parentDN = parentDN.getParentDNInSuffix();
}
Message m = ERR_LDIF_BACKEND_MODDN_NO_SUCH_SOURCE_ENTRY.get(
currentDN.toString());
throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, m, matchedDN,
null);
}
if (entryMap.containsKey(newDN))
{
Message m = ERR_LDIF_BACKEND_MODDN_TARGET_ENTRY_ALREADY_EXISTS.get(
newDN.toString());
throw new DirectoryException(ResultCode.ENTRY_ALREADY_EXISTS, m);
}
DN newParentDN = newDN.getParentDNInSuffix();
if (! entryMap.containsKey(newParentDN))
{
Message m = ERR_LDIF_BACKEND_MODDN_NEW_PARENT_DOESNT_EXIST.get(
String.valueOf(newParentDN));
throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, m);
}
// Remove the entry from the list of children for the old parent and
// add the new entry DN to the set of children for the new parent.
DN oldParentDN = currentDN.getParentDNInSuffix();
HashSet<DN> parentChildDNs = childDNs.get(oldParentDN);
if (parentChildDNs != null)
{
parentChildDNs.remove(currentDN);
if (parentChildDNs.isEmpty() &&