for (Container engineChild : engine.findChildren()) {
if (engineChild instanceof Host) {
Host host = (Host) engineChild;
for (Container hostChild : host.findChildren()) {
if (hostChild instanceof StandardContext) {
StandardContext standardContext = (StandardContext) hostChild;
int state = standardContext.getState();
if (state == 0) {
// context only initialized
tomcatWebAppBuilder.init(standardContext);
} else if (state == 1) {
// context already started
standardContext.addParameter("openejb.start.late", "true");
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(standardContext.getLoader().getClassLoader());
try {
tomcatWebAppBuilder.init(standardContext);
tomcatWebAppBuilder.beforeStart(standardContext);
tomcatWebAppBuilder.start(standardContext);
tomcatWebAppBuilder.afterStart(standardContext);
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
}
standardContext.removeParameter("openejb.start.late");
}
}
}
}
}