Skip to content

Commit

Permalink
use getInstanceForInjection to find injection point, better hierachy …
Browse files Browse the repository at this point in the history
…for standard beans, enable a couple of TCK tests

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1263 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 28, 2009
1 parent e3cf83d commit 1d63e43
Show file tree
Hide file tree
Showing 22 changed files with 365 additions and 321 deletions.
Expand Up @@ -35,11 +35,11 @@
import javax.inject.manager.Bean;
import javax.inject.manager.InjectionPoint;

import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.bean.AbstractProducerBean;
import org.jboss.webbeans.bean.NewEnterpriseBean;
import org.jboss.webbeans.bean.NewSimpleBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.ListComparator;
import org.jboss.webbeans.util.Proxies;
Expand Down Expand Up @@ -117,9 +117,9 @@ public void validate()
throw new UnsupportedOperationException("Not yet implemented");
}
}
if (bean instanceof AbstractBean && !(bean instanceof NewSimpleBean) && !(bean instanceof NewEnterpriseBean))
if (bean instanceof RIBean && !(bean instanceof NewSimpleBean) && !(bean instanceof NewEnterpriseBean))
{
AbstractBean<?, ?> abstractBean = (AbstractBean<?, ?>) bean;
RIBean<?> abstractBean = (RIBean<?>) bean;
if (abstractBean.isSpecializing())
{
if (!hasHigherPrecedence(bean.getDeploymentType(), abstractBean.getSpecializedBean().getDeploymentType()))
Expand Down
69 changes: 34 additions & 35 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -53,17 +53,16 @@
import javax.inject.manager.Interceptor;
import javax.inject.manager.Manager;

import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.NewEnterpriseBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bean.proxy.ProxyPool;
import org.jboss.webbeans.context.ContextMap;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.InjectionPointProvider;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
Expand All @@ -83,7 +82,6 @@
* @author Pete Muir
*
*/
@Standard
public class ManagerImpl implements Manager, Serializable
{

Expand All @@ -98,8 +96,9 @@ public class ManagerImpl implements Manager, Serializable
private transient List<Class<? extends Annotation>> enabledDeploymentTypes;
// The Web Beans event manager
private transient final EventManager eventManager;

// An injection point metadata beans factory
private transient final InjectionPointProvider injectionPointProvider;
private transient final ThreadLocal<InjectionPoint> currentInjectionPoint;

// The bean resolver
private transient final Resolver resolver;
Expand Down Expand Up @@ -130,8 +129,6 @@ public class ManagerImpl implements Manager, Serializable
private transient final NamingContext namingContext;

private final transient Map<Bean<?>, Bean<?>> specializedBeans;

private final transient ThreadLocal<Map<Bean<?>, ?>> incompleteInstances;

/**
* Create a new manager
Expand All @@ -153,18 +150,8 @@ public ManagerImpl(NamingContext namingContext, EjbResolver ejbResolver, Resourc
this.contextMap = new ContextMap();
this.eventManager = new EventManager();
this.ejbDescriptorCache = new EjbDescriptorCache();
this.injectionPointProvider = new InjectionPointProvider();
this.currentInjectionPoint = new ThreadLocal<InjectionPoint>();
this.specializedBeans = new HashMap<Bean<?>, Bean<?>>();
this.incompleteInstances = new ThreadLocal<Map<Bean<?>,?>>()
{

@Override
protected Map<Bean<?>, ?> initialValue()
{
return new HashMap<Bean<?>, Object>();
}

};
List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
defaultEnabledDeploymentTypes.add(0, Standard.class);
defaultEnabledDeploymentTypes.add(1, Production.class);
Expand Down Expand Up @@ -350,12 +337,12 @@ public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, Annotation...
* @return A reference to the manager
*/
// TODO Build maps in the deployer :-)
public void setBeans(Set<AbstractBean<?, ?>> beans)
public void setBeans(Set<RIBean<?>> beans)
{
synchronized (beans)
{
this.beans = new CopyOnWriteArrayList<Bean<?>>(beans);
for (AbstractBean<?, ?> bean : beans)
for (RIBean<?> bean : beans)
{
if (bean instanceof NewEnterpriseBean)
{
Expand Down Expand Up @@ -602,35 +589,47 @@ else if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())

public <T> T getInstanceToInject(InjectionPoint injectionPoint)
{
return getInstanceToInject(AnnotatedClassImpl.of((Class<T>) injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0])), null);
return this.<T>getInstanceToInject(injectionPoint, null);
}

public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<?> creationalContext)
{
return getInstanceToInject(AnnotatedClassImpl.of((Class<T>) injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0])), creationalContext);
}

private <T> T getInstanceToInject(AnnotatedItem<T, ?> element, CreationalContext<?> creationalContext)
{
Bean<T> bean = getBeanByType(element, element.getBindingTypesAsArray());
if (creationalContext instanceof CreationalContextImpl)
boolean registerInjectionPoint = !injectionPoint.getType().equals(InjectionPoint.class);
try
{
CreationalContextImpl<?> ctx = (CreationalContextImpl<?>) creationalContext;
if (ctx.containsIncompleteInstance(bean))
if (registerInjectionPoint)
{
currentInjectionPoint.set(injectionPoint);
}
AnnotatedItem<T, ?> element = AnnotatedClassImpl.of((Class<T>) injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0]));
Bean<T> bean = getBeanByType(element, element.getBindingTypesAsArray());
if (creationalContext instanceof CreationalContextImpl)
{
return ctx.getIncompleteInstance(bean);
CreationalContextImpl<?> ctx = (CreationalContextImpl<?>) creationalContext;
if (ctx.containsIncompleteInstance(bean))
{
return ctx.getIncompleteInstance(bean);
}
else
{
return getInstance(bean, ctx.getCreationalContext(bean));
}
}
else
{
return getInstance(bean, ctx.getCreationalContext(bean));
return getInstance(bean);
}
}
else
finally
{
return getInstance(bean);
if (registerInjectionPoint)
{
currentInjectionPoint.remove();
}
}
}


