1 22 23 package org.jboss.spring.callback; 24 25 import java.io.Serializable ; 26 import java.lang.reflect.Field ; 27 import java.lang.reflect.Modifier ; 28 import javax.annotation.PreDestroy; 29 import javax.ejb.PostActivate ; 30 import javax.ejb.PrePassivate ; 31 import javax.interceptor.InvocationContext; 32 33 import org.jboss.spring.support.SpringInjectionSupport; 34 35 43 public class SpringPassivationInterceptor extends SpringInjectionSupport implements Serializable 44 { 45 46 private static final long serialVersionUID = -7259379236645796135L; 47 48 @PostActivate 49 public void postActivate(InvocationContext ctx) throws Exception 50 { 51 inject(ctx.getTarget()); 52 ctx.proceed(); 53 } 54 55 @PrePassivate 56 public void prePassivate(InvocationContext ctx) throws Exception 57 { 58 Field [] fields = getAllFields(ctx.getTarget()); 59 for (Field f : fields) 60 { 61 boolean isSerializable = Serializable .class.isAssignableFrom(f.getType()); 62 boolean isTransient = Modifier.isTransient(f.getModifiers()); 63 if (!isSerializable && !isTransient) 64 { 65 f.setAccessible(true); 66 f.set(ctx.getTarget(), null); 67 } 68 } 69 ctx.proceed(); 70 } 71 72 @PreDestroy 73 public void preDestroy(InvocationContext ctx) throws Exception 74 { 75 ctx.proceed(); 76 } 77 78 } 79 | Popular Tags |