Author: marius.bogoevici
Date: 2009-10-28 23:23:25 -0400 (Wed, 28 Oct 2009)
New Revision: 4369
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java
Log:
Fix field injection and producer fields when instance is decorated/intercepted.
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-10-29
03:18:39 UTC (rev 4368)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2009-10-29
03:23:25 UTC (rev 4369)
@@ -43,6 +43,7 @@
import org.jboss.interceptor.model.InterceptionModel;
import org.jboss.interceptor.model.InterceptorClassMetadataImpl;
import org.jboss.interceptor.util.InterceptionUtils;
+import org.jboss.interceptor.util.proxy.TargetInstanceProxy;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
import org.jboss.weld.DeploymentException;
@@ -158,6 +159,7 @@
if (hasDecorators())
{
Set<Type> types = new LinkedHashSet<Type>(getTypes());
+ types.add(TargetInstanceProxy.class);
ProxyFactory proxyFactory = Proxies.getProxyFactory(types);
@SuppressWarnings("unchecked")
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2009-10-29
03:18:39 UTC (rev 4368)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2009-10-29
03:23:25 UTC (rev 4369)
@@ -25,6 +25,7 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.Producer;
+import org.jboss.interceptor.util.InterceptionUtils;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.introspector.WeldField;
@@ -94,7 +95,8 @@
public T produce(CreationalContext<T> creationalContext)
{
- return field.get(getReceiver(creationalContext));
+ // unwrap if we have a proxy
+ return
field.get(InterceptionUtils.getRawInstance(getReceiver(creationalContext)));
}
});
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java 2009-10-29
03:18:39 UTC (rev 4368)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java 2009-10-29
03:23:25 UTC (rev 4369)
@@ -18,17 +18,15 @@
import static org.jboss.weld.util.Reflections.ensureAccessible;
-import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.List;
-import javassist.util.proxy.MethodHandler;
-
+import org.jboss.interceptor.util.proxy.TargetInstanceProxyMethodHandler;
import org.jboss.weld.bean.DecoratorImpl;
-import org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance;
import org.jboss.weld.introspector.MethodSignature;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.jlr.MethodSignatureImpl;
+import org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance;
/**
* Method handler for decorated beans
@@ -36,13 +34,11 @@
* @author Pete Muir
*
*/
-public class DecoratorProxyMethodHandler implements MethodHandler, Serializable
+public class DecoratorProxyMethodHandler extends TargetInstanceProxyMethodHandler
{
private static final long serialVersionUID = 4577632640130385060L;
private final List<SerializableContextualInstance<DecoratorImpl<Object>,
Object>> decoratorInstances;
-
- private final Object instance;
/**
* Constructor
@@ -53,8 +49,8 @@
*/
public
DecoratorProxyMethodHandler(List<SerializableContextualInstance<DecoratorImpl<Object>,
Object>> decoratorInstances, Object instance)
{
+ super (instance, instance.getClass());
this.decoratorInstances = decoratorInstances;
- this.instance = instance;
}
/**
@@ -74,7 +70,7 @@
*
* @throws Throwable if the method invocation fails.
*/
- public Object invoke(Object self, Method method, Method proceed, Object[] args) throws
Throwable
+ protected Object doInvoke(Object self, Method method, Method proceed, Object[] args)
throws Throwable
{
MethodSignature methodSignature = new MethodSignatureImpl(method);
for (SerializableContextualInstance<DecoratorImpl<Object>, Object>
beanInstance : decoratorInstances)
@@ -86,7 +82,6 @@
}
}
- return ensureAccessible(method).invoke(instance, args);
+ return ensureAccessible(method).invoke(getTargetInstance(), args);
}
-
}
Show replies by date