Skip to content

Commit

Permalink
start to clean up the mess
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2786 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jun 8, 2009
1 parent 9f7eab7 commit 6ef53dd
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 51 deletions.
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/webbeans/BeanValidator.java
Expand Up @@ -105,7 +105,7 @@ public void validate()
checkFacadeInjectionPoint(injectionPoint, Any.class, Event.class);
Annotation[] bindings = injectionPoint.getBindings().toArray(new Annotation[0]);
AnnotatedItem<?, ?> annotatedItem = ResolvableAnnotatedClass.of(injectionPoint.getType(), bindings);
Set<?> resolvedBeans = manager.resolveByType(annotatedItem, injectionPoint, bindings);
Set<?> resolvedBeans = manager.getBeans(injectionPoint);
if (resolvedBeans.isEmpty())
{
throw new UnsatisfiedResolutionException("The injection point " + injectionPoint + " with binding types " + Names.annotationsToString(injectionPoint.getBindings()) + " in " + bean + " has unsatisfied dependencies with binding types ");
Expand Down
46 changes: 13 additions & 33 deletions impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -373,11 +373,15 @@ public void addBean(Bean<?> bean)
public <T> Set<DisposalMethodBean<T>> resolveDisposalBeans(Class<T> apiType, Annotation... bindings)
{
// Correct?
Set<Bean<T>> beans = getBeans(apiType, bindings);
Set<Bean<?>> beans = getBeans(apiType, bindings);
Set<DisposalMethodBean<T>> disposalBeans = new HashSet<DisposalMethodBean<T>>();
for (Bean<T> bean : beans)
for (Bean<?> bean : beans)
{
if (bean instanceof DisposalMethodBean)
{
disposalBeans.add((DisposalMethodBean<T>) bean);
}
}
return disposalBeans;
}

Expand Down Expand Up @@ -455,16 +459,13 @@ public Set<Bean<?>> getBeans(Type beanType, Annotation... bindings)
{
return (Set) resolveByType(ResolvableAnnotatedClass.of(beanType, bindings), bindings);
}

@Deprecated
public <T> Set<Bean<T>> getBeans(Class<T> beanType, Annotation... bindings)

public Set<Bean<?>> getBeans(AnnotatedItem<?, ?> element, Annotation... bindings)
{
return resolveByType(ResolvableAnnotatedClass.of(beanType, bindings), bindings);
return (Set) resolveByType(element, bindings);
}


@Deprecated
public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, InjectionPoint injectionPoint, Annotation... bindings)
public Set<Bean<?>> getBeans(InjectionPoint injectionPoint)
{
boolean registerInjectionPoint = !injectionPoint.getType().equals(InjectionPoint.class);
try
Expand All @@ -473,7 +474,8 @@ public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, InjectionPoin
{
currentInjectionPoint.get().push(injectionPoint);
}
return resolveByType(element, bindings);
// TODO Do this properly
return getBeans(ResolvableAnnotatedClass.of(injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0])));
}
finally
{
Expand Down Expand Up @@ -513,7 +515,7 @@ public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, Annotation...
throw new IllegalArgumentException("Cannot resolve a type parameterized with a type parameter " + element);
}
}
if (bindings.length > element.getMetaAnnotations(BindingType.class).size())
if (bindings != null && bindings.length > element.getMetaAnnotations(BindingType.class).size())
{
throw new DuplicateBindingTypeException("Duplicate bindings (" + Arrays.asList(bindings) + ") type passed " + element.toString());
}
Expand Down Expand Up @@ -767,19 +769,6 @@ public Object getReference(Bean<?> bean, Type beanType)
return getInstance(bean,true);
}


@Deprecated
public Object getInstanceToInject(InjectionPoint injectionPoint)
{
return this.getInjectableReference(injectionPoint, null);
}

@Deprecated
public void injectNonContextualInstance(Object instance)
{
nonContextualInjector.inject(instance);
}

@SuppressWarnings("unchecked")
public Object getInjectableReference(InjectionPoint injectionPoint, CreationalContext<?> creationalContext)
{
Expand Down Expand Up @@ -916,15 +905,6 @@ else if (beans.size() > 1)
return bean;
}


