// the superclass closes the modules
final ServletContext servletContext = servlet.getServletContext();
ModuleManagementFacade facade = ImpalaServletUtils.getModuleManagementFacade(servletContext);
if (facade == null) {
throw new ConfigurationException("Unable to load " + FrameworkServletContextCreator.class.getName()
+ " as no attribute '" + WebConstants.IMPALA_FACTORY_ATTRIBUTE
+ "' has been set up. Have you set up your Impala ContextLoader correctly?");
}
final String servletName = servlet.getServletName();
ModuleStateHolder moduleStateHolder = facade.getModuleStateHolder();
if (!initialized) {
ModuleStateChangeNotifier moduleStateChangeNotifier = facade.getModuleStateChangeNotifier();
moduleStateChangeNotifier.addListener(new ModuleStateChangeListener() {
public void moduleStateChanged(ModuleStateHolder moduleStateHolder, ModuleStateChange change) {
try {
servlet.init();
}
catch (Exception e) {
logger.error("Unable to reinitialize servlet " + servlet.getServletName(), e);
}
}
public String getModuleName() {
return servletName;
}
public Transition getTransition() {
return Transition.UNLOADED_TO_LOADED;
}
});
this.initialized = true;
}
ConfigurableApplicationContext context = moduleStateHolder.getModule(servletName);
if (context != null) {
if (context instanceof WebApplicationContext) {
return (WebApplicationContext) context;
}
else {
throw new ConfigurationException("Module registered under name of servlet '" + servletName
+ "' needs to be an instance of " + WebApplicationContext.class.getName());
}
}
else {
throw new ConfigurationException("No module registered under the name of servlet '" + servletName + "'");
}
}