use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class JCDIServiceImpl method _createJCDIInjectionContext.
// instance could be null. If null, create a new one
@SuppressWarnings("unchecked")
private <T> JCDIInjectionContext<T> _createJCDIInjectionContext(EjbDescriptor ejb, T instance, Map<Class<?>, Object> ejbInfo) {
BaseContainer baseContainer = null;
EJBContextImpl ejbContext = null;
JCDIInjectionContextImpl<T> jcdiCtx = null;
CreationalContext<T> creationalContext = null;
if (ejbInfo != null) {
baseContainer = (BaseContainer) ejbInfo.get(BaseContainer.class);
ejbContext = (EJBContextImpl) ejbInfo.get(EJBContextImpl.class);
}
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 weldManager = bootstrap.getManager(bda);
org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = weldManager.getEjbDescriptor(ejb.getName());
// get or create the ejb's creational context
if (null != ejbInfo) {
jcdiCtx = (JCDIInjectionContextImpl<T>) ejbInfo.get(JCDIService.JCDIInjectionContext.class);
}
if (null != jcdiCtx) {
creationalContext = jcdiCtx.getCreationalContext();
}
if (null != jcdiCtx && creationalContext == null) {
// The creational context may have been created by interceptors because they are created first
// (see createInterceptorInstance below.)
// And we only want to create the ejb's creational context once or we will have a memory
// leak there too.
Bean<T> bean = weldManager.getBean(ejbDesc);
creationalContext = weldManager.createCreationalContext(bean);
jcdiCtx.setCreationalContext(creationalContext);
}
// Create the injection target
InjectionTarget<T> it = weldManager.createInjectionTarget(ejbDesc);
if (null != jcdiCtx) {
jcdiCtx.setInjectionTarget(it);
}
// JJS: 7/20/17 We must perform the around_construct interception because Weld does not know about
// interceptors defined by descriptors.
WeldCreationalContext<T> weldCreationalContext = (WeldCreationalContext) creationalContext;
weldCreationalContext.setConstructorInterceptionSuppressed(true);
JCDIAroundConstructCallback<T> aroundConstructCallback = new JCDIAroundConstructCallback<>(baseContainer, ejbContext);
weldCreationalContext.registerAroundConstructCallback(aroundConstructCallback);
if (null != jcdiCtx) {
jcdiCtx.setJCDIAroundConstructCallback(aroundConstructCallback);
}
T beanInstance = instance;
if (beanInstance == null) {
// Create instance , perform constructor injection.
beanInstance = it.produce(creationalContext);
}
if (null != jcdiCtx) {
jcdiCtx.setInstance(beanInstance);
}
return jcdiCtx;
// Injection is not performed yet. Separate injectEJBInstance() call is required.
}
use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.
the class JCDIServiceImpl method createManagedObject.
@Override
public <T> JCDIInjectionContext<T> createManagedObject(Class<T> managedClass, BundleDescriptor bundle, boolean invokePostConstruct) {
T managedObject;
BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor();
// First get BeanDeploymentArchive for this ejb
BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc);
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication());
BeanManager beanManager = bootstrap.getManager(bda);
AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(managedClass);
if (!invokePostConstruct) {
annotatedType = new NoPostConstructPreDestroyAnnotatedType<>(annotatedType);
}
@SuppressWarnings("unchecked") InjectionTarget<T> it = (InjectionTarget<T>) ((BeanDeploymentArchiveImpl) bda).getInjectionTarget(annotatedType);
if (it == null) {
it = ((WeldManager) beanManager).fireProcessInjectionTarget(annotatedType);
}
CreationalContext<T> cc = beanManager.createCreationalContext(null);
managedObject = it.produce(cc);
it.inject(managedObject, cc);
if (invokePostConstruct) {
it.postConstruct(managedObject);
}
return new JCDIInjectionContextImpl<>(it, cc, managedObject);
}
Aggregations