Skip to content

Commit

Permalink
Fix field injection and producer fields when instance is decorated/in…
Browse files Browse the repository at this point in the history
…tercepted.
  • Loading branch information
mbogoevici committed Oct 29, 2009
1 parent 0a42a48 commit 1eef37f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
Expand Up @@ -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;
Expand Down Expand Up @@ -158,6 +159,7 @@ protected void initProxyClassForDecoratedBean()
if (hasDecorators())
{
Set<Type> types = new LinkedHashSet<Type>(getTypes());
types.add(TargetInstanceProxy.class);
ProxyFactory proxyFactory = Proxies.getProxyFactory(types);

@SuppressWarnings("unchecked")
Expand Down
4 changes: 3 additions & 1 deletion impl/src/main/java/org/jboss/weld/bean/ProducerField.java
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,8 @@ public Set<InjectionPoint> getInjectionPoints()

public T produce(CreationalContext<T> creationalContext)
{
return field.get(getReceiver(creationalContext));
// unwrap if we have a proxy
return field.get(InterceptionUtils.getRawInstance(getReceiver(creationalContext)));
}

});
Expand Down
Expand Up @@ -18,31 +18,27 @@

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
*
* @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
Expand All @@ -53,8 +49,8 @@ public class DecoratorProxyMethodHandler implements MethodHandler, Serializable
*/
public DecoratorProxyMethodHandler(List<SerializableContextualInstance<DecoratorImpl<Object>, Object>> decoratorInstances, Object instance)
{
super (instance, instance.getClass());
this.decoratorInstances = decoratorInstances;
this.instance = instance;
}

/**
Expand All @@ -74,7 +70,7 @@ public DecoratorProxyMethodHandler(List<SerializableContextualInstance<Decorator
*
* @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)
Expand All @@ -86,7 +82,6 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args)
}
}

return ensureAccessible(method).invoke(instance, args);
return ensureAccessible(method).invoke(getTargetInstance(), args);
}

}

0 comments on commit 1eef37f

Please sign in to comment.