ArrayList<DN> includeBranches =
new ArrayList<DN>(includeBranchStrings.size());
for (String s : includeBranchStrings)
{
DN includeBranch;
try
{
includeBranch = DN.decode(s);
}
catch (DirectoryException de)
{
Message message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get(
s, de.getMessageObject());
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
catch (Exception e)
{
Message message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get(
s, getExceptionMessage(e));
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
if(! includeBranches.contains(includeBranch))
{
includeBranches.add(includeBranch);
}
}
if(backendID != null)
{
backend = DirectoryServer.getBackend(backendID);
if (backend == null)
{
Message message = ERR_LDIFIMPORT_NO_BACKENDS_FOR_ID.get();
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
else if (! backend.supportsLDIFImport())
{
Message message = ERR_LDIFIMPORT_CANNOT_IMPORT.get(backendID);
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
// Make sure that if the "backendID" argument was provided, no include
// base was included, and the "append" ption was not provided, the
// "clearBackend" argument was also provided if there are more then one
// baseDNs for the backend being imported.
else if(!append && includeBranches.isEmpty() &&
backend.getBaseDNs().length > 1 && !clearBackend)
{
StringBuilder builder = new StringBuilder();
builder.append(backend.getBaseDNs()[0].toNormalizedString());
for(int i = 1; i < backend.getBaseDNs().length; i++)
{
builder.append(" / ");
builder.append(backend.getBaseDNs()[i].toNormalizedString());
}
Message message = ERR_LDIFIMPORT_MISSING_CLEAR_BACKEND.get(
builder.toString(), ATTR_IMPORT_CLEAR_BACKEND);
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
}
else
{
// Find the backend that includes all the branches.
for(DN includeBranch : includeBranches)
{
Backend locatedBackend = DirectoryServer.getBackend(includeBranch);
if(locatedBackend != null)
{
if(backend == null)
{
backend = locatedBackend;
}
else if(backend != locatedBackend)
{
// The include branches span across multiple backends.
Message message = ERR_LDIFIMPORT_INVALID_INCLUDE_BASE.get(
includeBranch.toNormalizedString(), backend.getBackendID());
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
}
}
}
// Find backends with subordinate base DNs that should be excluded from the
// import.
defaultIncludeBranches = new ArrayList<DN>(backend.getBaseDNs().length);
for (DN dn : backend.getBaseDNs())
{
defaultIncludeBranches.add(dn);
}
if (backend.getSubordinateBackends() != null)
{
for (Backend subBackend : backend.getSubordinateBackends())
{
for (DN baseDN : subBackend.getBaseDNs())
{
for (DN importBase : defaultIncludeBranches)
{
if (baseDN.isDescendantOf(importBase) &&
(! baseDN.equals(importBase)))
{
if (! excludeBranches.contains(baseDN))
{
excludeBranches.add(baseDN);
}
break;
}
}
}
}
}
for (String s : excludeBranchStrings)
{
DN excludeBranch;
try
{
excludeBranch = DN.decode(s);
}
catch (DirectoryException de)