private void loadServletClasses(WebAppConfiguration wac)
throws WebAppConfigurationException,
IllegalAccessException, InstantiationException {
for (WebAppServlet servletDef : wac.getServlets()) {
if (servletDef.getServletName() == null) {
throw new WebAppConfigurationException("Invalid servlet definition");
}
String servletClassName = servletDef.getServletClass();
String jspFileName = servletDef.getJspFile();
if (servletClassName == null && jspFileName == null) {
throw new WebAppConfigurationException(
"No servet-class or jsp-file for servlet '"
+ servletDef.getServletName() + "'");
}
if (servletClassName != null && jspFileName != null) {
throw new WebAppConfigurationException("servlet '"
+ servletDef.getServletName()
+ "' has both servlet-class and jsp-file elements defined");
}
Object servletObject;
// for jsp-file element, we use the generic JSP servlet class
if (servletClassName == null) {
servletClassName = getJspServletClassName(servletDef.getJspFile());
}
Class<?> servletClass = null;
try {
if (servletClassName != null) {
servletClass = classLoader.loadClass(servletClassName);
}
} catch (ClassNotFoundException e) {
LOGGER.log(Level.SEVERE, "Cannot find " + servletClassName);
}
if (servletClass != null) {
servletObject = servletClass.newInstance();
if (!(servletObject instanceof Servlet)) {
throw new WebAppConfigurationException("'" + servletClassName
+ "' is not a Servlet");
}
manager.addServlet(servletDef, (Servlet) servletObject);
}
}