use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class DeploymentImpl method createModuleBda.
private void createModuleBda(ReadableArchive archive, Collection<EjbDescriptor> ejbs, DeploymentContext context, String moduleName) {
RootBeanDeploymentArchive rootBda = new RootBeanDeploymentArchive(archive, ejbs, context, moduleName);
BeanDeploymentArchive moduleBda = rootBda.getModuleBda();
BeansXml moduleBeansXml = moduleBda.getBeansXml();
if (moduleBeansXml == null || !moduleBeansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
addBdaToDeploymentBdas(rootBda);
addBdaToDeploymentBdas(moduleBda);
addBeanDeploymentArchives(rootBda);
}
// first check if the parent is an ear and if so see if there are app libs defined there.
if (!earContextAppLibBdasProcessed && context instanceof DeploymentContextImpl) {
DeploymentContextImpl deploymentContext = (DeploymentContextImpl) context;
DeploymentContext parentContext = deploymentContext.getParentContext();
if (parentContext != null) {
processBdasForAppLibs(parentContext.getSource(), parentContext);
parentContext.getSource();
earContextAppLibBdasProcessed = true;
}
}
// then check the module
processBdasForAppLibs(archive, context);
}
use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class ValidationNamingProxy method obtainBeanManager.
/**
* Obtain the BeanManagerNamingProxy from hk2, so the BeanManager can be looked up
*
* @throws NamingException
*/
private synchronized BeanManager obtainBeanManager() throws NamingException {
BeanManager beanManager = null;
// Use invocation context to find applicable BeanDeploymentArchive.
ComponentInvocation inv = invocationManager.getCurrentInvocation();
if (inv != null) {
JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId());
if (componentEnv != null) {
BundleDescriptor bundle = null;
if (componentEnv instanceof EjbDescriptor) {
bundle = (BundleDescriptor) ((EjbDescriptor) componentEnv).getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
} else if (componentEnv instanceof WebBundleDescriptor) {
bundle = (BundleDescriptor) componentEnv;
}
if (bundle != null) {
BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle);
if (bda != null) {
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication());
beanManager = bootstrap.getManager(bda);
}
}
}
}
return beanManager;
}
use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class WeldDeployer method processApplicationLoaded.
private void processApplicationLoaded(ApplicationInfo applicationInfo) {
WeldBootstrap bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
if (bootstrap != null) {
DeploymentImpl deploymentImpl = applicationInfo.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
deploymentImpl.buildDeploymentGraph();
List<BeanDeploymentArchive> archives = deploymentImpl.getBeanDeploymentArchives();
addResourceLoaders(archives);
addCdiServicesToNonModuleBdas(deploymentImpl.getLibJarRootBdas(), services.getService(InjectionManager.class));
addCdiServicesToNonModuleBdas(deploymentImpl.getRarRootBdas(), services.getService(InjectionManager.class));
// Get current TCL
ClassLoader oldTCL = Thread.currentThread().getContextClassLoader();
invocationManager.pushAppEnvironment(() -> applicationInfo.getName());
ComponentInvocation componentInvocation = createComponentInvocation(applicationInfo);
try {
bootstrap.startExtensions(postProcessExtensions(deploymentImpl.getExtensions(), archives));
bootstrap.startContainer(deploymentImpl.getContextId() + ".bda", SERVLET, deploymentImpl);
bootstrap.startInitialization();
fireProcessInjectionTargetEvents(bootstrap, deploymentImpl);
bootstrap.deployBeans();
bootstrap.validateBeans();
invocationManager.preInvoke(componentInvocation);
bootstrap.endInitialization();
} catch (Throwable t) {
doBootstrapShutdown(applicationInfo);
throw new DeploymentException(getDeploymentErrorMsgPrefix(t) + t.getMessage(), t);
} finally {
invocationManager.postInvoke(componentInvocation);
invocationManager.popAppEnvironment();
// The TCL is originally the EAR classloader and is reset during Bean deployment to the
// corresponding module classloader in BeanDeploymentArchiveImpl.getBeans
// for Bean classloading to succeed.
// The TCL is reset to its old value here.
Thread.currentThread().setContextClassLoader(oldTCL);
deploymentComplete(deploymentImpl);
}
}
}
use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class JCDIServiceImpl method createInterceptorInstance.
/**
* @param <T> interceptor type
* @param interceptorClass The interceptor class.
* @param ejb The ejb descriptor.
* @param ejbContext The ejb jcdi context. This context is only used to store any contexts for interceptors
* not bound to the ejb. Nothing else in this context will be used in this method as they are
* most likely null.
* @param ejbInterceptors All of the ejb interceptors for the ejb.
*
* @return The interceptor instance.
*/
@Override
@SuppressWarnings("unchecked")
public <T> T createInterceptorInstance(Class<T> interceptorClass, EjbDescriptor ejb, JCDIService.JCDIInjectionContext<T> ejbContext, Set<EjbInterceptor> ejbInterceptors) {
BundleDescriptor topLevelBundleDesc = (BundleDescriptor) ejb.getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
// First get BeanDeploymentArchive for this ejb
BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName());
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication());
WeldManager beanManager = bootstrap.getManager(bda);
org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = beanManager.getEjbDescriptor(ejb.getName());
// get or create the ejb's creational context
CreationalContext<T> creationalContext = ejbContext.getCreationalContext();
if (creationalContext == null) {
// We have to do this because interceptors are created before the ejb but in certain cases we must associate
// the interceptors with the ejb so that they are cleaned up correctly.
// And we only want to create the ejb's creational context once or we will have a memory
// leak there too.
Bean<T> bean = beanManager.getBean(ejbDesc);
creationalContext = beanManager.createCreationalContext(bean);
ejbContext.setCreationalContext(creationalContext);
}
// first see if there's an Interceptor object defined for the interceptorClass
// This happens when @Interceptor or @InterceptorBinding is used.
Interceptor<T> interceptor = findEjbInterceptor(interceptorClass, ejbInterceptors);
if (interceptor != null) {
// using the ejb's creationalContext so we don't have to do any cleanup.
// the cleanup will be handled by weld when it clean's up the ejb.
Object instance = beanManager.getReference(interceptor, interceptorClass, creationalContext);
return (T) instance;
}
// Check to see if the interceptor was defined as a Bean.
// This can happen when using @Interceptors to define the interceptors.
Set<Bean<?>> availableBeans = beanManager.getBeans(interceptorClass);
if (availableBeans != null && !availableBeans.isEmpty()) {
// using the ejb's creationalContext so we don't have to do any cleanup.
// the cleanup will be handled by weld when it clean's up the ejb.
Bean<?> interceptorBean = beanManager.resolve(availableBeans);
Object instance = beanManager.getReference(interceptorBean, interceptorClass, creationalContext);
return (T) instance;
}
// There are other interceptors like SessionBeanInterceptor that are
// defined via code and they are not beans.
// Cannot use the ejb's creationalContext.
creationalContext = beanManager.createCreationalContext(null);
AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(interceptorClass);
InjectionTarget<T> it = beanManager.getInjectionTargetFactory(annotatedType).createInterceptorInjectionTarget();
T interceptorInstance = it.produce(creationalContext);
it.inject(interceptorInstance, creationalContext);
// make sure the interceptor's cdi objects get cleaned up when the ejb is cleaned up.
ejbContext.addDependentContext(new JCDIInjectionContextImpl<>(it, creationalContext, interceptorInstance));
return interceptorInstance;
}
use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class BeanDeploymentArchiveImpl method formatAccessibleBDAs.
private String formatAccessibleBDAs(BeanDeploymentArchive bda) {
StringBuffer sb = new StringBuffer("[");
for (BeanDeploymentArchive accessibleBDA : bda.getBeanDeploymentArchives()) {
if (accessibleBDA instanceof BeanDeploymentArchiveImpl) {
sb.append(((BeanDeploymentArchiveImpl) accessibleBDA).getFriendlyId()).append(",");
}
}
sb.append("]");
return sb.toString();
}
Aggregations