Skip to content

Commit

Permalink
WBRI-183, thanks to Takeshi Kondo
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1995 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Mar 14, 2009
1 parent 156b5a6 commit 30d1998
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
25 changes: 20 additions & 5 deletions impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -112,7 +113,7 @@ public class ManagerImpl implements WebBeansManager, Serializable
private transient final ExecutorService taskExecutor = Executors.newSingleThreadExecutor();

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

// The bean resolver
private transient final Resolver resolver;
Expand Down Expand Up @@ -167,7 +168,14 @@ public ManagerImpl(NamingContext namingContext, EjbServices ejbServices, Resourc
this.contextMap = new ContextMap();
this.eventManager = new EventManager();
this.ejbDescriptorCache = new EjbDescriptorCache();
this.currentInjectionPoint = new ThreadLocal<InjectionPoint>();
this.currentInjectionPoint = new ThreadLocal<Stack<InjectionPoint>>()
{
@Override
protected Stack<InjectionPoint> initialValue()
{
return new Stack<InjectionPoint>();
}
};
this.specializedBeans = new HashMap<Bean<?>, Bean<?>>();
this.servletInjector = new ServletInjector(this);
List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
Expand Down Expand Up @@ -635,7 +643,7 @@ public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContex
{
if (registerInjectionPoint)
{
currentInjectionPoint.set(injectionPoint);
currentInjectionPoint.get().push(injectionPoint);
}
AnnotatedItem<T, ?> element = ResolvableAnnotatedClass.of((Class<T>) injectionPoint.getType(), injectionPoint.getBindings().toArray(new Annotation[0]));
Bean<T> bean = getBeanByType(element, element.getBindingsAsArray());
Expand All @@ -660,7 +668,7 @@ public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContex
{
if (registerInjectionPoint)
{
currentInjectionPoint.remove();
currentInjectionPoint.get().pop();
}
}
}
Expand Down Expand Up @@ -917,7 +925,14 @@ public final TransactionServices getTransactionServices()
*/
public InjectionPoint getInjectionPoint()
{
return currentInjectionPoint.get();
if (!currentInjectionPoint.get().empty())
{
return currentInjectionPoint.get().peek();
}
else
{
return null;
}
}

/**
Expand Down
@@ -0,0 +1,15 @@
package org.jboss.webbeans.test.unit.implementation.producer;

import javax.inject.Initializer;

public class IntInjection
{

int value;

@Initializer public IntInjection(Integer integer)
{
this.value = integer;
}

}
@@ -0,0 +1,32 @@
package org.jboss.webbeans.test.unit.implementation.producer;

import javax.inject.Current;
import javax.inject.Produces;
import javax.inject.manager.InjectionPoint;
import javax.inject.manager.Manager;

class ManagerProducer
{

@Current Manager manager;

private static boolean injectionPointInjected;

public static boolean isInjectionPointInjected()
{
return injectionPointInjected;
}

public static void setInjectionPointInjected(boolean injectionPointInjected)
{
ManagerProducer.injectionPointInjected = injectionPointInjected;
}

@Produces
Integer create(InjectionPoint point)
{
injectionPointInjected = point != null;
return 10;
}

}
@@ -0,0 +1,18 @@
package org.jboss.webbeans.test.unit.implementation.producer;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
import org.testng.annotations.Test;

@Artifact
public class ManagerProducerTest extends AbstractWebBeansTest
{
@Test(description="WBRI-183")
public void testInjectManagerProducer()
{
ManagerProducer.setInjectionPointInjected(false);
manager.getInstanceByType(IntInjection.class);
assert ManagerProducer.isInjectionPointInjected();
}

}

0 comments on commit 30d1998

Please sign in to comment.