Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Feb 16, 2010
1 parent b175241 commit ca09d47
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 42 deletions.
34 changes: 12 additions & 22 deletions impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
Expand Up @@ -488,7 +488,7 @@ public void addInterceptor(Interceptor<?> bean)
@SuppressWarnings("unchecked")
public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(Type eventType, Annotation... bindings)
{
checkBindingTypes(Arrays.asList(bindings));
checkQualifiers(Arrays.asList(bindings));
HashSet<Annotation> bindingAnnotations = new HashSet<Annotation>(Arrays.asList(bindings));
bindingAnnotations.add(AnyLiteral.INSTANCE);
Set<ObserverMethod<? super T>> observers = new HashSet<ObserverMethod<? super T>>();
Expand All @@ -500,7 +500,7 @@ public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(Type eventType,
return observers;
}

private void checkBindingTypes(Collection<Annotation> bindings)
private void checkQualifiers(Collection<Annotation> bindings)
{
HashSet<Annotation> bindingAnnotations = new HashSet<Annotation>(bindings);
for (Annotation annotation : bindings)
Expand Down Expand Up @@ -879,9 +879,9 @@ public Object getInjectableReference(InjectionPoint injectionPoint, CreationalCo
}
}

public <T> Bean<T> getBean(WeldAnnotated<T, ?> element, Annotation... bindings)
public <T> Bean<T> getBean(WeldAnnotated<T, ?> element, Annotation... qualifiers)
{
Bean<T> bean = (Bean<T>) resolve(getBeans(element, bindings));
Bean<T> bean = (Bean<T>) resolve(getBeans(element, qualifiers));
if (bean == null)
{
throw new UnsatisfiedResolutionException(UNRESOLVABLE_ELEMENT, element);
Expand All @@ -900,37 +900,27 @@ public Set<Bean<?>> getBeans(String name)
return nameBasedResolver.resolve(name);
}

/**
* Resolves a list of decorators based on API types and binding types
*
* @param types The set of API types to match
* @param bindings The binding types to match
* @return A list of matching decorators
*
* @see javax.enterprise.inject.spi.BeanManager#resolveDecorators(java.util.Set,
* java.lang.annotation.Annotation[])
*/
public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... bindings)
public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... qualifiers)
{
checkResolveDecoratorsArguments(types, Arrays.asList(bindings));
checkResolveDecoratorsArguments(types, Arrays.asList(qualifiers));
// TODO Fix this cast and make the resolver return a list
return new ArrayList<Decorator<?>>(decoratorResolver.resolve(ResolvableFactory.of(types, null, bindings)));
return new ArrayList<Decorator<?>>(decoratorResolver.resolve(ResolvableFactory.of(types, qualifiers, null)));
}

public List<Decorator<?>> resolveDecorators(Set<Type> types, Set<Annotation> bindings)
public List<Decorator<?>> resolveDecorators(Set<Type> types, Set<Annotation> qualifiers)
{
checkResolveDecoratorsArguments(types, bindings);
checkResolveDecoratorsArguments(types, qualifiers);
// TODO Fix this cast and make the resolver return a list
return new ArrayList<Decorator<?>>(decoratorResolver.resolve(ResolvableFactory.of(types, bindings, null)));
return new ArrayList<Decorator<?>>(decoratorResolver.resolve(ResolvableFactory.of(types, qualifiers, null)));
}

private void checkResolveDecoratorsArguments(Set<Type> types, Collection<Annotation> bindings)
private void checkResolveDecoratorsArguments(Set<Type> types, Collection<Annotation> qualifiers)
{
if (types.isEmpty())
{
throw new ForbiddenArgumentException(NO_DECORATOR_TYPES);
}
checkBindingTypes(bindings);
checkQualifiers(qualifiers);
}

