}
}
private HttpServlet tryGetOrLoadServlet(TreeLogger logger, String className) {
synchronized (loadedServletsByClassName) {
HttpServlet servlet = (HttpServlet) loadedServletsByClassName.get(className);
if (servlet != null) {
// Found it.
//
return servlet;
}
// Try to load and instantiate it.
//
Throwable caught = null;
try {
Class servletClass = Class.forName(className);
Object newInstance = servletClass.newInstance();
if (!(newInstance instanceof HttpServlet)) {
logger.log(TreeLogger.ERROR,
"Not compatible with HttpServlet: " + className
+ " (does your service extend RemoteServiceServlet?)", null);
return null;
}
// Success. Hang onto the instance so we can reuse it.
//
servlet = (HttpServlet) newInstance;
servlet.init(getServletConfig());
loadedServletsByClassName.put(className, servlet);
return servlet;
} catch (ClassNotFoundException e) {
caught = e;