/** * @param manager * @return the number of enabled beans, without built-in, extensions, interceptors, decorators */ static Integer getNumberOfEnabledBeans(BeanManagerImpl manager) { List<Bean<?>> enabledBeans = manager.getBeans(); int count = 0; for (Bean<?> bean : enabledBeans) { if (!Components.isBuiltinBeanButNotExtension(bean)) { count++; } } return count; }
/** * @param bean * @param probe * @return the set of dependents */ static Set<Dependency> getDependents(Bean<?> bean, Probe probe) { Set<Dependency> dependents = new HashSet<Dependency>(); for (Bean<?> candidate : probe.getBeans()) { if (candidate.equals(bean)) { continue; } BeanManager beanManager = probe.getBeanManager(candidate); if (beanManager == null) { // Don't process built-in beans continue; } Set<InjectionPoint> injectionPoints = candidate.getInjectionPoints(); if (injectionPoints != null && !injectionPoints.isEmpty()) { for (InjectionPoint injectionPoint : injectionPoints) { // At this point unsatisfied or ambiguous dependency should not exits Bean<?> candidateDependency = beanManager.resolve( beanManager.getBeans( injectionPoint.getType(), injectionPoint .getQualifiers() .toArray(new Annotation[injectionPoint.getQualifiers().size()]))); boolean satisfies = false; if (isBuiltinBeanButNotExtension(candidateDependency)) { satisfies = bean.equals( probe.getBean( Components.getBuiltinBeanId((AbstractBuiltInBean<?>) candidateDependency))); } else { satisfies = bean.equals(candidateDependency); } if (satisfies) { dependents.add(new Dependency(candidate, injectionPoint)); } } } } return dependents; }
/** * @param bean * @param beanManager * @param probe * @return the set of dependencies */ static Set<Dependency> getDependencies(Bean<?> bean, BeanManager beanManager, Probe probe) { Set<Dependency> dependencies = new HashSet<Dependency>(); Set<InjectionPoint> injectionPoints = bean.getInjectionPoints(); if (injectionPoints != null && !injectionPoints.isEmpty()) { for (InjectionPoint injectionPoint : injectionPoints) { // At this point unsatisfied or ambiguous dependency should not exits Bean<?> dependency = beanManager.resolve( beanManager.getBeans( injectionPoint.getType(), injectionPoint .getQualifiers() .toArray(new Annotation[injectionPoint.getQualifiers().size()]))); if (isBuiltinBeanButNotExtension(dependency)) { dependency = probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependency)); } dependencies.add(new Dependency(dependency, injectionPoint)); } } return dependencies; }
/** * @param bda * @param bean * @return true if the bda is null or the id of the BDA for the given bean equals to the value */ boolean testBda(String bda, Bean<?> bean) { if (bda == null) { return true; } if (bean == null) { return false; } BeanManagerImpl beanManagerImpl = probe.getBeanManager(bean); if (beanManagerImpl == null) { return false; } if (FILTER_ADDITIONAL_BDAS_MARKER.equals(bda)) { if (beanManagerImpl.getId().endsWith(ADDITIONAL_BDA_SUFFIX)) { return false; } } else { if (!Components.getId(beanManagerImpl.getId()).equals(bda)) { return false; } } return true; }