Author: dallen6
Date: 2010-04-27 15:32:14 -0400 (Tue, 27 Apr 2010)
New Revision: 6167
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
Log:
Fixed problem with enterprise bean proxies; constructors and remove methods.
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java 2010-04-27
18:33:24 UTC (rev 6166)
+++
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java 2010-04-27
19:32:14 UTC (rev 6167)
@@ -19,7 +19,9 @@
import javassist.CtClass;
import javassist.CtConstructor;
+import javassist.CtMethod;
import javassist.CtNewConstructor;
+import javassist.CtNewMethod;
import org.jboss.weld.exceptions.WeldException;
@@ -42,10 +44,8 @@
public EnterpriseProxyFactory(Class<T> proxiedBeanType)
{
super(proxiedBeanType);
- addInterface(EnterpriseBeanInstance.class);
}
- // Not sure this is a useful approach, but non-default constructors are problematic
(DRA)
@Override
protected void addConstructors(CtClass proxyClassType)
{
@@ -54,7 +54,7 @@
CtClass baseType = classPool.get(beanType.getName());
for (CtConstructor constructor : baseType.getConstructors())
{
- proxyClassType.addConstructor(CtNewConstructor.copy(constructor,
proxyClassType, null));
+
proxyClassType.addConstructor(CtNewConstructor.make(constructor.getParameterTypes(),
constructor.getExceptionTypes(), proxyClassType));
}
}
catch (Exception e)
@@ -69,4 +69,26 @@
return PROXY_SUFFIX;
}
+ @Override
+ protected void addSpecialMethods(CtClass proxyClassType)
+ {
+ super.addSpecialMethods(proxyClassType);
+
+ // Add methods for the EnterpriseBeanInstance interface
+ try
+ {
+ CtClass enterpriseBeanInstanceInterface =
classPool.get(EnterpriseBeanInstance.class.getName());
+ proxyClassType.addInterface(enterpriseBeanInstanceInterface);
+ for (CtMethod method : enterpriseBeanInstanceInterface.getDeclaredMethods())
+ {
+ log.trace("Adding method " + method.getLongName());
+ proxyClassType.addMethod(CtNewMethod.make(method.getReturnType(),
method.getName(), method.getParameterTypes(), method.getExceptionTypes(),
createSpecialInterfaceBody(method, EnterpriseBeanInstance.class), proxyClassType));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+
+ }
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-04-27
18:33:24 UTC (rev 6166)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-04-27
19:32:14 UTC (rev 6167)
@@ -381,7 +381,12 @@
}
}
- private void addSpecialMethods(CtClass proxyClassType)
+ /**
+ * Adds methods requiring special implementations rather than just delegation.
+ *
+ * @param proxyClassType the Javassist class description for the proxy type
+ */
+ protected void addSpecialMethods(CtClass proxyClassType)
{
try
{
@@ -394,7 +399,7 @@
for (CtMethod method : lifecycleMixinClass.getDeclaredMethods())
{
log.trace("Adding method " + method.getLongName());
- proxyClassType.addMethod(CtNewMethod.make(method.getReturnType(),
method.getName(), method.getParameterTypes(), method.getExceptionTypes(),
createLifecycleBody(method), proxyClassType));
+ proxyClassType.addMethod(CtNewMethod.make(method.getReturnType(),
method.getName(), method.getParameterTypes(), method.getExceptionTypes(),
createSpecialInterfaceBody(method, LifecycleMixin.class), proxyClassType));
}
CtClass targetInstanceProxyClass =
classPool.get(TargetInstanceProxy.class.getName());
CtMethod getInstanceMethod =
targetInstanceProxyClass.getDeclaredMethod("getTargetInstance");
@@ -409,18 +414,19 @@
}
/**
- * Creates the method body code for lifecycle methods which forward the calls
- * directly to the bean instance.
+ * Creates the method body code for methods which forward the calls
+ * directly to the bean instance. These methods are not considered
+ * to be implemented by any superclass of the proxy.
*
- * @param method a lifecycle method
+ * @param method a method
* @return code for the body of the method to be compiled
* @throws NotFoundException if any of the parameter types are not found
*/
- private String createLifecycleBody(CtMethod method) throws NotFoundException
+ protected String createSpecialInterfaceBody(CtMethod method, Class<?>
interfaceClazz) throws NotFoundException
{
StringBuilder bodyString = new StringBuilder();
bodyString.append("{ beanInstance.invoke(");
- bodyString.append(LifecycleMixin.class.getName());
+ bodyString.append(interfaceClazz.getName());
bodyString.append(".class.getDeclaredMethod(\"");
bodyString.append(method.getName());
bodyString.append("\", ");