[weld-commits] Weld SVN: r5894 - in core/trunk/impl/src/main/java/org/jboss/weld: manager and 2 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Sat Feb 20 13:44:01 EST 2010
Author: pete.muir at jboss.org
Date: 2010-02-20 13:44:00 -0500 (Sat, 20 Feb 2010)
New Revision: 5894
Added:
core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagers.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/manager/Transform.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
Log:
WELD-304
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-02-20 18:05:53 UTC (rev 5893)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -419,7 +419,7 @@
for (String name : namedAccessibleBeans.keySet())
{
- Set<Bean<?>> resolvedBeans = beanManager.getBeanResolver().resolve(Beans.removeDisabledAndSpecializedBeans(namedAccessibleBeans.get(name), beanManager.getEnabledAlternativeClasses(), beanManager.getEnabledAlternativeStereotypes(), beanManager.getSpecializedBeans()));
+ Set<Bean<?>> resolvedBeans = beanManager.getBeanResolver().resolve(Beans.removeDisabledAndSpecializedBeans(namedAccessibleBeans.get(name), beanManager));
if (resolvedBeans.size() > 1)
{
throw new DeploymentException(AMBIGUOUS_EL_NAME, name, resolvedBeans);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-02-20 18:05:53 UTC (rev 5893)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -28,6 +28,7 @@
import static org.jboss.weld.logging.messages.BeanManagerMessage.TOO_MANY_ACTIVITIES;
import static org.jboss.weld.logging.messages.BeanManagerMessage.UNPROXYABLE_RESOLUTION;
import static org.jboss.weld.logging.messages.BeanManagerMessage.UNRESOLVABLE_ELEMENT;
+import static org.jboss.weld.manager.BeanManagers.buildAccessibleClosure;
import java.io.Serializable;
import java.lang.annotation.Annotation;
@@ -385,22 +386,8 @@
this.childActivities = new CopyOnWriteArraySet<BeanManagerImpl>();
}
- private <T> Set<Iterable<T>> buildAccessibleClosure(Collection<BeanManagerImpl> hierarchy, Transform<T> transform)
- {
- Set<Iterable<T>> result = new HashSet<Iterable<T>>();
- hierarchy.add(this);
- result.add(transform.transform(this));
- for (BeanManagerImpl beanManager : accessibleManagers)
- {
- // Only add if we aren't already in the tree (remove cycles)
- if (!hierarchy.contains(beanManager))
- {
- result.addAll(beanManager.buildAccessibleClosure(new ArrayList<BeanManagerImpl>(hierarchy), transform));
- }
- }
- return result;
- }
+
private <T> Iterable<T> createDynamicAccessibleIterable(final Transform<T> transform)
{
return new Iterable<T>()
@@ -408,7 +395,7 @@
public Iterator<T> iterator()
{
- Set<Iterable<T>> iterable = buildAccessibleClosure(new ArrayList<BeanManagerImpl>(), transform);
+ Set<Iterable<T>> iterable = buildAccessibleClosure(BeanManagerImpl.this, new ArrayList<BeanManagerImpl>(), transform);
return Iterators.concat(Iterators.transform(iterable.iterator(), IterableToIteratorFunction.<T>instance()));
}
@@ -417,7 +404,7 @@
private <T> Iterable<T> createStaticAccessibleIterable(final Transform<T> transform)
{
- Set<Iterable<T>> iterable = buildAccessibleClosure(new ArrayList<BeanManagerImpl>(), transform);
+ Set<Iterable<T>> iterable = buildAccessibleClosure(this, new ArrayList<BeanManagerImpl>(), transform);
return Iterables.concat(iterable);
}
@@ -426,6 +413,11 @@
accessibleManagers.add(accessibleBeanManager);
beanResolver.clear();
}
+
+ public HashSet<BeanManagerImpl> getAccessibleManagers()
+ {
+ return accessibleManagers;
+ }
public void addBean(Bean<?> bean)
{
Added: core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagers.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagers.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagers.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -0,0 +1,51 @@
+package org.jboss.weld.manager;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public class BeanManagers
+{
+
+ private static class BeanManagerTransform implements Transform<BeanManagerImpl>
+ {
+
+ public static final BeanManagerTransform INSTANCE = new BeanManagerTransform();
+
+ public Iterable<BeanManagerImpl> transform(BeanManagerImpl beanManager)
+ {
+ return beanManager.getAccessibleManagers();
+ }
+
+ }
+
+ private BeanManagers() {}
+
+ public static Set<Iterable<BeanManagerImpl>> getAccessibleClosure(BeanManagerImpl beanManager)
+ {
+ Set<Iterable<BeanManagerImpl>> beanManagers = new HashSet<Iterable<BeanManagerImpl>>();
+ beanManagers.add(Collections.singleton(beanManager));
+ beanManagers.addAll(buildAccessibleClosure(beanManager, new HashSet<BeanManagerImpl>(), BeanManagerTransform.INSTANCE));
+ return beanManagers;
+ }
+
+ public static <T> Set<Iterable<T>> buildAccessibleClosure(BeanManagerImpl beanManager, Collection<BeanManagerImpl> hierarchy, Transform<T> transform)
+ {
+ Set<Iterable<T>> result = new HashSet<Iterable<T>>();
+ hierarchy.add(beanManager);
+ result.add(transform.transform(beanManager));
+ for (BeanManagerImpl accessibleBeanManager : beanManager.getAccessibleManagers())
+ {
+ // Only add if we aren't already in the tree (remove cycles)
+ if (!hierarchy.contains(accessibleBeanManager))
+ {
+ result.addAll(buildAccessibleClosure(accessibleBeanManager, new ArrayList<BeanManagerImpl>(hierarchy), transform));
+ }
+ }
+ return result;
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagers.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: core/trunk/impl/src/main/java/org/jboss/weld/manager/Transform.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/Transform.java 2010-02-20 18:05:53 UTC (rev 5893)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/Transform.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -16,7 +16,7 @@
*/
package org.jboss.weld.manager;
-interface Transform<T>
+public interface Transform<T>
{
public Iterable<T> transform(BeanManagerImpl beanManager);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java 2010-02-20 18:05:53 UTC (rev 5893)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -58,7 +58,7 @@
matchedBeans.add(bean);
}
}
- return Beans.removeDisabledAndSpecializedBeans(matchedBeans, beanManager.getEnabledAlternativeClasses(), beanManager.getEnabledAlternativeStereotypes(), beanManager.getSpecializedBeans());
+ return Beans.removeDisabledAndSpecializedBeans(matchedBeans, beanManager);
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java 2010-02-20 18:05:53 UTC (rev 5893)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -105,7 +105,7 @@
@Override
protected Set<T> filterResult(Set<T> matched)
{
- return Beans.removeDisabledAndSpecializedBeans(matched, beanManager.getEnabledAlternativeClasses(), beanManager.getEnabledAlternativeStereotypes(), getBeanManager().getSpecializedBeans());
+ return Beans.removeDisabledAndSpecializedBeans(matched, beanManager);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2010-02-20 18:05:53 UTC (rev 5893)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2010-02-20 18:44:00 UTC (rev 5894)
@@ -54,7 +54,6 @@
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;
@@ -91,6 +90,7 @@
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.manager.BeanManagers;
import org.jboss.weld.metadata.cache.InterceptorBindingModel;
import org.jboss.weld.metadata.cache.MergedStereotypes;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
@@ -580,7 +580,7 @@
* @param enabledDeploymentTypes The enabled deployment types
* @return The filtered beans
*/
- public static <T extends Bean<?>> Set<T> removeDisabledAndSpecializedBeans(Set<T> beans, Collection<Class<?>> enabledAlternativeClasses, Collection<Class<? extends Annotation>> enabledAlternativeSterotypes, Map<Contextual<?>, Contextual<?>> specializedBeans)
+ public static <T extends Bean<?>> Set<T> removeDisabledAndSpecializedBeans(Set<T> beans, BeanManagerImpl beanManager)
{
if (beans.size() == 0)
{
@@ -591,7 +591,7 @@
Set<T> result = new HashSet<T>();
for (T bean : beans)
{
- if (isBeanEnabled(bean, enabledAlternativeClasses, enabledAlternativeSterotypes) && !isSpecialized(bean, beans, specializedBeans))
+ if (isBeanEnabled(bean, beanManager.getEnabledAlternativeClasses(), beanManager.getEnabledAlternativeStereotypes()) && !isSpecialized(bean, beans, beanManager))
{
result.add(bean);
}
@@ -661,16 +661,22 @@
*
* @param bean
* @param beans
- * @param specializedBeans
+ * @param allSpecializedBeans
* @return
*/
- public static <T extends Bean<?>> boolean isSpecialized(T bean, Set<T> beans, Map<Contextual<?>, Contextual<?>> specializedBeans)
+ public static <T extends Bean<?>> boolean isSpecialized(T bean, Set<T> beans, BeanManagerImpl beanManager)
{
- if (specializedBeans.containsKey(bean))
+ for (Iterable<BeanManagerImpl> beanManagers : BeanManagers.getAccessibleClosure(beanManager))
{
- if (beans.contains(specializedBeans.get(bean)))
+ for (BeanManagerImpl accessibleBeanManager : beanManagers)
{
- return true;
+ if (accessibleBeanManager.getSpecializedBeans().containsKey(bean))
+ {
+ if (beans.contains(accessibleBeanManager.getSpecializedBeans().get(bean)))
+ {
+ return true;
+ }
+ }
}
}
return false;
More information about the weld-commits
mailing list