Search in sources :

Example 11 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class BeanDeploymentArchiveImpl method toString.

// A graphical representation of the BDA hierarchy to aid in debugging
// and to provide a better representation of how Weld treats the deployed
// archive.
@Override
public String toString() {
    String beanClassesString = ((getBeanClasses().size() > 0) ? getBeanClasses().toString() : "");
    String initVal = "|ID: " + getId() + ", bdaType= " + bdaType + ", accessibleBDAs #:" + getBeanDeploymentArchives().size() + ", " + formatAccessibleBDAs(this) + ", Bean Classes #: " + getBeanClasses().size() + "," + beanClassesString + ", ejbs=" + getEjbs() + "\n";
    StringBuffer valBuff = new StringBuffer(initVal);
    Collection<BeanDeploymentArchive> bdas = getBeanDeploymentArchives();
    Iterator<BeanDeploymentArchive> iter = bdas.iterator();
    while (iter.hasNext()) {
        BeanDeploymentArchive bda = (BeanDeploymentArchive) iter.next();
        BDAType embedBDAType = BDAType.UNKNOWN;
        if (bda instanceof BeanDeploymentArchiveImpl) {
            embedBDAType = ((BeanDeploymentArchiveImpl) bda).getBDAType();
        }
        String embedBDABeanClasses = ((bda.getBeanClasses().size() > 0) ? bda.getBeanClasses().toString() : "");
        String val = "|---->ID: " + bda.getId() + ", bdaType= " + embedBDAType.toString() + ", accessibleBDAs #:" + bda.getBeanDeploymentArchives().size() + ", " + formatAccessibleBDAs(bda) + ", Bean Classes #: " + bda.getBeanClasses().size() + "," + embedBDABeanClasses + ", ejbs=" + bda.getEjbs() + "\n";
        valBuff.append(val);
    }
    return valBuff.toString();
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 12 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class DeploymentImpl method createLibJarBda.

private void createLibJarBda(RootBeanDeploymentArchive rootLibBda) {
    BeanDeploymentArchive libModuleBda = rootLibBda.getModuleBda();
    BeansXml moduleBeansXml = libModuleBda.getBeansXml();
    if (moduleBeansXml == null || !moduleBeansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
        addBdaToDeploymentBdas(rootLibBda);
        addBdaToDeploymentBdas(libModuleBda);
        if (libJarRootBdas == null) {
            libJarRootBdas = new ArrayList<>();
        }
        for (RootBeanDeploymentArchive existingLibJarRootBda : libJarRootBdas) {
            rootLibBda.getBeanDeploymentArchives().add(existingLibJarRootBda);
            rootLibBda.getBeanDeploymentArchives().add(existingLibJarRootBda.getModuleBda());
            rootLibBda.getModuleBda().getBeanDeploymentArchives().add(existingLibJarRootBda);
            rootLibBda.getModuleBda().getBeanDeploymentArchives().add(existingLibJarRootBda.getModuleBda());
            existingLibJarRootBda.getBeanDeploymentArchives().add(rootLibBda);
            existingLibJarRootBda.getBeanDeploymentArchives().add(rootLibBda.getModuleBda());
            existingLibJarRootBda.getModuleBda().getBeanDeploymentArchives().add(rootLibBda);
            existingLibJarRootBda.getModuleBda().getBeanDeploymentArchives().add(rootLibBda.getModuleBda());
        }
        libJarRootBdas.add(rootLibBda);
    }
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 13 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class DeploymentImpl method getExtensions.

@Override
public Iterable<Metadata<Extension>> getExtensions() {
    if (extensions != null) {
        return extensions;
    }
    List<BeanDeploymentArchive> bdas = getBeanDeploymentArchives();
    ArrayList<Metadata<Extension>> extnList = new ArrayList<>();
    for (BeanDeploymentArchive bda : bdas) {
        if (!(bda instanceof RootBeanDeploymentArchive)) {
            ClassLoader moduleClassLoader = ((BeanDeploymentArchiveImpl) bda).getModuleClassLoaderForBDA();
            extensions = context.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class).loadExtensions(moduleClassLoader);
            if (extensions != null) {
                for (Metadata<Extension> bdaExtn : extensions) {
                    extnList.add(bdaExtn);
                }
            }
        }
    }
    extnList.addAll(dynamicExtensions);
    return extnList;
}
Also used : Extension(javax.enterprise.inject.spi.Extension) Metadata(org.jboss.weld.bootstrap.spi.Metadata) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 14 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class DeploymentImpl method getBeanDeploymentArchive.

/**
 * Get a bda for the specified beanClass
 *
 * @param beanClass The beanClass to get the bda for.
 *
 * @return If the beanClass is in the archive represented by the bda
 * then return that bda.  Otherwise if the class loader of the beanClass matches the module class loader
 * of any of the root bdas then return that root bda.  Otherwise return null.
 */
public BeanDeploymentArchive getBeanDeploymentArchive(Class<?> beanClass) {
    if (beanClass == null) {
        return null;
    }
    for (BeanDeploymentArchive oneBda : beanDeploymentArchives) {
        BeanDeploymentArchiveImpl beanDeploymentArchiveImpl = (BeanDeploymentArchiveImpl) oneBda;
        if (beanDeploymentArchiveImpl.getBeanClassObjects().contains(beanClass)) {
            return oneBda;
        }
    }
    // find a root bda
    ClassLoader classLoader = beanClass.getClassLoader();
    RootBeanDeploymentArchive rootBda = findRootBda(classLoader, ejbRootBdas);
    if (rootBda == null) {
        rootBda = findRootBda(classLoader, warRootBdas);
        if (rootBda == null) {
            rootBda = findRootBda(classLoader, libJarRootBdas);
            if (rootBda == null) {
                rootBda = findRootBda(classLoader, rarRootBdas);
            }
        }
    }
    return rootBda;
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 15 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive 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;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) URL(java.net.URL) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) InjectionServicesImpl(org.glassfish.weld.services.InjectionServicesImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

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