}
// We will use the LDIF reader to read the configuration file. Create an
// LDIF import configuration to do this and then get the reader.
LDIFReader reader;
try
{
LDIFImportConfig importConfig = new LDIFImportConfig(f.getAbsolutePath());
// FIXME -- Should we support encryption or compression for the config?
reader = new LDIFReader(importConfig);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = ERR_CONFIG_FILE_CANNOT_OPEN_FOR_READ.get(
f.getAbsolutePath(), String.valueOf(e));
throw new InitializationException(message, e);
}
// Read the first entry from the configuration file.
Entry entry;
try
{
entry = reader.readEntry(checkSchema);
}
catch (LDIFException le)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, le);
}
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_CONFIG_FILE_INVALID_LDIF_ENTRY.get(
le.getLineNumber(), f.getAbsolutePath(), String.valueOf(le));
throw new InitializationException(message, le);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
try
{
reader.close();
}
catch (Exception e2)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e2);
}
}
Message message =
ERR_CONFIG_FILE_READ_ERROR.get(f.getAbsolutePath(),
String.valueOf(e));
throw new InitializationException(message, e);
}
// Make sure that the provide LDIF file is not empty.
if (entry == null)
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_CONFIG_FILE_EMPTY.get(f.getAbsolutePath());
throw new InitializationException(message);
}
// Make sure that the DN of this entry is equal to the config root DN.
try
{
DN configRootDN = DN.decode(DN_CONFIG_ROOT);
if (! entry.getDN().equals(configRootDN))
{
Message message = ERR_CONFIG_FILE_INVALID_BASE_DN.get(
f.getAbsolutePath(), entry.getDN().toString(),
DN_CONFIG_ROOT);
throw new InitializationException(message);
}
}
catch (InitializationException ie)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, ie);
}
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
throw ie;
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
try
{
reader.close();
}
catch (Exception e2)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e2);
}
}
// This should not happen, so we can use a generic error here.
Message message = ERR_CONFIG_FILE_GENERIC_ERROR.get(f.getAbsolutePath(),
String.valueOf(e));
throw new InitializationException(message, e);
}
// Convert the entry to a configuration entry and put it in the config
// hash.
configEntries = new ConcurrentHashMap<DN,ConfigEntry>();
configRootEntry = new ConfigEntry(entry, null);
configEntries.put(entry.getDN(), configRootEntry);
// Iterate through the rest of the configuration file and process the
// remaining entries.
while (true)
{
// Read the next entry from the configuration.
try
{
entry = reader.readEntry(checkSchema);
}
catch (LDIFException le)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, le);
}
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_CONFIG_FILE_INVALID_LDIF_ENTRY.get(
le.getLineNumber(), f.getAbsolutePath(),
String.valueOf(le));
throw new InitializationException(message, le);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
try
{
reader.close();
}
catch (Exception e2)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e2);
}
}
Message message = ERR_CONFIG_FILE_READ_ERROR.get(f.getAbsolutePath(),
String.valueOf(e));
throw new InitializationException(message, e);
}
// If the entry is null, then we have reached the end of the configuration
// file.
if (entry == null)
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
break;
}
// Make sure that the DN of the entry read doesn't already exist.
DN entryDN = entry.getDN();
if (configEntries.containsKey(entryDN))
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_CONFIG_FILE_DUPLICATE_ENTRY.get(
entryDN.toString(),
String.valueOf(reader.getLastEntryLineNumber()),
f.getAbsolutePath());
throw new InitializationException(message);
}
// Make sure that the parent DN of the entry read does exist.
DN parentDN = entryDN.getParent();
if (parentDN == null)
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_CONFIG_FILE_UNKNOWN_PARENT.get(
entryDN.toString(),
reader.getLastEntryLineNumber(),
f.getAbsolutePath());
throw new InitializationException(message);
}
ConfigEntry parentEntry = configEntries.get(parentDN);
if (parentEntry == null)
{
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
Message message = ERR_CONFIG_FILE_NO_PARENT.get(entryDN.toString(),
reader.getLastEntryLineNumber(),
f.getAbsolutePath(), parentDN.toString());
throw new InitializationException(message);
}
// Create the new configuration entry, add it as a child of the provided
// parent entry, and put it into the entry has.
try
{
ConfigEntry configEntry = new ConfigEntry(entry, parentEntry);
parentEntry.addChild(configEntry);
configEntries.put(entryDN, configEntry);
}
catch (Exception e)
{
// This should not happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
try
{
reader.close();
}
catch (Exception e2)
{
if (debugEnabled())
{