From: Bill D. <bde...@jb...> - 2005-06-12 21:59:13
|
User: bdecoste Date: 05/06/12 17:58:42 Modified: src/main/org/jboss/ejb3/stateful Stateful21Container.java Log: more EJBHome, EJBLocalHome, EJBObject, EJBLocalObject support Revision Changes Path 1.5 +71 -24 jboss-ejb3/src/main/org/jboss/ejb3/stateful/Stateful21Container.java (In the diff below, changes in quantity of whitespace are not shown.) Index: Stateful21Container.java =================================================================== RCS file: /cvsroot/jboss/jboss-ejb3/src/main/org/jboss/ejb3/stateful/Stateful21Container.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- Stateful21Container.java 12 Jun 2005 19:58:57 -0000 1.4 +++ Stateful21Container.java 12 Jun 2005 21:58:42 -0000 1.5 @@ -43,7 +43,7 @@ * Comment * * @author <a href="mailto:bi...@jb...">Bill Burke</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class Stateful21Container extends StatefulContainer { @@ -68,6 +68,13 @@ long hash = MethodHashing.methodHash(declaredMethods[i]); advisedMethods.put(hash, declaredMethods[i]); } + + declaredMethods = javax.ejb.EJBObject.class.getMethods(); + for (int i = 0; i < declaredMethods.length; i++) + { + long hash = MethodHashing.methodHash(declaredMethods[i]); + advisedMethods.put(hash, declaredMethods[i]); + } } LocalHome localHome = (LocalHome)resolveAnnotation(LocalHome.class); @@ -79,11 +86,8 @@ long hash = MethodHashing.methodHash(declaredMethods[i]); advisedMethods.put(hash, declaredMethods[i]); } - } - if (home != null || localHome != null) - { - Method[] declaredMethods = javax.ejb.EJBObject.class.getMethods(); + declaredMethods = javax.ejb.EJBLocalObject.class.getMethods(); for (int i = 0; i < declaredMethods.length; i++) { long hash = MethodHashing.methodHash(declaredMethods[i]); @@ -112,8 +116,13 @@ { throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString()); } - if(info.unadvisedMethod != null && isHomeMethod(info.unadvisedMethod)){ + + if (info.unadvisedMethod != null && isHomeMethod(info.unadvisedMethod)) + { return invokeLocalHomeMethod(info, args); + } else if (info.unadvisedMethod != null && isEJBObjectMethod(info.unadvisedMethod)) + { + return invokeEJBLocalObjectMethod(id, info, args); } Interceptor[] aspects = info.interceptors; @@ -131,6 +140,23 @@ } } + private Object invokeEJBLocalObjectMethod(Object id, MethodInfo info, Object[] args) throws Exception + { + if (info.unadvisedMethod.getName().equals("remove")) + { + Object bean = getCache().get(id).getInstance(); + + invokePreDestroy(bean); + + getCache().remove(id); + + return null; + } else // TODO + { + return null; + } + } + private Object invokeLocalHomeMethod(MethodInfo info, Object[] args) throws Exception { if (info.unadvisedMethod.getName().equals("create")) @@ -152,7 +178,18 @@ Object proxy = factory.createProxy(initParameterTypes, initParameterValues); return proxy; - } else // remove + } else if (info.unadvisedMethod.getName().equals("remove")) + { + StatefulHandleImpl handle = (StatefulHandleImpl)args[0]; + + Object bean = getCache().get(handle.id).getInstance(); + + invokePreDestroy(bean); + + getCache().remove(handle.id); + + return null; + } else // TODO { return null; } @@ -236,7 +273,6 @@ if (localHomeAnnotation != null) localHome = localHomeAnnotation.value(); - // TODO remove and other home methods if (method.getDeclaringClass().getName().equals("javax.ejb.EJBHome")) return true; @@ -256,9 +292,10 @@ protected boolean isEJBObjectMethod(Method method) { if (method.getDeclaringClass().getName().equals("javax.ejb.EJBObject")) - { return true; - } + + if (method.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject")) + return true; return false; } @@ -332,14 +369,13 @@ protected InvocationResponse invokeEJBObjectMethod(MethodInfo info, StatefulRemoteInvocation statefulInvocation) throws Throwable { - if (info.unadvisedMethod.getName().equals("getHandle")) - { ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); ThreadLocalENCFactory.push(enc); try { Thread.currentThread().setContextClassLoader(classloader); - + if (info.unadvisedMethod.getName().equals("getHandle")) + { StatefulContainerInvocation newStatefulInvocation = buildInvocation(info, statefulInvocation); StatefulHandleImpl handle = new StatefulHandleImpl(); @@ -349,15 +385,26 @@ response.setContextInfo(newStatefulInvocation.getResponseContextInfo()); return response; - } finally + } else if (info.unadvisedMethod.getName().equals("remove")) { - Thread.currentThread().setContextClassLoader(oldLoader); - ThreadLocalENCFactory.pop(); - } + Object bean = getCache().get(statefulInvocation.getId()).getInstance(); + + invokePreDestroy(bean); + + getCache().remove(statefulInvocation.getId()); + + InvocationResponse response = new InvocationResponse(null); + response.setContextInfo(statefulInvocation.getResponseContextInfo()); + return response; } else // TODO { return null; } + } finally + { + Thread.currentThread().setContextClassLoader(oldLoader); + ThreadLocalENCFactory.pop(); + } } public void invokeInit(Object bean, Class[] initParameterTypes, Object[] initParameterValues) |