Skip to content

Commit

Permalink
Check all possible beans for specializable.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Nov 18, 2011
1 parent 466b4ce commit 356c4a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Expand Up @@ -138,7 +138,7 @@ public AbstractBeanDeployer<E> deploy() {
for (ObserverMethodImpl<?, ?> observer : getEnvironment().getObservers()) {
Bean ob = observer.getDeclaringBean();
// make sure we're not specialized
if (manager.getSpecializedBeans().containsKey(ob) == false) {
if (Beans.isSpecialized(ob, manager) == false) {
log.debug(FOUND_OBSERVER_METHOD, observer);
observer.initialize();
ProcessObserverMethodImpl.fire(manager, observer);
Expand Down
36 changes: 28 additions & 8 deletions impl/src/main/java/org/jboss/weld/util/Beans.java
Expand Up @@ -60,6 +60,7 @@
import javax.annotation.PreDestroy;
import javax.decorator.Decorator;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Alternative;
Expand Down Expand Up @@ -558,18 +559,37 @@ public static boolean isAlternative(WeldAnnotated<?, ?> annotated, MergedStereot
/**
* Check if bean is specialized by any of beans
*
* @param bean
* @param beans
* @param allSpecializedBeans
* @return
* @param bean the bean to check
* @param beanManager bean manager
* @return true if bean is specialized by some bean in all beans
*/
public static <T extends Bean<?>> boolean isSpecialized(T bean, Set<T> beans, BeanManagerImpl beanManager) {
public static <T extends Bean<?>> boolean isSpecialized(T bean, BeanManagerImpl beanManager) {
for (Iterable<BeanManagerImpl> beanManagers : BeanManagers.getAccessibleClosure(beanManager)) {
for (BeanManagerImpl accessibleBeanManager : beanManagers) {
if (accessibleBeanManager.getSpecializedBeans().containsKey(bean)) {
if (beans.contains(accessibleBeanManager.getSpecializedBeans().get(bean))) {
return true;
}
return true;
}
}
}
return false;
}

/**
* Check if bean is specialized by any of beans
*
* @param bean the bean to check
* @param beans the possible specialized beans
* @param beanManager bean manager
* @return true if bean is specialized by some bean in beans
*/
public static <T extends Bean<?>> boolean isSpecialized(T bean, Set<T> beans, BeanManagerImpl beanManager) {
for (Iterable<BeanManagerImpl> beanManagers : BeanManagers.getAccessibleClosure(beanManager)) {
for (BeanManagerImpl accessibleBeanManager : beanManagers) {
Map<Contextual<?>, Contextual<?>> specializedBeans = accessibleBeanManager.getSpecializedBeans();
Contextual<?> specializedBean = specializedBeans.get(bean);
//noinspection SuspiciousMethodCalls
if (specializedBean != null && beans.contains(specializedBean)) {
return true;
}
}
}
Expand Down

0 comments on commit 356c4a6

Please sign in to comment.