[weld-commits] Weld SVN: r4712 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/decorators and 1 other directory.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Fri Nov 6 00:44:57 EST 2009


Author: marius.bogoevici
Date: 2009-11-06 00:44:56 -0500 (Fri, 06 Nov 2009)
New Revision: 4712

Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/SimpleDecoratorTest.java
Log:
Fixing broken decorator test. Non-decorated calls are now redirected correctly to the contextual instance.

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java	2009-11-06 05:26:28 UTC (rev 4711)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java	2009-11-06 05:44:56 UTC (rev 4712)
@@ -94,6 +94,9 @@
    private Class<T> proxyClassForDecorators;
    
    private final ThreadLocal<Integer> decoratorStackPosition;
+
+   private final ThreadLocal<T> decoratedActualInstance = new ThreadLocal<T>();
+
    private WeldMethod<?, ?> postConstruct;
    private WeldMethod<?, ?> preDestroy;
    
@@ -178,6 +181,11 @@
       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();
@@ -211,7 +219,10 @@
       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)
@@ -222,6 +233,13 @@
       {
          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()

Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/SimpleDecoratorTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/SimpleDecoratorTest.java	2009-11-06 05:26:28 UTC (rev 4711)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/SimpleDecoratorTest.java	2009-11-06 05:44:56 UTC (rev 4712)
@@ -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);



More information about the weld-commits mailing list