1 22 package org.jboss.ejb3.test.interceptors2; 23 24 import javax.interceptor.AroundInvoke; 25 import javax.interceptor.InvocationContext; 26 import javax.ejb.PostActivate ; 27 import javax.annotation.PostConstruct; 28 import javax.annotation.PreDestroy; 29 import javax.ejb.PrePassivate ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NamingException ; 32 33 38 public class AnnotatedClassInterceptor extends AnnotatedClassInterceptor2 39 { 40 @AroundInvoke 41 public Object intercept(InvocationContext inv) throws Exception 42 { 43 System.out.println("AnnotatedClassInterceptor intercepting!"); 44 InitialContext ctx = new InitialContext (); 45 StatusRemote status = (StatusRemote)ctx.lookup("StatusBean/remote"); 46 status.addInterception(new Interception(this, "intercept", instance)); 47 return inv.proceed(); 48 } 49 50 @PostConstruct 51 public void postConstruct(InvocationContext inv) 52 { 53 StatusRemote status = null; 54 status = findStatusRemote(); 55 status.addLifecycle(PostConstruct.class, new Interception(this, "postConstruct", instance)); 56 try 57 { 58 inv.proceed(); 59 } 60 catch (Exception e) 61 { 62 throw new RuntimeException (e); 63 } 64 } 65 66 @PostActivate 67 public void postActivate(InvocationContext inv) 68 { 69 StatusRemote status = null; 70 status = findStatusRemote(); 71 status.addLifecycle(PostActivate .class, new Interception(this, "postActivate", instance)); 72 try 73 { 74 inv.proceed(); 75 } 76 catch (Exception e) 77 { 78 throw new RuntimeException (e); 79 } 80 } 81 82 private StatusRemote findStatusRemote() 83 { 84 StatusRemote status; 85 try 86 { 87 InitialContext ctx = new InitialContext (); 88 status = (StatusRemote)ctx.lookup("StatusBean/remote"); 89 } 90 catch (NamingException e) 91 { 92 throw new RuntimeException (e); 93 } 94 return status; 95 } 96 97 @PrePassivate 98 public void prePassivate(InvocationContext ctx) 99 { 100 StatusRemote status = findStatusRemote(); 101 status.addLifecycle(PrePassivate .class, new Interception(this, "prePassivate", instance)); 102 try 103 { 104 ctx.proceed(); 105 } 106 catch (Exception e) 107 { 108 throw new RuntimeException (e); 109 } 110 } 111 112 @PreDestroy 113 public void preDestroy(InvocationContext ctx) 114 { 115 StatusRemote status = findStatusRemote(); 116 status.addLifecycle(PreDestroy.class, new Interception(this, "preDestroy", instance)); 117 try 118 { 119 ctx.proceed(); 120 } 121 catch (Exception e) 122 { 123 throw new RuntimeException (e); 124 } 125 } 126 127 public Object intercept2(InvocationContext ctx) throws Exception 128 { 129 throw new RuntimeException ("Should not be called"); 130 } 131 132 public void postConstruct2(InvocationContext ctx) 133 { 134 throw new RuntimeException ("Should not be called"); 135 } 136 137 public void postActivate2(InvocationContext ctx) 138 { 139 throw new RuntimeException ("Should not be called"); 140 } 141 142 public void prePassivate2(InvocationContext ctx) 143 { 144 throw new RuntimeException ("Should not be called"); 145 } 146 147 public void preDestroy2(InvocationContext ctx) 148 { 149 throw new RuntimeException ("Should not be called"); 150 } 151 152 } 153 | Popular Tags |