}
public void addGBeans(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException {
J2eeContext earJ2eeContext = earContext.getJ2eeContext();
J2eeContext moduleJ2eeContext = J2eeContextImpl.newModuleContextFromApplication(earJ2eeContext, NameFactory.WEB_MODULE, module.getName());
WebModule webModule = (WebModule) module;
WebAppType webApp = (WebAppType) webModule.getSpecDD();
TomcatWebAppType tomcatWebApp = (TomcatWebAppType) webModule.getVendorDD();
boolean contextPriorityClassLoader = defaultContextPriorityClassloader;
if (tomcatWebApp != null && tomcatWebApp.isSetContextPriorityClassloader()) {
contextPriorityClassLoader = tomcatWebApp.getContextPriorityClassloader();
}
// construct the webClassLoader
ClassLoader webClassLoader = getWebClassLoader(earContext, webModule, cl, contextPriorityClassLoader);
if (tomcatWebApp != null) {
GbeanType[] gbeans = tomcatWebApp.getGbeanArray();
ServiceConfigBuilder.addGBeans(gbeans, webClassLoader, moduleJ2eeContext, earContext);
}
ObjectName webModuleName = null;
try {
webModuleName = NameFactory.getModuleName(null, null, null, null, null, moduleJ2eeContext);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("Could not construct module name", e);
}
UserTransaction userTransaction = new OnlineUserTransaction();
//this may add to the web classpath with enhanced classes.
Map compContext = buildComponentContext(earContext, webModule, webApp, tomcatWebApp, userTransaction, webClassLoader);
GBeanData webModuleData = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
try {
webModuleData.setReferencePattern("J2EEServer", earContext.getServerObjectName());
if (!earContext.getJ2EEApplicationName().equals("null")) {
webModuleData.setReferencePattern("J2EEApplication", earContext.getApplicationObjectName());
}
webModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD());
Set securityRoles = collectRoleNames(webApp);
Map rolePermissions = new HashMap();
URI baseUri = URI.create(webModule.getTargetPath() + "/");
webModuleData.setAttribute("webAppRoot", baseUri);
webModuleData.setAttribute("contextPath", webModule.getContextRoot());
webModuleData.setAttribute("componentContext", compContext);
webModuleData.setAttribute("userTransaction", userTransaction);
//classpath may have been augmented with enhanced classes
webModuleData.setAttribute("webClassPath", webModule.getWebClasspath());
// unsharableResources, applicationManagedSecurityResources
GBeanResourceEnvironmentBuilder rebuilder = new GBeanResourceEnvironmentBuilder(webModuleData);
ENCConfigBuilder.setResourceEnvironment(earContext, webModule.getModuleURI(), rebuilder, webApp.getResourceRefArray(), tomcatWebApp.getResourceRefArray());
webModuleData.setAttribute("contextPriorityClassLoader", Boolean.valueOf(contextPriorityClassLoader));
webModuleData.setReferencePattern("TransactionContextManager", earContext.getTransactionContextManagerObjectName());
webModuleData.setReferencePattern("TrackedConnectionAssociator", earContext.getConnectionTrackerObjectName());
webModuleData.setReferencePattern("Container", tomcatContainerObjectName);
// Process the Tomcat container-config elements
if (tomcatWebApp.isSetHost()) {
String virtualServer = tomcatWebApp.getHost().trim();
webModuleData.setAttribute("virtualServer", virtualServer);
}
if (tomcatWebApp.isSetCrossContext()) {
webModuleData.setAttribute("crossContext", Boolean.TRUE);
}
if (tomcatWebApp.isSetTomcatRealm()) {
String tomcatRealm = tomcatWebApp.getTomcatRealm().trim();
ObjectName realmName = NameFactory.getComponentName(null, null, null, null, tomcatRealm, RealmGBean.GBEAN_INFO.getJ2eeType(), moduleJ2eeContext);
webModuleData.setReferencePattern("TomcatRealm", realmName);
}
if (tomcatWebApp.isSetValveChain()) {
String valveChain = tomcatWebApp.getValveChain().trim();
ObjectName valveName = NameFactory.getComponentName(null, null, null, null, valveChain, ValveGBean.J2EE_TYPE, moduleJ2eeContext);
webModuleData.setReferencePattern("TomcatValveChain", valveName);
}
Map portMap = webModule.getPortMap();
//Handle the role permissions and webservices on the servlets.
ServletType[] servletTypes = webApp.getServletArray();
Map webServices = new HashMap();
for (int i = 0; i < servletTypes.length; i++) {
ServletType servletType = servletTypes[i];
//Handle the Role Ref Permissions
processRoleRefPermissions(servletType, securityRoles, rolePermissions);
//Do we have webservices configured?
if (portMap != null) {
//Check if the Servlet is a Webservice
String servletName = servletType.getServletName().getStringValue().trim();
if (portMap.containsKey(servletName)) {
//Yes, this servlet is a web service so let the web service builder
// deal with configuring the web service stack
String servletClassName = servletType.getServletClass().getStringValue().trim();
Object portInfo = portMap.get(servletName);
if (portInfo == null) {
throw new DeploymentException("No web service deployment info for servlet name " + servletName);
}
StoredObject wsContainer = configurePOJO(webModule.getModuleFile(), portInfo, servletClassName, webClassLoader);
webServices.put(servletName, wsContainer);
}
}
}