1 22 package org.jboss.ejb3.test.interceptors2; 23 24 import java.io.Serializable ; 25 26 import javax.annotation.Resource; 27 import javax.ejb.EJBContext ; 28 import javax.interceptor.InvocationContext; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 32 37 public class DefaultInterceptor implements Serializable 38 { 39 @Resource 40 EJBContext ejbCtx; 41 42 static int currentInstance; 43 int instance = ++currentInstance; 44 45 private StatusRemote findStatusRemote() 46 { 47 try 48 { 49 InitialContext ctx = new InitialContext (); 50 StatusRemote status = (StatusRemote)ctx.lookup("StatusBean/remote"); 51 return status; 52 } 53 catch (NamingException e) 54 { 55 throw new RuntimeException (e); 56 } 57 } 58 59 60 public Object intercept(InvocationContext ctx) throws Exception 61 { 62 System.out.println("DefaultInterceptor intercepting!"); 63 StatusRemote status = findStatusRemote(); 64 status.addInterception(new Interception(this, "intercept", instance)); 65 return ctx.proceed(); 66 } 67 68 public void postConstruct(InvocationContext ctx) 69 { 70 System.out.println("DefaultInterceptor pc!"); 71 StatusBean.addPostConstruct(new Interception(this, "postConstruct", instance)); 72 try 73 { 74 ctx.proceed(); 75 } 76 catch (Exception e) 77 { 78 throw new RuntimeException (e); 79 } 80 } 81 82 public void postActivate(InvocationContext ctx) throws Exception 83 { 84 System.out.println("DefaultInterceptor pa!"); 85 StatusBean.addPostActivate(new Interception(this, "postActivate", instance)); 86 try 87 { 88 ctx.proceed(); 89 } 90 catch (Exception e) 91 { 92 throw new RuntimeException (e); 93 } 94 } 95 96 public void prePassivate(InvocationContext ctx) 97 { 98 System.out.println("DefaultInterceptor pp!"); 99 StatusBean.addPrePassivate(new Interception(this, "prePassivate", instance)); 100 try 101 { 102 ctx.proceed(); 103 } 104 catch (Exception e) 105 { 106 throw new RuntimeException (e); 107 } 108 } 109 110 public void preDestroy(InvocationContext ctx) 111 { 112 System.out.println("DefaultInterceptor pd!"); 113 StatusBean.addPreDestroy(new Interception(this, "preDestroy", instance)); 114 try 115 { 116 ctx.proceed(); 117 } 118 catch (Exception e) 119 { 120 throw new RuntimeException (e); 121 } 122 } 123 } 124 | Popular Tags |