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();
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations