1 22 package org.jboss.ejb3.test.interceptors2; 23 24 import java.io.Serializable ; 25 26 import javax.annotation.Resource; 27 import javax.annotation.PostConstruct; 28 import javax.interceptor.AroundInvoke; 29 import javax.ejb.EJBContext ; 30 import javax.interceptor.InvocationContext; 31 import javax.ejb.PostActivate ; 32 import javax.annotation.PreDestroy; 33 import javax.ejb.PrePassivate ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 36 37 42 public class AnnotatedClassInterceptor3 implements Serializable 43 { 44 @Resource 45 EJBContext ejbCtx; 46 47 static int currentInstance; 48 int instance = ++currentInstance; 49 50 @AroundInvoke 51 public Object intercept3(InvocationContext ctx) throws Exception 52 { 53 StatusRemote status = findStatusRemote(); 54 status.addInterception(new Interception(this, "intercept3", instance)); 55 return ctx.proceed(); 56 } 57 58 private StatusRemote findStatusRemote() 59 { 60 try 61 { 62 InitialContext ctx = new InitialContext (); 63 StatusRemote status = (StatusRemote)ctx.lookup("StatusBean/remote"); 64 return status; 65 } 66 catch (NamingException e) 67 { 68 throw new RuntimeException (e); 69 } 70 } 71 72 @PostConstruct 73 public void postConstruct3(InvocationContext ctx) 74 { 75 StatusRemote status = findStatusRemote(); 76 status.addLifecycle(PostConstruct.class, new Interception(this, "postConstruct3", instance)); 77 try 78 { 79 ctx.proceed(); 80 } 81 catch (Exception e) 82 { 83 throw new RuntimeException (e); 84 } 85 } 86 87 @PostActivate 88 public void postActivate3(InvocationContext ctx) 89 { 90 StatusRemote status = findStatusRemote(); 91 status.addLifecycle(PostActivate .class, new Interception(this, "postActivate3", instance)); 92 try 93 { 94 ctx.proceed(); 95 } 96 catch (Exception e) 97 { 98 throw new RuntimeException (e); 99 } 100 } 101 102 @PrePassivate 103 public void prePassivate3(InvocationContext ctx) 104 { 105 StatusRemote status = findStatusRemote(); 106 status.addLifecycle(PrePassivate .class, new Interception(this, "prePassivate3", instance)); 107 try 108 { 109 ctx.proceed(); 110 } 111 catch (Exception e) 112 { 113 throw new RuntimeException (e); 114 } 115 } 116 117 @PreDestroy 118 public void preDestroy3(InvocationContext ctx) 119 { 120 StatusRemote status = findStatusRemote(); 121 status.addLifecycle(PreDestroy.class, new Interception(this, "preDestroy3", instance)); 122 try 123 { 124 ctx.proceed(); 125 } 126 catch (Exception e) 127 { 128 throw new RuntimeException (e); 129 } 130 } 131 } 132 | Popular Tags |