/**
* Gets an instance by name, returning null if none is found and throwing an
* exception if too many beans match
Expand Down Expand Up @@ -871,9 +870,9 @@ public ResourceLoader getResourceLoader()
*
* @return the factory
*/
public InjectionPointProvider getInjectionPointProvider()
public InjectionPoint getInjectionPoint()
{
return injectionPointProvider;
return currentInjectionPoint.get();
}

/**
Expand Down
Expand Up @@ -54,7 +54,7 @@
* @param <T> the type of bean
* @param <E> the Class<?> of the bean type
*/
public abstract class AbstractBean<T, E> extends Bean<T>
public abstract class AbstractBean<T, E> extends RIBean<T>
{

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -417,7 +417,7 @@ public Class<? extends Annotation> getDeploymentType()
*
* @return The set of merged stereotypes
*/
public MergedStereotypes<T, E> getMergedStereotypes()
protected MergedStereotypes<T, E> getMergedStereotypes()
{
return mergedStereotypes;
}
Expand Down Expand Up @@ -542,6 +542,7 @@ public boolean isSpecializing()
}

@Override
// TODO Fix this!!!
public boolean equals(Object other)
{
if (other instanceof AbstractBean)
Expand Down
Expand Up @@ -35,7 +35,6 @@

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injection.FieldInjectionPoint;
import org.jboss.webbeans.injection.InjectionPointProvider;
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.injection.ParameterInjectionPoint;
import org.jboss.webbeans.introspector.AnnotatedClass;
Expand Down Expand Up @@ -98,18 +97,9 @@ protected void init()
*/
protected void injectBoundFields(T instance, CreationalContext<T> creationalContext)
{
InjectionPointProvider injectionPointProvider = manager.getInjectionPointProvider();
for (FieldInjectionPoint<?> injectableField : injectableFields)
{
injectionPointProvider.pushInjectionPoint(injectableField);
try
{
injectableField.inject(instance, manager, creationalContext);
}
finally
{
injectionPointProvider.popInjectionPoint();
}
injectableField.inject(instance, manager, creationalContext);
}
}

Expand Down
Expand Up @@ -194,7 +194,7 @@ protected void checkReturnValue(T instance)
{
throw new IllegalProductException("Producers cannot declare passivating scope and return a non-serializable class");
}
InjectionPoint injectionPoint = manager.getInjectionPointProvider().getCurrentInjectionPoint();
InjectionPoint injectionPoint = manager.getInjectionPoint();
if (injectionPoint == null)
{
return;
Expand Down

This file was deleted.

45 changes: 45 additions & 0 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bean/RIBean.java
@@ -0,0 +1,45 @@
package org.jboss.webbeans.bean;

import java.util.Set;

import javax.context.Dependent;
import javax.inject.manager.Bean;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;

public abstract class RIBean<T> extends Bean<T>
{

private final ManagerImpl manager;

protected RIBean(ManagerImpl manager)
{
super(manager);
this.manager = manager;
}

@Override
protected ManagerImpl getManager()
{
return manager;
}

public abstract Class<T> getType();

public abstract boolean isSpecializing();

public boolean isDependent()
{
return getScopeType().equals(Dependent.class);
}

public abstract boolean isProxyable();

public abstract boolean isPrimitive();

public abstract Set<AnnotatedInjectionPoint<?, ?>> getInjectionPoints();

public abstract RIBean<?> getSpecializedBean();

}
Expand Up @@ -37,7 +37,6 @@
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
import org.jboss.webbeans.injection.ConstructorInjectionPoint;
import org.jboss.webbeans.injection.FieldInjectionPoint;
import org.jboss.webbeans.injection.InjectionPointProvider;
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.injection.ParameterInjectionPoint;
import org.jboss.webbeans.introspector.AnnotatedClass;
Expand Down Expand Up @@ -125,7 +124,6 @@ public T create(CreationalContext<T> creationalContext)
try
{
DependentContext.INSTANCE.setActive(true);
InjectionPointProvider injectionPointProvider = manager.getInjectionPointProvider();
T instance = null;
try
{
Expand Down

0 comments on commit 1d63e43

Please sign in to comment.