Set<String> securityRoles,
Map<String, PermissionCollection> rolePermissions,
EARContext moduleContext) throws DeploymentException {
String servletName = servletType.getServletName().getStringValue().trim();
AbstractName servletAbstractName = moduleContext.getNaming().createChildName(webModuleName, servletName, NameFactory.SERVLET);
GBeanData servletData;
Map<String, String> initParams = new HashMap<String, String>();
if (servletType.isSetServletClass()) {
ClassLoader webClassLoader = moduleContext.getClassLoader();
String servletClassName = servletType.getServletClass().getStringValue().trim();
Class servletClass;
try {
servletClass = webClassLoader.loadClass(servletClassName);
} catch (ClassNotFoundException e) {
throw new DeploymentException("Could not load servlet class " + servletClassName, e); // TODO identify web app in message
}
Class baseServletClass;
try {
baseServletClass = webClassLoader.loadClass(Servlet.class.getName());
} catch (ClassNotFoundException e) {
throw new DeploymentException("Could not load javax.servlet.Servlet in web classloader", e); // TODO identify web app in message
}
if (baseServletClass.isAssignableFrom(servletClass)) {
servletData = new GBeanData(servletAbstractName, JettyServletHolder.GBEAN_INFO);
servletData.setAttribute("servletClass", servletClassName);
} else {
servletData = new GBeanData(pojoWebServiceTemplate);
servletData.setAbstractName(servletAbstractName);
//let the web service builder deal with configuring the gbean with the web service stack
// Object portInfo = portMap.get(servletName);
// if (portInfo == null) {
// throw new DeploymentException("No web service deployment info for servlet name " + servletName); // TODO identify web app in message
// }
boolean configured = false;
for (Object aWebServiceBuilder : webServiceBuilder) {
WebServiceBuilder serviceBuilder = (WebServiceBuilder) aWebServiceBuilder;
if (serviceBuilder.configurePOJO(servletData, servletName, module, servletClassName, moduleContext)) {
configured = true;
break;
}
}
if (!configured) {
throw new DeploymentException("POJO web service: " + servletName + " not configured by any web service builder");
}
}
} else if (servletType.isSetJspFile()) {
servletData = new GBeanData(servletAbstractName, JettyServletHolder.GBEAN_INFO);
servletData.setAttribute("jspFile", servletType.getJspFile().getStringValue().trim());
servletData.setAttribute("servletClass", jspServlet.getServletClassName());
initParams.put("development", "false");
} else {
throw new DeploymentException("Neither servlet class nor jsp file is set for " + servletName); // TODO identify web app in message
}
// link to previous servlet, if there is one, so that we
// preserve the <load-on-startup> ordering.
// http://issues.apache.org/jira/browse/GERONIMO-645
if (null != previousServlet) {
servletData.addDependency(previousServlet);
}
//TODO in init param setter, add classpath if jspFile is not null.
servletData.setReferencePattern("JettyServletRegistration", webModuleName);
servletData.setAttribute("servletName", servletName);
ParamValueType[] initParamArray = servletType.getInitParamArray();
for (ParamValueType paramValueType : initParamArray) {
initParams.put(paramValueType.getParamName().getStringValue().trim(), paramValueType.getParamValue().getStringValue().trim());
}
servletData.setAttribute("initParams", initParams);
if (servletType.isSetLoadOnStartup()) {
Integer loadOnStartup = new Integer(servletType.xgetLoadOnStartup().getStringValue());
servletData.setAttribute("loadOnStartup", loadOnStartup);
}
Set mappings = servletMappings.get(servletName);
servletData.setAttribute("servletMappings", mappings == null ? Collections.EMPTY_SET : mappings);
//run-as
if (servletType.isSetRunAs()) {
String runAsRole = servletType.getRunAs().getRoleName().getStringValue().trim();
servletData.setAttribute("runAsRole", runAsRole);
}
processRoleRefPermissions(servletType, securityRoles, rolePermissions);
try {