// Make sure that the target entry exists.
if (! entryMap.containsKey(currentDN))
{
Message message =
ERR_MEMORYBACKEND_ENTRY_DOESNT_EXIST.get(String.valueOf(currentDN));
throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message);
}
// Make sure that the target entry doesn't have any children.
HashSet<DN> children = childDNs.get(currentDN);
if (children != null)
{
if (children.isEmpty())
{
childDNs.remove(currentDN);
}
else
{
Message message = ERR_MEMORYBACKEND_CANNOT_RENAME_ENRY_WITH_CHILDREN.
get(String.valueOf(currentDN));
throw new DirectoryException(
ResultCode.NOT_ALLOWED_ON_NONLEAF, message);
}
}
// Make sure that no entry exists with the new DN.
if (entryMap.containsKey(e.getDN()))
{
Message message =
ERR_MEMORYBACKEND_ENTRY_ALREADY_EXISTS.get(String.valueOf(e.getDN()));
throw new DirectoryException(ResultCode.ENTRY_ALREADY_EXISTS, message);
}
// Make sure that the new DN is in this backend.
boolean matchFound = false;
for (DN dn : baseDNs)
{
if (dn.isAncestorOf(e.getDN()))
{
matchFound = true;
break;
}
}
if (! matchFound)
{
Message message = ERR_MEMORYBACKEND_CANNOT_RENAME_TO_ANOTHER_BACKEND.get(
String.valueOf(currentDN));
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
}
// Make sure that the parent of the new entry exists.
DN parentDN = e.getDN().getParentDNInSuffix();
if ((parentDN == null) || (! entryMap.containsKey(parentDN)))
{
Message message = ERR_MEMORYBACKEND_RENAME_PARENT_DOESNT_EXIST.get(
String.valueOf(currentDN), String.valueOf(parentDN));
throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message);
}
// Delete the current entry and add the new one.
deleteEntry(currentDN, null);