use of org.glassfish.weld.services.InjectionServicesImpl in project Payara by payara.
the class DeploymentImpl method loadBeanDeploymentArchive.
@Override
public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE, new Object[] { beanClass });
}
List<BeanDeploymentArchive> beanDeploymentArchives = getBeanDeploymentArchives();
ListIterator<BeanDeploymentArchive> lIter = beanDeploymentArchives.listIterator();
while (lIter.hasNext()) {
BeanDeploymentArchive bda = lIter.next();
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_CHECKING, new Object[] { beanClass, bda.getId() });
}
if (((BeanDeploymentArchiveImpl) bda).getModuleBeanClasses().contains(beanClass.getName())) {
// as Weld automatically add theses classes to the BDA's bean Classes
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_ADD_TO_EXISTING, new Object[] { beanClass.getName(), bda });
}
return bda;
}
// and get the right BDA for the beanClass
if (!bda.getBeanDeploymentArchives().isEmpty()) {
for (BeanDeploymentArchive subBda : bda.getBeanDeploymentArchives()) {
Collection<String> moduleBeanClassNames = ((BeanDeploymentArchiveImpl) subBda).getModuleBeanClasses();
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_CHECKING_SUBBDA, new Object[] { beanClass, subBda.getId() });
}
boolean match = moduleBeanClassNames.contains(beanClass.getName());
if (match) {
// as Weld automatically add theses classes to the BDA's bean Classes
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_ADD_TO_EXISTING, new Object[] { beanClass.getName(), subBda });
}
return subBda;
}
}
}
}
BeanDeploymentArchive extensionBDA = extensionBDAMap.get(beanClass.getClassLoader());
if (extensionBDA != null) {
return extensionBDA;
}
// If the BDA was not found for the Class, create one and add it
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_CREATE_NEW_BDA, new Object[] { beanClass });
}
List<Class<?>> beanClasses = new ArrayList<>();
List<URL> beanXMLUrls = new CopyOnWriteArrayList<>();
Set<EjbDescriptor> ejbs = new HashSet<>();
beanClasses.add(beanClass);
BeanDeploymentArchive newBda = new BeanDeploymentArchiveImpl(beanClass.getName(), beanClasses, beanXMLUrls, ejbs, context);
// have to create new InjectionServicesImpl for each new BDA so injection context is propagated for the correct bundle
newBda.getServices().add(InjectionServices.class, new InjectionServicesImpl(injectionManager, DOLUtils.getCurrentBundleForContext(context), this));
BeansXml beansXml = newBda.getBeansXml();
if (beansXml == null || !beansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_ADD_NEW_BDA_TO_ROOTS, new Object[] {});
}
lIter = beanDeploymentArchives.listIterator();
while (lIter.hasNext()) {
BeanDeploymentArchive bda = lIter.next();
bda.getBeanDeploymentArchives().add(newBda);
}
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_RETURNING_NEWLY_CREATED_BDA, new Object[] { beanClass, newBda });
}
beanDeploymentArchives.add(newBda);
idToBeanDeploymentArchive.put(newBda.getId(), newBda);
extensionBDAMap.put(beanClass.getClassLoader(), newBda);
return newBda;
}
return null;
}
use of org.glassfish.weld.services.InjectionServicesImpl in project Payara by payara.
the class WeldDeployer method load.
/**
* Processing in this method is performed for each module that is in the process of being loaded by
* the container.
*
* <p>
* This method will collect information from each archive (module) and produce
* <code>BeanDeploymentArchive</code> information for each module.
* </p>
*
* <p>
* The
* <code>BeanDeploymentArchive</code>s are stored in the <code>Deployment</code> (that will
* eventually be handed off to <code>Weld</code>. Once this method is called for all modules (and
* <code>BeanDeploymentArchive</code> information has been collected for all <code>Weld</code>
* modules), a relationship structure is produced defining the accessiblity rules for the
* <code>BeanDeploymentArchive</code>s.
* </p>
*
* @param container
* @param context
* @return
*/
@Override
public WeldApplicationContainer load(WeldContainer container, DeploymentContext context) {
DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
ApplicationInfo applicationInfo = applicationRegistry.get(deployParams.name);
ReadableArchive archive = context.getSource();
boolean[] setTransientAppMetaData = { false };
// See if a WeldBootsrap has already been created - only want one per app.
WeldBootstrap bootstrap = getWeldBootstrap(context, applicationInfo, setTransientAppMetaData);
EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
EjbServices ejbServices = null;
Set<EjbDescriptor> ejbs = new HashSet<>();
if (ejbBundle != null) {
ejbs.addAll(ejbBundle.getEjbs());
ejbServices = new EjbServicesImpl(services);
}
// Create a deployment collecting information from the ReadableArchive (archive)
// If the archive is a composite, or has version numbers per maven conventions, strip them out
String archiveName = getArchiveName(context, applicationInfo, archive);
DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
if (deploymentImpl == null) {
deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory, archiveName, services.getService(InjectionManager.class));
// 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, archiveName);
}
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);
}
DeployCommandParameters dc = context.getCommandParameters(DeployCommandParameters.class);
ExternalConfigurationImpl externalConfiguration = new ExternalConfigurationImpl();
externalConfiguration.setRollingUpgradesDelimiter(System.getProperty("fish.payara.rollingUpgradesDelimiter", ":"));
externalConfiguration.setBeanIndexOptimization(dc != null ? !dc.isAvailabilityEnabled() : true);
deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration);
BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName);
if (beanDeploymentArchive != null && !beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
if (setTransientAppMetaData[0]) {
// Do this only if we have a root BDA
appToBootstrap.put(context.getModuleMetaData(Application.class), bootstrap);
applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
}
WebBundleDescriptor webBundleDescriptor = context.getModuleMetaData(WebBundleDescriptor.class);
boolean developmentMode = isDevelopmentMode(context);
if (webBundleDescriptor != null) {
webBundleDescriptor.setExtensionProperty(WELD_EXTENSION, "true");
// Add the Weld Listener. We have to do it here too in case addWeldListenerToAllWars wasn't
// able to do it.
webBundleDescriptor.addAppListenerDescriptorToFirst(new AppListenerDescriptorImpl(WELD_LISTENER));
// Add Weld Context Listener - this listener will ensure the WeldELContextListener is used
// for JSP's..
webBundleDescriptor.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
webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WeldTerminationListenerProxy.class.getName()));
// Adding Weld ConverstationFilter if there is a filterMapping for it and it doesn't exist already.
// However, it will be applied only if web.xml has a mapping for it.
// Doing this here to make sure that its done only for CDI enabled web applications
registerWeldConversationFilter(webBundleDescriptor);
// every deployment
if (developmentMode) {
registerProbeFilter(webBundleDescriptor);
}
}
if (developmentMode) {
registerProbeExtension(externalConfiguration, deploymentImpl);
}
BundleDescriptor bundle = (webBundleDescriptor != null) ? webBundleDescriptor : ejbBundle;
if (bundle != null) {
if (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(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.
InjectionServices injectionServices = new InjectionServicesImpl(deploymentImpl.injectionManager, bundle, deploymentImpl);
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, beanDeploymentArchive.getId() });
}
beanDeploymentArchive.getServices().add(InjectionServices.class, injectionServices);
EEModuleDescriptor eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
if (eeModuleDescriptor != null) {
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
// Relevant in WAR BDA - WEB-INF/lib BDA scenarios
for (BeanDeploymentArchive subBda : beanDeploymentArchive.getBeanDeploymentArchives()) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, subBda.getId() });
}
subBda.getServices().add(InjectionServices.class, injectionServices);
// Should not be subBda?
eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
if (eeModuleDescriptor != null) {
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
}
}
bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
}
}
context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
return new WeldApplicationContainer();
}
Aggregations