1 package org.apache.ojb.broker.util.interceptor; 2 3 17 18 import java.lang.reflect.Method ; 19 20 import java.lang.reflect.InvocationHandler ; 22 26 30 public abstract class Interceptor implements InvocationHandler 31 { 32 33 private Object realSubject = null; 34 35 38 public Object invoke(Object proxy, Method methodToBeInvoked, Object [] args) throws Throwable 39 { 40 beforeInvoke(proxy, methodToBeInvoked, args); 41 Object result = null; 42 result = doInvoke(proxy, methodToBeInvoked, args); 43 afterInvoke(proxy, methodToBeInvoked, args); 44 return result; 45 } 46 47 50 protected abstract void beforeInvoke(Object proxy, Method methodToBeInvoked, Object [] args) 51 throws Throwable ; 52 53 56 protected abstract void afterInvoke(Object proxy, Method methodToBeInvoked, Object [] args) 57 throws Throwable ; 58 59 62 protected Object doInvoke(Object proxy, Method methodToBeInvoked, Object [] args) 63 throws Throwable 64 { 65 Method m = 66 getRealSubject().getClass().getMethod( 67 methodToBeInvoked.getName(), 68 methodToBeInvoked.getParameterTypes()); 69 return m.invoke(getRealSubject(), args); 70 } 71 72 76 public Object getRealSubject() 77 { 78 return realSubject; 79 } 80 81 85 public void setRealSubject(Object realSubject) 86 { 87 this.realSubject = realSubject; 88 } 89 90 } 91 | Popular Tags |