buildConfigs();
if (roleConfig == null)
{
throw new NestedException("Role configuration is null");
}
if (logConfig == null)
{
throw new NestedException("Log configuration is null");
}
if (systemConfig == null)
{
throw new NestedException("System configuration is null");
}
if (instrConfig == null)
{
throw new NestedException("Instrumentation configuration is null");
}
DefaultContext c = new DefaultContext();
String contextPath = System.getProperty(CONFIG_PROPERTY) + System.getProperty("file.separator") + "..";
c.put("current-dir", contextPath);
c.put(ContextManagerConstants.THREAD_TIMEOUT, new Long(1000));
c.put(ContextManagerConstants.THREADS_CPU, new Integer(2));
c.put(ContextManagerConstants.CONTEXT_DIRECTORY, new File(contextPath));
c.put(ContextManagerConstants.WORK_DIRECTORY, new File(contextPath + "/tmp"));
ClassLoader loader = Thread.currentThread().getContextClassLoader();
c.put(ClassLoader.class.getName(), loader);
c.put(ContextManagerConstants.PARAMETERS, new Parameters());
c.put(ContextManagerConstants.CONTAINER_CLASS, KeelContainer.class);
c.put(ContextManagerConstants.LOGGER_MANAGER_CONFIGURATION, logConfig);
c.put(ContextManagerConstants.CONFIGURATION, systemConfig);
c.put(ContextManagerConstants.INSTRUMENT_MANAGER_CONFIGURATION, instrConfig);
c.put(ContextManagerConstants.LOG_CATEGORY, "keel");
c.put("keel.config.roles", roleConfig);
c.put("keel.config.system", systemConfig);
c.put("keel.config.log", logConfig);
c.put("keel.config.instr", instrConfig);
c.put("keel.config.spring.file", springFileConfig.toArray(new String[]
{}));
c.put("keel.config.spring.classpath", springClasspathConfig.toArray(new String[]
{}));
c.put("keel.config.hibernate", hibernateConfig.toArray(new String[]
{}));
/*
* Set the context for the getLoggerManager() calls below to work
* we'll set the context again later
*/
setContext(c);
/*
* Create a custom meta-info manager. This gets around the fact
* that keel-server needs its own sandboxed classpath, which
* KeelURLClassloader provides for classes. But,
* java.lang.Classpath doesn't let one override the fact that
* resources gotten via the load.getResources() is always looked up
* from the parent loader in addition to the current loader.
*/
final MetaInfoManager metaManager = createMetaManager(loader);
c.put(MetaInfoManager.ROLE, metaManager);
/*
* Put a logger manager in the Context. NOTE: getLoggerManager()
* needs a context set in the first place
*/
c.put(LoggerManager.ROLE, getLoggerManager());
c.put("keel.loggerManager", getLoggerManager());
setContext(c);
/*
* So far we have been using the primordial logger since the logger
* config hadn't been read and we did not have enough context. Now
* we do, so create a proper logger
*/
try
{
logger = getLoggerManager().getLoggerForCategory("keel.container");
}
catch (Exception e)
{
getLogger().debug("Cannot create Keel logger, using defult logger", e);
}
c.put(LifecycleExtensionManager.ROLE, createLifeCycleExtensionManager(c));
setContext(c);
/*
* Create the container
*/
DefaultContainerManager containerManager = null;
try
{
containerManager = new DefaultContainerManager(context);
if (containerManager instanceof Initializable)
{
((Initializable) containerManager).initialize();
}
}
catch (ClassNotFoundException e)
{
getLogger().error("Error loading KeelContainer class", e);
throw new NestedException(e);
}
catch (Exception e)
{
getLogger().error("Error initializing Container Manager", e);
throw new NestedException(e);
}
try
{
setProperties(System.getProperty(CONFIG_PROPERTY));
}
catch (Exception e)
{
throw new NestedException(e);
}
return containerManager;
}