Author: pete.muir(a)jboss.org
Date: 2009-06-08 12:26:44 -0400 (Mon, 08 Jun 2009)
New Revision: 2787
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/ResolvableAnnotatedItem.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/Resolver.java
Log:
More tidying
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-06-08 15:29:47
UTC (rev 2786)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-06-08 16:26:44
UTC (rev 2787)
@@ -457,46 +457,11 @@
public Set<Bean<?>> getBeans(Type beanType, Annotation... bindings)
{
- return (Set) resolveByType(ResolvableAnnotatedClass.of(beanType, bindings),
bindings);
+ return getBeans(ResolvableAnnotatedClass.of(beanType, bindings), bindings);
}
public Set<Bean<?>> getBeans(AnnotatedItem<?, ?> element,
Annotation... bindings)
{
- return (Set) resolveByType(element, bindings);
- }
-
- public Set<Bean<?>> getBeans(InjectionPoint injectionPoint)
- {
- boolean registerInjectionPoint =
!injectionPoint.getType().equals(InjectionPoint.class);
- try
- {
- if (registerInjectionPoint)
- {
- currentInjectionPoint.get().push(injectionPoint);
- }
- // TODO Do this properly
- return getBeans(ResolvableAnnotatedClass.of(injectionPoint.getType(),
injectionPoint.getBindings().toArray(new Annotation[0])));
- }
- finally
- {
- if (registerInjectionPoint)
- {
- currentInjectionPoint.get().pop();
- }
- }
- }
-
- /**
- * Check the resolution request is valid, and then ask the resolver to
- * perform the resolution. For internal use.
- *
- * @param element The item to resolve
- * @param bindings The binding types to match
- * @return The set of matching beans
- */
- @Deprecated
- public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?>
element, Annotation... bindings)
- {
for (Annotation annotation : element.getAnnotationsAsSet())
{
if
(!getServices().get(MetaDataCache.class).getBindingTypeModel(annotation.annotationType()).isValid())
@@ -522,6 +487,27 @@
return resolver.get(element);
}
+ public Set<Bean<?>> getBeans(InjectionPoint injectionPoint)
+ {
+ boolean registerInjectionPoint =
!injectionPoint.getType().equals(InjectionPoint.class);
+ try
+ {
+ if (registerInjectionPoint)
+ {
+ currentInjectionPoint.get().push(injectionPoint);
+ }
+ // TODO Do this properly
+ return getBeans(ResolvableAnnotatedClass.of(injectionPoint.getType(),
injectionPoint.getBindings().toArray(new Annotation[0])));
+ }
+ finally
+ {
+ if (registerInjectionPoint)
+ {
+ currentInjectionPoint.get().pop();
+ }
+ }
+ }
+
/**
* Wraps a collection of beans into a thread safe list. Since this overwrites
* any existing list of beans in the manager, this should only be done on
@@ -780,7 +766,7 @@
currentInjectionPoint.get().push(injectionPoint);
}
AnnotatedItem<?, ?> element =
ResolvableAnnotatedClass.of(injectionPoint.getType(),
injectionPoint.getBindings().toArray(new Annotation[0]));
- Bean<?> resolvedBean = getBeanByType(element,
element.getBindingsAsArray());
+ Bean<?> resolvedBean = getBean(element, element.getBindingsAsArray());
if
(getServices().get(MetaDataCache.class).getScopeModel(resolvedBean.getScopeType()).isNormal()
&& !Proxies.isTypeProxyable(injectionPoint.getType()))
{
throw new UnproxyableResolutionException("Attempting to inject an
unproxyable normal scoped bean " + resolvedBean + " into " +
injectionPoint);
@@ -881,13 +867,12 @@
@Deprecated
public <T> T getInstanceByType(AnnotatedItem<T, ?> element, Annotation...
bindings)
{
- return getInstance(getBeanByType(element, bindings));
+ return getInstance(getBean(element, bindings));
}
- @Deprecated
- public <T> Bean<T> getBeanByType(AnnotatedItem<T, ?> element,
Annotation... bindings)
+ private <T> Bean<T> getBean(AnnotatedItem<T, ?> element,
Annotation... bindings)
{
- Set<Bean<T>> beans = resolveByType(element, bindings);
+ Set<Bean<?>> beans = getBeans(element, bindings);
if (beans.size() == 0)
{
throw new UnsatisfiedResolutionException(element + "Unable to resolve any
Web Beans");
@@ -896,7 +881,7 @@
{
throw new AmbiguousResolutionException(element + "Resolved multiple Web
Beans");
}
- Bean<T> bean = beans.iterator().next();
+ Bean<T> bean = (Bean<T>) beans.iterator().next();
boolean normalScoped =
getServices().get(MetaDataCache.class).getScopeModel(bean.getScopeType()).isNormal();
if (normalScoped && !Beans.isBeanProxyable(bean))
{
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/ResolvableAnnotatedItem.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/ResolvableAnnotatedItem.java 2009-06-08
15:29:47 UTC (rev 2786)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/ResolvableAnnotatedItem.java 2009-06-08
16:26:44 UTC (rev 2787)
@@ -26,6 +26,18 @@
abstract class ResolvableAnnotatedItem<T, S> extends ForwardingAnnotatedItem<T,
S>
{
+ public static <T1, S1> ResolvableAnnotatedItem<T1, S1> of(final
AnnotatedItem<T1, S1> delegate)
+ {
+ return new ResolvableAnnotatedItem<T1, S1>()
+ {
+ @Override
+ protected AnnotatedItem<T1, S1> delegate()
+ {
+ return delegate;
+ }
+ };
+ }
+
private static final long serialVersionUID = 1L;
@Override
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/Resolver.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/Resolver.java 2009-06-08
15:29:47 UTC (rev 2786)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/resolution/Resolver.java 2009-06-08
16:26:44 UTC (rev 2787)
@@ -48,8 +48,6 @@
private static final long serialVersionUID = 1L;
private static final Class<AnnotatedItem<Object, Object>>
ANNOTATED_ITEM_GENERIFIED_WITH_OBJECT_OBJECT = new TypeLiteral<AnnotatedItem<Object,
Object>>(){}.getRawType();
- private static final Class<Set<Bean<Object>>>
BEAN_SET_GENERIFIED_WITH_OBJECT = new
TypeLiteral<Set<Bean<Object>>>(){}.getRawType();
- private static final Class<Set<Bean<?>>>
BEAN_SET_GENERIFIED_WITH_WILDCARD = new
TypeLiteral<Set<Bean<?>>>(){}.getRawType();
// The resolved injection points
private ConcurrentCache<ResolvableAnnotatedItem<?, ?>,
Set<Bean<?>>> resolvedInjectionPoints;
@@ -94,12 +92,12 @@
* @param element The injection point to add
* @return A set of matching beans for the injection point
*/
- private <T, S> Set<Bean<T>> registerInjectionPoint(final
ResolvableAnnotatedItem<T, S> element)
+ private Set<Bean<?>> registerInjectionPoint(final
ResolvableAnnotatedItem<?, ?> element)
{
- Callable<Set<Bean<T>>> callable = new
Callable<Set<Bean<T>>>()
+ Callable<Set<Bean<?>>> callable = new
Callable<Set<Bean<?>>>()
{
- public Set<Bean<T>> call() throws Exception
+ public Set<Bean<?>> call() throws Exception
{
return retainHighestPrecedenceBeans(getMatchingBeans(element,
manager.getBeans()), manager.getEnabledDeploymentTypes());
}
@@ -146,20 +144,9 @@
* @param key The resolving criteria
* @return An unmodifiable set of matching beans
*/
- public <T, S> Set<Bean<T>> get(final AnnotatedItem<T, S> key)
+ public Set<Bean<?>> get(final AnnotatedItem<?, ?> key)
{
- final AnnotatedItem<T, S> transformedElement = transformElement(key);
-
- Set<Bean<T>> beans = registerInjectionPoint(new
ResolvableAnnotatedItem<T, S>()
- {
-
- @Override
- public AnnotatedItem<T, S> delegate()
- {
- return transformedElement;
- }
-
- });
+ Set<Bean<?>> beans =
registerInjectionPoint(ResolvableAnnotatedItem.of(transformElement(key)));
return Collections.unmodifiableSet(beans);
}
@@ -178,7 +165,7 @@
* @param name The name to match
* @return The set of matching beans
*/
- public Set<Bean<? extends Object>> get(final String name)
+ public Set<Bean<?>> get(final String name)
{
return resolvedNames.putIfAbsent(name, new
Callable<Set<Bean<?>>>()
{
@@ -196,12 +183,6 @@
}
return retainHighestPrecedenceBeans(beans,
manager.getEnabledDeploymentTypes());
}
-
- // Helper method to deal with dynamic casts being needed
- private Set<Bean<?>>
retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends
Annotation>> enabledDeploymentTypes)
- {
- return
BEAN_SET_GENERIFIED_WITH_WILDCARD.cast(Resolver.retainHighestPrecedenceBeans(BEAN_SET_GENERIFIED_WITH_OBJECT.cast(beans),
enabledDeploymentTypes));
- }
});
}
@@ -216,7 +197,7 @@
* @param enabledDeploymentTypes The enabled deployment types
* @return The filtered beans
*/
- private static <T> Set<Bean<T>>
retainHighestPrecedenceBeans(Set<Bean<T>> beans, List<Class<? extends
Annotation>> enabledDeploymentTypes)
+ private static Set<Bean<?>>
retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends
Annotation>> enabledDeploymentTypes)
{
if (beans.size() > 0)
{
@@ -226,12 +207,12 @@
possibleDeploymentTypes.add(bean.getDeploymentType());
}
possibleDeploymentTypes.retainAll(enabledDeploymentTypes);
- Set<Bean<T>> trimmed = new HashSet<Bean<T>>();
+ Set<Bean<?>> trimmed = new HashSet<Bean<?>>();
if (possibleDeploymentTypes.size() > 0)
{
Class<? extends Annotation> highestPrecedencePossibleDeploymentType =
possibleDeploymentTypes.last();
- for (Bean<T> bean : beans)
+ for (Bean<?> bean : beans)
{
if
(bean.getDeploymentType().equals(highestPrecedencePossibleDeploymentType))
{
@@ -255,16 +236,14 @@
* @param beans The beans to filter
* @return A set of filtered beans
*/
- private <T> Set<Bean<T>> getMatchingBeans(AnnotatedItem<T, ?>
element, List<Bean<?>> beans)
+ private Set<Bean<?>> getMatchingBeans(AnnotatedItem<?, ?> element,
List<Bean<?>> beans)
{
- Set<Bean<T>> resolvedBeans = new HashSet<Bean<T>>();
+ Set<Bean<?>> resolvedBeans = new HashSet<Bean<?>>();
for (Bean<?> bean : beans)
{
if (element.isAssignableFrom(bean.getTypes()) &&
containsAllBindings(element, bean.getBindings()))
{
- @SuppressWarnings("unchecked")
- Bean<T> b = (Bean<T>) bean;
- resolvedBeans.add(b);
+ resolvedBeans.add(bean);
}
}
return resolvedBeans;