if (includeBranchStrings.isPresent())
{
includeBranches = new ArrayList<DN>();
for (String s : includeBranchStrings.getValues())
{
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 1;
}
catch (Exception e)
{
Message message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get(
s, getExceptionMessage(e));
logError(message);
return 1;
}
includeBranches.add(includeBranch);
}
}
ArrayList<Backend> backendList = new ArrayList<Backend>();
ArrayList<BackendCfg> entryList = new ArrayList<BackendCfg>();
ArrayList<List<DN>> dnList = new ArrayList<List<DN>>();
int code = BackendToolUtils.getBackends(backendList, entryList, dnList);
if (code != 0)
{
return code;
}
int numBackends = backendList.size();
for (int i=0; i < numBackends; i++)
{
Backend b = backendList.get(i);
if(backendID.isPresent())
{
if (! backendID.getValue().equals(b.getBackendID()))
{
continue;
}
}
else
{
boolean useBackend = false;
for(DN baseDN : dnList.get(i))
{
for(DN includeDN : includeBranches)
{
if(baseDN.isAncestorOf(includeDN))
{
useBackend = true;
break;
}
}
if(useBackend)
{
break;
}
}
if(!useBackend)
{
continue;
}
}
if (backend == null)
{
backend = b;
defaultIncludeBranches = dnList.get(i);
}
else
{
Message message = ERR_LDIFIMPORT_MULTIPLE_BACKENDS_FOR_ID.get();
logError(message);
return 1;
}
}
if (backend == null)
{
Message message =
ERR_LDIFIMPORT_NO_BACKENDS_FOR_ID.get();
logError(message);
return 1;
}
else if (! backend.supportsLDIFImport())
{
Message message = ERR_LDIFIMPORT_CANNOT_IMPORT.get(backendID.getValue());
logError(message);
return 1;
}
for (List<DN> baseList : dnList)
{
for (DN baseDN : baseList)
{
for (DN importBase : defaultIncludeBranches)
{
if (baseDN.isDescendantOf(importBase) &&
(! baseDN.equals(importBase)))
{
if (! excludeBranches.contains(baseDN))
{
excludeBranches.add(baseDN);
}
break;
}
}
}
}
// Make sure that if the "backendID" argument was provided, no include base
// was included, the
// "clearBackend" argument was also provided if there are more then one
// baseDNs for the backend being imported.
if(backendID.isPresent() && !includeBranchStrings.isPresent() &&
!append.isPresent() &&
defaultIncludeBranches.size() > 1 &&
!clearBackend.isPresent())
{
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(), clearBackend.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
for (String s : excludeBranchStrings.getValues())
{
DN excludeBranch;
try
{
excludeBranch = DN.decode(s);
}
catch (DirectoryException de)