*/
@Override
public WeldApplicationContainer load(WeldContainer container, DeploymentContext context) {
DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
ApplicationInfo appInfo = applicationRegistry.get(deployParams.name);
ReadableArchive archive = context.getSource();
// See if a WeldBootsrap has already been created - only want one per app.
WeldBootstrap bootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP,
WeldBootstrap.class);
if ( bootstrap == null) {
bootstrap = new WeldBootstrap();
Application app = context.getModuleMetaData(Application.class);
appToBootstrap.put(app, bootstrap);
// Stash the WeldBootstrap instance, so we may access the WeldManager later..
context.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
appInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
// Making sure that if WeldBootstrap is added, shutdown is set to false, as it is/would not have been called.
appInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false");
}
EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
EjbServices ejbServices = null;
Set<EjbDescriptor> ejbs = new HashSet<EjbDescriptor>();
if( ejbBundle != null ) {
ejbs.addAll(ejbBundle.getEjbs());
ejbServices = new EjbServicesImpl(services);
}
// Create a Deployment Collecting Information From The ReadableArchive (archive)
DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
if (deploymentImpl == null) {
deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory);
// Add services
TransactionServices transactionServices = new TransactionServicesImpl(services);
deploymentImpl.getServices().add(TransactionServices.class, transactionServices);
SecurityServices securityServices = new SecurityServicesImpl();
deploymentImpl.getServices().add(SecurityServices.class, securityServices);
ProxyServices proxyServices = new ProxyServicesImpl(services);
deploymentImpl.getServices().add(ProxyServices.class, proxyServices);
BootstrapConfigurationImpl bootstrapConfiguration = new BootstrapConfigurationImpl();
deploymentImpl.getServices().add(BootstrapConfiguration.class, bootstrapConfiguration);
addWeldListenerToAllWars(context);
} else {
deploymentImpl.scanArchive(archive, ejbs, context);
}
deploymentImpl.addDeployedEjbs(ejbs);
if( ejbBundle != null && (!deploymentImpl.getServices().contains(EjbServices.class))) {
// EJB Services is registered as a top-level service
deploymentImpl.getServices().add(EjbServices.class, ejbServices);
}
BeanDeploymentArchive bda = deploymentImpl.getBeanDeploymentArchiveForArchive(archive.getName());
if (bda != null && !bda.getBeansXml().getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
WebBundleDescriptor wDesc = context.getModuleMetaData(WebBundleDescriptor.class);
if( wDesc != null) {
wDesc.setExtensionProperty(WELD_EXTENSION, "true");
// Add the Weld Listener. We have to do it here too in case addWeldListenerToAllWars wasn't
// able to do it.
wDesc.addAppListenerDescriptorToFirst(new AppListenerDescriptorImpl(WELD_LISTENER));
// Add Weld Context Listener - this listener will ensure the WeldELContextListener is used
// for JSP's..
wDesc.addAppListenerDescriptor(new AppListenerDescriptorImpl(WELD_CONTEXT_LISTENER));
// Weld 2.2.1.Final. There is a tck test for this: org.jboss.cdi.tck.tests.context.session.listener.SessionContextHttpSessionListenerTest
// This WeldTerminationListener must come after all application-defined listeners
wDesc.addAppListenerDescriptor(new AppListenerDescriptorImpl(WELD_TERMINATION_LISTENER));
// Adding Weld ConverstationFilter if there is filterMapping for it and it doesn't exist already.
// However, it will be applied only if web.xml has mapping for it.
// Doing this here to make sure that its done only for CDI enabled web application
for (ServletFilterMapping sfMapping : wDesc.getServletFilterMappings()) {
String displayName = ((ServletFilterMappingDescriptor)sfMapping).getDisplayName();
if (WELD_CONVERSATION_FILTER_NAME.equals(displayName)) {
ServletFilterDescriptor ref = new ServletFilterDescriptor();
ref.setClassName(WELD_CONVERSATION_FILTER_CLASS);
ref.setName(WELD_CONVERSATION_FILTER_NAME);
wDesc.addServletFilter(ref);
break;
}
}
}
BundleDescriptor bundle = (wDesc != null) ? wDesc : ejbBundle;
if( bundle != null) {
// if (bda.getBeanDeploymentArchives().size() > 0 && !bda.getBeansXml().getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
if (!bda.getBeansXml().getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
// Register EE injection manager at the bean deployment archive level.
// We use the generic InjectionService service to handle all EE-style
// injection instead of the per-dependency-type InjectionPoint approach.
// Each InjectionServicesImpl instance knows its associated GlassFish bundle.
InjectionManager injectionMgr = services.getService(InjectionManager.class);
InjectionServices injectionServices = new InjectionServicesImpl(injectionMgr, bundle, deploymentImpl);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
CDILoggerInfo.ADDING_INJECTION_SERVICES,
new Object [] {injectionServices, bda.getId()});
}
bda.getServices().add(InjectionServices.class, injectionServices);
//Relevant in WAR BDA - WEB-INF/lib BDA scenarios
for(BeanDeploymentArchive subBda: bda.getBeanDeploymentArchives()){
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
CDILoggerInfo.ADDING_INJECTION_SERVICES,
new Object [] {injectionServices, subBda.getId()});
}
subBda.getServices().add(InjectionServices.class, injectionServices);
}
}
bundleToBeanDeploymentArchive.put(bundle, bda);
}
}
WeldApplicationContainer wbApp = new WeldApplicationContainer();
// Stash the WeldBootstrap instance, so we may access the WeldManager later..
//context.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
appInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
return wbApp;
}