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