*/
@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);
}
EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
EjbServices ejbServices = null;
Set<EjbDescriptor> ejbs = new HashSet<EjbDescriptor>();
if( ejbBundle != null ) {
ejbs.addAll(ejbBundle.getEjbs());
ejbServices = new EjbServicesImpl(services);
}
// Check if we already have a Deployment
DeploymentImpl deploymentImpl = context.getTransientAppMetaData(
WELD_DEPLOYMENT, DeploymentImpl.class);
// Create a Deployment Collecting Information From The ReadableArchive (archive)
if (deploymentImpl == null) {
deploymentImpl = new DeploymentImpl(archive, ejbs, context);
// Add services
TransactionServices transactionServices = new TransactionServicesImpl(services);
deploymentImpl.getServices().add(TransactionServices.class, transactionServices);
// JJS: commented out next 2 lines as the new hibernate validator provides this via their
// portable extensions.
//ValidationServices validationServices = new ValidationServicesImpl();
//deploymentImpl.getServices().add(ValidationServices.class, validationServices);
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);
} else {
deploymentImpl.scanArchive(archive, ejbs, context);
}
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());
WebBundleDescriptor wDesc = context.getModuleMetaData(WebBundleDescriptor.class);
if( wDesc != null) {
wDesc.setExtensionProperty(WELD_EXTENSION, "true");
// Add the Weld Listener if it does not already exist..
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));
}
BundleDescriptor bundle = (wDesc != null) ? wDesc : ejbBundle;
if( bundle != null ) {
// 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);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
CDILoggerInfo.ADDING_INJECTION_SERVICES,
new Object [] {injectionServices, bda.getId()});
}
bda.getServices().add(InjectionServices.class, injectionServices);
if (bda.getBeanDeploymentArchives().size() != 0) {
//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(bootstrap);
// 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;
}