/**
* Resolves a set of beans based on their name
*
* @param The name to match
* @return The set of matching beans
*
* @see javax.enterprise.inject.spi.BeanManager#getBeans(java.lang.String)
*/
public Set<Bean<?>> getBeans(String name)
{
return resolver.get(name);
Expand Down
Expand Up @@ -191,7 +191,8 @@ public void invokeDisposeMethod(Object instance)

for (InjectionPoint injectionPoint : disposalInjectionPoints)
{
Object injectionObject = getManager().getInstanceToInject(injectionPoint);
// TODO this seems very wrong, we should be passing a creational context here
Object injectionObject = getManager().getInjectableReference(injectionPoint, null);
parameters.add(injectionObject);
}

Expand Down
Expand Up @@ -27,7 +27,10 @@
import java.util.Set;

import javax.enterprise.inject.TypeLiteral;
import javax.enterprise.inject.spi.InjectionPoint;

import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotationStore;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem;
import org.jboss.webbeans.util.Names;
Expand All @@ -41,17 +44,17 @@ public class ResolvableAnnotatedClass<T> extends AbstractAnnotatedItem<T, Class<

private final String _string;

public static <T> ResolvableAnnotatedClass<T> of(TypeLiteral<T> typeLiteral, Annotation[] annotations)
public static <T> AnnotatedItem<T, Class<T>> of(TypeLiteral<T> typeLiteral, Annotation[] annotations)
{
return new ResolvableAnnotatedClass<T>(typeLiteral.getRawType(), typeLiteral.getType(), annotations);
}

public static <T> ResolvableAnnotatedClass<T> of(Class<T> clazz, Annotation[] annotations)
public static <T> AnnotatedItem<T, Class<T>> of(Class<T> clazz, Annotation[] annotations)
{
return new ResolvableAnnotatedClass<T>(clazz, clazz, annotations);
}

public static <T> ResolvableAnnotatedClass<T> of(Type type, Annotation[] annotations)
public static <T> AnnotatedItem<T, Class<T>> of(Type type, Annotation[] annotations)
{
if (type instanceof Class)
{
Expand All @@ -67,7 +70,22 @@ else if (type instanceof ParameterizedType)
}
}

public static <T> ResolvableAnnotatedClass<T> of(Member member, Annotation[] annotations)

public static <T> AnnotatedItem<T, Class<T>> of(InjectionPoint injectionPoint)
{
if (injectionPoint instanceof AnnotatedInjectionPoint)
{
@SuppressWarnings("unchecked")
AnnotatedItem<T, Class<T>> ip = (AnnotatedItem<T, Class<T>>) injectionPoint;
return ip;
}
else
{
return of(injectionPoint.getType(), injectionPoint.getAnnotations());
}
}

public static <T> AnnotatedItem<T, Class<T>> of(Member member, Annotation[] annotations)
{
if (member instanceof Field)
{
Expand Down
Expand Up @@ -31,14 +31,6 @@
public interface WebBeansManager extends BeanManager, Serializable
{

/**
* Perform JSR-299 dependency injection into a non-contextual instance
*
* @param instance
* the instance to inject
*/
public void injectNonContextualInstance(Object instance);

public void shutdown();

}
Expand Up @@ -6,12 +6,15 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import javax.enterprise.inject.deployment.Production;
import javax.enterprise.inject.deployment.Standard;
import javax.enterprise.inject.spi.Bean;

import org.jboss.testharness.AbstractTest;
import org.jboss.webbeans.CurrentManager;
Expand Down Expand Up @@ -151,4 +154,20 @@ public boolean isExceptionInHierarchy(Throwable exception, Class<? extends Throw
return false;
}

public <T> Bean<T> getBean(Type beanType, Annotation... bindings)
{
Set<Bean<?>> beans = getCurrentManager().getBeans(beanType, bindings);
if (beans.size() > 1)
{
throw new RuntimeException("More than one bean resolved to " + beanType + " with bindings " + Arrays.asList(bindings));
}
if (beans.size() == 0)
{
throw new RuntimeException("No beans resolved to " + beanType + " with bindings " + Arrays.asList(bindings));
}
@SuppressWarnings("deprecated")
Bean<T> bean = (Bean<T>) beans.iterator().next();
return bean;
}

}
Expand Up @@ -47,7 +47,7 @@ public class EnterpriseBeanLifecycleTest extends AbstractWebBeansTest
public void testCreateSFSB()
{
GrossStadt frankfurt = getCurrentManager().getInstanceByType(GrossStadt.class);
Bean<KleinStadt> stadtBean = getCurrentManager().getBeans(KleinStadt.class).iterator().next();
Bean<KleinStadt> stadtBean = getBean(KleinStadt.class);
assert stadtBean != null : "Expected a bean for stateful session bean Kassel";
CreationalContext<KleinStadt> creationalContext = new MockCreationalContext<KleinStadt>();
KleinStadt stadtInstance = stadtBean.create(creationalContext);
Expand Down Expand Up @@ -75,7 +75,7 @@ public void testCreateSFSB()
public void testDestroyRemovesSFSB() throws Exception
{
GrossStadt frankfurt = getCurrentManager().getInstanceByType(GrossStadt.class);
Bean<KleinStadt> stadtBean = getCurrentManager().getBeans(KleinStadt.class).iterator().next();
Bean<KleinStadt> stadtBean = getBean(KleinStadt.class);
assert stadtBean != null : "Expected a bean for stateful session bean Kassel";
Context requestContext = getCurrentManager().getContext(RequestScoped.class);
CreationalContext<KleinStadt> creationalContext = new MockCreationalContext<KleinStadt>();
Expand Down
Expand Up @@ -66,10 +66,10 @@ public void testDd()

ManagerImpl manager = parserEnv.getManager();

Set<Bean<Order>> beansSet = manager.getBeans(Order.class);
Set<Bean<?>> beansSet = manager.getBeans(Order.class);
List<Class<? extends Annotation>> dTypes = manager.getEnabledDeploymentTypes();
dTypes.size();
for(Bean<Order> bean : beansSet)
for(Bean<?> bean : beansSet)
{
Class<? extends Annotation> deploymentType = bean.getDeploymentType();
System.out.println("after parsing: " + deploymentType);
Expand Down

0 comments on commit 6ef53dd

Please sign in to comment.