Author: pete.muir(a)jboss.org
Date: 2009-03-14 09:01:37 -0400 (Sat, 14 Mar 2009)
New Revision: 1989
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java
Log:
use predestroy callback to note bean instance was removed
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-14
00:07:04 UTC (rev 1988)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-14
13:01:37 UTC (rev 1989)
@@ -238,6 +238,10 @@
{
throw new IllegalArgumentException("instance to destroy cannot be
null");
}
+ if (!(instance instanceof EnterpriseBeanInstance))
+ {
+ throw new IllegalArgumentException("Cannot destroy session bean instance
not created by the container");
+ }
EnterpriseBeanInstance enterpiseBeanInstance = (EnterpriseBeanInstance) instance;
if (enterpiseBeanInstance.isDestroyed())
{
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java 2009-03-14
00:07:04 UTC (rev 1988)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanInstance.java 2009-03-14
13:01:37 UTC (rev 1989)
@@ -16,11 +16,9 @@
*/
package org.jboss.webbeans.bean.proxy;
-import java.util.Collection;
/**
- * Interface implemented by all enterprise bean proxies to determine if
- * the enterprise bean has already had a remove method called by the application
+ * Interface implemented by all enterprise bean proxies to query/control the proxy
*
* @author Pete Muir
*
@@ -35,10 +33,6 @@
*/
public boolean isDestroyed();
- /**
- * The unproxied version of this object
- * @return
- */
- public Collection<Object> getUnproxiedInstances();
+ public void setDestroyed(boolean destroyed);
}
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-03-14
00:07:04 UTC (rev 1988)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-03-14
13:01:37 UTC (rev 1989)
@@ -61,6 +61,7 @@
}
+ // TODO Surely we can do this better!
public static boolean isContextualInstance(Class<?> beanClass)
{
return contextualInstance.get().contains(beanClass);
@@ -127,6 +128,24 @@
{
return destroyed;
}
+ else if ("setDestroyed".equals(method.getName()))
+ {
+ if (args.length != 1)
+ {
+ throw new
IllegalArgumentException("enterpriseBeanInstance.setDestroyed() called with >1
argument");
+ }
+ if (!args[0].getClass().equals(boolean.class))
+ {
+ throw new
IllegalArgumentException("enterpriseBeanInstance.setDestroyed() called with
non-boolean argument");
+ }
+ destroyed = ((Boolean) args[0]).booleanValue();
+ }
+
+ if (destroyed)
+ {
+ return null;
+ }
+
Class<?> businessInterface = method.getDeclaringClass();
Object proxiedInstance = proxiedInstances.get(businessInterface);
if (proxiedInstance == null)
@@ -148,17 +167,6 @@
proxiedInstances.put(businessInterface, proxiedInstance);
}
Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
- if (removeMethods.contains(proxiedMethod))
- {
- if (canCallRemoveMethods)
- {
- destroyed = true;
- }
- else
- {
- throw new UnsupportedOperationException("Remove method can't be
called directly on non-dependent scoped Enterprise Beans");
- }
- }
try
{
setContextualInstance(beanClass, true);
@@ -172,4 +180,5 @@
}
}
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java 2009-03-14
00:07:04 UTC (rev 1988)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java 2009-03-14
13:01:37 UTC (rev 1989)
@@ -23,6 +23,7 @@
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.bean.proxy.EnterpriseBeanInstance;
import org.jboss.webbeans.bean.proxy.EnterpriseBeanProxyMethodHandler;
/**
@@ -65,6 +66,7 @@
{
enterpriseBean.preDestroy(target);
}
+ getEnterpriseBeanInstance(enterpriseBean).setDestroyed(true);
invocationContext.proceed();
}
@@ -78,12 +80,28 @@
{
if (EnterpriseBeanProxyMethodHandler.isContextualInstance(beanClass))
{
+ // Access all non-new enterprise beans.
+ // TODO Deal with XML defined enterprise beans!
return (EnterpriseBean<T>)
CurrentManager.rootManager().getEnterpriseBeanMap().get(beanClass);
}
else
{
+ // Access all @New enterprise beans
return (EnterpriseBean<T>)
CurrentManager.rootManager().getNewEnterpriseBeanMap().get(beanClass);
}
}
+
+ private static <T> EnterpriseBeanInstance
getEnterpriseBeanInstance(EnterpriseBean<T> bean)
+ {
+ T instance =
CurrentManager.rootManager().getContext(bean.getScopeType()).get(bean);
+ if (instance instanceof EnterpriseBeanInstance)
+ {
+ return (EnterpriseBeanInstance) instance;
+ }
+ else
+ {
+ throw new IllegalStateException("Contextual instance not an session bean
created by the container");
+ }
+ }
}
Show replies by date