Search in sources :

Example 41 with BeanDeploymentArchive

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

the class BeanDeploymentArchiveImpl method formatAccessibleBDAs.

private String formatAccessibleBDAs(BeanDeploymentArchive bda) {
    StringBuilder sb = new StringBuilder("[");
    for (BeanDeploymentArchive accessibleBDA : bda.getBeanDeploymentArchives()) {
        if (accessibleBDA instanceof BeanDeploymentArchiveImpl) {
            sb.append(((BeanDeploymentArchiveImpl) accessibleBDA).getFriendlyId()).append(",");
        }
    }
    sb.append("]");
    return sb.toString();
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 42 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 43 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 44 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));
    newBda.getServices().add(ResourceInjectionServices.class, new ResourceInjectionServicesImpl());
    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);
        // Make all previously found extension BDAs visible to this extension BDA
        newBda.getBeanDeploymentArchives().addAll(extensionBDAMap.values());
        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) ResourceInjectionServicesImpl(org.glassfish.weld.services.ResourceInjectionServicesImpl) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) InjectionServicesImpl(org.glassfish.weld.services.InjectionServicesImpl) ResourceInjectionServicesImpl(org.glassfish.weld.services.ResourceInjectionServicesImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 45 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<>();
    // Track classloaders to ensure we don't scan the same classloader twice
    HashSet<ClassLoader> scannedClassLoaders = new HashSet<>();
    // ensure we don't add the same extension twice
    HashMap<Class<?>, Metadata<Extension>> loadedExtensions = new HashMap<>();
    for (BeanDeploymentArchive bda : bdas) {
        if (!(bda instanceof RootBeanDeploymentArchive)) {
            ClassLoader moduleClassLoader = ((BeanDeploymentArchiveImpl) bda).getModuleClassLoaderForBDA();
            if (!scannedClassLoaders.contains(moduleClassLoader)) {
                scannedClassLoaders.add(moduleClassLoader);
                extensions = context.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class).loadExtensions(moduleClassLoader);
                if (extensions != null) {
                    for (Metadata<Extension> bdaExtn : extensions) {
                        if (loadedExtensions.get(bdaExtn.getValue().getClass()) == null) {
                            extnList.add(bdaExtn);
                            loadedExtensions.put(bdaExtn.getValue().getClass(), bdaExtn);
                        }
                    }
                }
            }
        }
    }
    // Load sniffer extensions
    @SuppressWarnings("unchecked") Iterable<Supplier<Extension>> snifferExtensions = context.getTransientAppMetaData(WeldDeployer.SNIFFER_EXTENSIONS, Iterable.class);
    if (snifferExtensions != null) {
        for (Supplier<Extension> extensionCreator : snifferExtensions) {
            final Extension extension = extensionCreator.get();
            final Class<?> extensionClass = extension.getClass();
            final Metadata<Extension> extensionMetadata = new MetadataImpl<>(extension, extensionClass.getName());
            extnList.add(extensionMetadata);
        }
    }
    extnList.addAll(dynamicExtensions);
    extensions = extnList;
    return extnList;
}
Also used : Metadata(org.jboss.weld.bootstrap.spi.Metadata) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Extension(javax.enterprise.inject.spi.Extension) MetadataImpl(org.jboss.weld.bootstrap.spi.helpers.MetadataImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) Supplier(java.util.function.Supplier)

Aggregations

BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)47 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)11 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 HashSet (java.util.HashSet)7 Deployment (org.jboss.weld.bootstrap.spi.Deployment)7 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)6 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)6 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)6 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)6 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)6 Test (org.testng.annotations.Test)6 BeanManager (javax.enterprise.inject.spi.BeanManager)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)4 Test (org.junit.Test)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 Metadata (org.jboss.weld.bootstrap.spi.Metadata)3 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2