Skip to content

Commit

Permalink
Fixing broken decorator test. Non-decorated calls are now redirected …
Browse files Browse the repository at this point in the history
…correctly to the contextual instance.
  • Loading branch information
mbogoevici committed Nov 6, 2009
1 parent 5fce629 commit a07497b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
Expand Up @@ -94,6 +94,9 @@ public abstract class AbstractClassBean<T> extends AbstractBean<T, Class<T>>
private Class<T> proxyClassForDecorators;

private final ThreadLocal<Integer> decoratorStackPosition;

private final ThreadLocal<T> decoratedActualInstance = new ThreadLocal<T>();

private WeldMethod<?, ?> postConstruct;
private WeldMethod<?, ?> preDestroy;

Expand Down Expand Up @@ -178,6 +181,11 @@ protected T applyDecorators(T instance, CreationalContext<T> creationalContext,
List<SerializableContextualInstance<DecoratorImpl<Object>, Object>> decoratorInstances = new ArrayList<SerializableContextualInstance<DecoratorImpl<Object>,Object>>();
InjectionPoint ip = originalInjectionPoint;
boolean outside = decoratorStackPosition.get().intValue() == 0;
if (outside)
{
decoratedActualInstance.set(instance);
}

try
{
int i = decoratorStackPosition.get();
Expand Down Expand Up @@ -211,7 +219,10 @@ protected T applyDecorators(T instance, CreationalContext<T> creationalContext,
try
{
T proxy = proxyClassForDecorators.newInstance();
((ProxyObject) proxy).setHandler(new DecoratorProxyMethodHandler(decoratorInstances, instance));
// temporary fix for decorators - make sure that the instance wrapped by the decorators
// is the contextual instance
// TODO - correct the decoration algorithm to avoid the creation of new target class instances
((ProxyObject) proxy).setHandler(new DecoratorProxyMethodHandler(decoratorInstances, decoratedActualInstance.get()));
return proxy;
}
catch (InstantiationException e)
Expand All @@ -222,6 +233,13 @@ protected T applyDecorators(T instance, CreationalContext<T> creationalContext,
{
throw new RuntimeException("Could not access bean correctly when creating decorator proxy for " + toString(), e);
}
finally
{
if (outside)
{
decoratedActualInstance.set(null);
}
}
}

public List<Decorator<?>> getDecorators()
Expand Down
Expand Up @@ -14,7 +14,7 @@
@BeansXml("beans.xml")
public class SimpleDecoratorTest extends AbstractWeldTest
{
@Test(groups = "broken")
@Test
public void testSimpleDecorator()
{
SimpleBean simpleBean = getCurrentManager().getInstanceByType(SimpleBean.class);
Expand Down

0 comments on commit a07497b

Please sign in to comment.