/**
Expand Down
40 changes: 20 additions & 20 deletions impl/src/main/java/org/jboss/weld/resolution/ResolvableFactory.java
Expand Up @@ -18,7 +18,6 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -30,60 +29,61 @@
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.introspector.WeldAnnotated;
import org.jboss.weld.literal.DefaultLiteral;
import org.jboss.weld.util.collections.Arrays2;
import org.jboss.weld.util.reflection.Reflections;

public class ResolvableFactory
{

public static Resolvable of(WeldAnnotated<?, ?> element)
public static Resolvable of(WeldAnnotated<?, ?> annotated)
{
if (element instanceof Resolvable)
if (annotated instanceof Resolvable)
{
return (Resolvable) element;
return (Resolvable) annotated;
}
else
{
Set<Type> types = new HashSet<Type>();
types.add(element.getBaseType());
return new ResolvableImpl(element.getQualifiers(), types, null);
types.add(annotated.getBaseType());
return new ResolvableImpl(types, annotated.getQualifiers(), null);
}
}

public static Resolvable of(Set<Type> typeClosure, Set<Annotation> bindings, AbstractClassBean<?> declaringBean)
public static Resolvable of(Set<Type> typeClosure, Set<Annotation> qualifiers, AbstractClassBean<?> declaringBean)
{
return new ResolvableImpl(bindings, typeClosure, declaringBean);
return new ResolvableImpl(typeClosure, qualifiers, declaringBean);
}

public static Resolvable of(Set<Type> typeClosure, AbstractClassBean<?> declaringBean, Annotation... bindings)
public static Resolvable of(Set<Type> typeClosure, Annotation[] qualifiers, AbstractClassBean<?> declaringBean)
{
return new ResolvableImpl(new HashSet<Annotation>(Arrays.asList(bindings)), typeClosure, declaringBean);
return new ResolvableImpl(typeClosure, Arrays2.asSet(qualifiers), declaringBean);
}

public static InterceptorResolvable of(InterceptionType interceptionType, Annotation... bindings)
public static InterceptorResolvable of(InterceptionType interceptionType, Annotation[] qualifiers)
{
return new InterceptorResolvableImpl(new HashSet<Annotation>(Arrays.asList(bindings)), interceptionType );
return new InterceptorResolvableImpl(Arrays2.asSet(qualifiers), interceptionType );
}

private ResolvableFactory() {}

private static class ResolvableImpl implements Resolvable
{

private final Set<Annotation> bindings;
private final Set<Annotation> qualifiers;
private final Map<Class<? extends Annotation>, Annotation> annotations;
private final Set<Type> typeClosure;
private final AbstractClassBean<?> declaringBean;

public ResolvableImpl(Set<Annotation> bindings, Set<Type> typeClosure, AbstractClassBean<?> declaringBean)
public ResolvableImpl(Set<Type> typeClosure, Set<Annotation> qualifiers, AbstractClassBean<?> declaringBean)
{
this.bindings = bindings;
if (bindings.size() == 0)
this.qualifiers = qualifiers;
if (qualifiers.size() == 0)
{
this.bindings.add(DefaultLiteral.INSTANCE);
this.qualifiers.add(DefaultLiteral.INSTANCE);
}
this.annotations = new HashMap<Class<? extends Annotation>, Annotation>();
this.typeClosure = typeClosure;
for (Annotation annotation : bindings)
for (Annotation annotation : qualifiers)
{
annotations.put(annotation.annotationType(), annotation);
}
Expand All @@ -92,7 +92,7 @@ public ResolvableImpl(Set<Annotation> bindings, Set<Type> typeClosure, AbstractC

public Set<Annotation> getQualifiers()
{
return bindings;
return qualifiers;
}

public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
Expand Down Expand Up @@ -140,7 +140,7 @@ private static class InterceptorResolvableImpl extends ResolvableImpl implements

private InterceptorResolvableImpl(Set<Annotation> bindings, InterceptionType interceptionType)
{
super(bindings, Collections.singleton((Type)Object.class), null);
super(Collections.singleton((Type)Object.class), bindings, null);
this.interceptionType = interceptionType;
}

Expand Down

0 comments on commit ca09d47

Please sign in to comment.