1 package org.sape.carbon.core.component.proxy; 2 3 import java.lang.reflect.InvocationHandler ; 4 import java.lang.reflect.Method ; 5 import java.lang.reflect.Proxy ; 6 7 19 public abstract class AbstractInterceptor implements Interceptor { 20 21 24 protected Interceptor nextInterceptor; 25 26 29 protected boolean nextInterceptorIsProxy; 30 31 35 protected InvocationHandler nextInvocationHandler; 36 37 40 private Method interceptorMethod; 41 42 43 44 51 public void setNextInterceptor(Interceptor interceptor) { 52 this.nextInterceptor = interceptor; 53 this.nextInterceptorIsProxy = Proxy.isProxyClass(interceptor.getClass()); 54 55 if (this.nextInterceptorIsProxy) { 57 this.nextInvocationHandler = Proxy.getInvocationHandler(interceptor); 58 try { 59 this.interceptorMethod = 60 Interceptor.class.getMethod("invoke", new Class [] { Invocation.class }); 61 } catch (NoSuchMethodException nsme) { 62 } 64 } 65 } 66 67 74 protected Object callNextInterceptor(Invocation invocation) throws Throwable { 75 if (this.nextInterceptorIsProxy) { 76 return this.nextInvocationHandler.invoke( 77 this.nextInterceptor, 78 this.interceptorMethod, 79 new Object [] { invocation }); 80 } else { 81 return this.nextInterceptor.invoke(invocation); 82 83 } 84 } 85 86 } 87 | Popular Tags |