use of org.apache.webbeans.spi.BeanArchiveService in project tomee by apache.
the class CdiScanner method init.
@Override
public void init(final Object object) {
if (!StartupObject.class.isInstance(object)) {
return;
}
containerLoader = ParentClassLoaderFinder.Helper.get();
final StartupObject startupObject = StartupObject.class.cast(object);
final AppInfo appInfo = startupObject.getAppInfo();
final ClassLoader classLoader = startupObject.getClassLoader();
final ClassLoaderComparator comparator;
if (classLoader instanceof ClassLoaderComparator) {
comparator = (ClassLoaderComparator) classLoader;
} else {
comparator = new DefaultClassLoaderComparator(classLoader);
}
final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();
// app beans
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
final BeansInfo beans = ejbJar.beans;
if (beans == null || "false".equalsIgnoreCase(ejbJar.properties.getProperty("openejb.cdi.activated"))) {
continue;
}
if (startupObject.isFromWebApp()) {
// deploy only the related ejbmodule
if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
continue;
}
} else if (ejbJar.webapp && !appInfo.webAppAlone) {
continue;
}
if (appInfo.webAppAlone || !ejbJar.webapp) {
// "manual" extension to avoid to add it through SPI mecanism
classes.addAll(asList(TRANSACTIONAL_INTERCEPTORS));
for (final Class<?> interceptor : TRANSACTIONAL_INTERCEPTORS) {
interceptorsManager.addEnabledInterceptorClass(interceptor);
}
}
// here for ears we need to skip classes in the parent classloader
final ClassLoader scl = ClassLoader.getSystemClassLoader();
final boolean filterByClassLoader = "true".equals(ejbJar.properties.getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true")));
final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);
final Map<BeansInfo.BDAInfo, BeanArchiveService.BeanArchiveInformation> infoByBda = new HashMap<>();
for (final BeansInfo.BDAInfo bda : beans.bdas) {
if (bda.uri != null) {
try {
beansXml.add(bda.uri.toURL());
} catch (final MalformedURLException e) {
// no-op
}
}
infoByBda.put(bda, handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda));
}
for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
// infoByBda.put() not needed since we know it means annotated
handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda);
}
if (startupObject.getBeanContexts() != null) {
for (final BeanContext bc : startupObject.getBeanContexts()) {
final String name = bc.getBeanClass().getName();
if (BeanContext.Comp.class.getName().equals(name)) {
continue;
}
boolean cdi = false;
for (final BeansInfo.BDAInfo bda : beans.bdas) {
final BeanArchiveService.BeanArchiveInformation info = infoByBda.get(bda);
if (info.getBeanDiscoveryMode() == BeanArchiveService.BeanDiscoveryMode.NONE) {
continue;
}
if (bda.managedClasses.contains(name)) {
classes.add(load(name, classLoader));
cdi = true;
break;
}
}
if (!cdi) {
for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
if (bda.managedClasses.contains(name)) {
classes.add(load(name, classLoader));
break;
}
}
}
}
}
if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.cdi.debug", "false"))) {
final Logger logger = Logger.getInstance(LogCategory.OPENEJB, CdiScanner.class.getName());
logger.info("CDI beans for " + startupObject.getAppInfo().appId + (startupObject.getWebContext() != null ? " webcontext = " + startupObject.getWebContext().getContextRoot() : ""));
final List<String> names = new ArrayList<>(classes.size());
for (final Class<?> c : classes) {
names.add(c.getName());
}
Collections.sort(names);
for (final String c : names) {
logger.info(" " + c);
}
}
}
}
Aggregations