1 25 26 package org.objectweb.easybeans.tests.enhancer.interceptors.business.bean; 27 28 import java.lang.reflect.Method ; 29 import java.util.Map ; 30 31 import javax.interceptor.AroundInvoke; 32 import javax.interceptor.InvocationContext; 33 34 38 public class SingleMethodInterceptor { 39 40 47 @AroundInvoke 48 public Object onlySingleMethod(final InvocationContext invocationContext) throws Exception { 49 Method m = invocationContext.getMethod(); 50 if (!m.getName().equals("singleMethodIntercepted")) { 52 throw new Exception ("Interceptor should only be called on a single method"); 53 } 54 55 Object o = invocationContext.getTarget(); 57 if (o instanceof StatelessBean) { 58 StatelessBean bean = (StatelessBean) o; 59 bean.incrementSingleMethodInterceptedCounter(); 60 } else { 61 throw new Exception ("Bean is not a stateless bean"); 62 } 63 64 Map contextData = invocationContext.getContextData(); 66 Object obj = contextData.get("KEY"); 67 if (obj == null) { 68 throw new Exception ("Objects are not propagated in the Map ContextData"); 69 } 70 if (obj instanceof String ) { 71 String value = (String ) obj; 72 if (!value.equals("TEST")) { 73 throw new Exception ("Object value has been changed in the map ContextData."); 74 } 75 } else { 76 throw new Exception ("Object type has been changed in the map ContextData."); 77 } 78 79 return invocationContext.proceed(); 80 } 81 82 } 83 | Popular Tags |