Search in sources :

Example 21 with BeanDeploymentArchive

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.
}
Also used : JCDIService(com.sun.enterprise.container.common.spi.JCDIService) EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) javax.enterprise.inject.spi(javax.enterprise.inject.spi) WeldManager(org.jboss.weld.manager.api.WeldManager) BaseContainer(com.sun.ejb.containers.BaseContainer) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WeldCreationalContext(org.jboss.weld.contexts.WeldCreationalContext) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 22 with BeanDeploymentArchive

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);
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Aggregations

BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)22 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)9 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)3 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 javax.enterprise.inject.spi (javax.enterprise.inject.spi)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 InjectionServicesImpl (org.glassfish.weld.services.InjectionServicesImpl)2 WeldManager (org.jboss.weld.manager.api.WeldManager)2 BaseContainer (com.sun.ejb.containers.BaseContainer)1 EJBContextImpl (com.sun.ejb.containers.EJBContextImpl)1 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)1 Application (com.sun.enterprise.deployment.Application)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1