
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class DebugProxy implements InvocationHandler{

	private Object obj;

	public static Object newInstance(Object obj) {

		return java.lang.reflect.Proxy.newProxyInstance(
			obj.getClass().getClassLoader(),
			obj.getClass().getInterfaces(),
			new DebugProxy(obj));
	}


	private DebugProxy(Object obj) {
		this.obj = obj;
	}


	public Object invoke(Object proxy, Method m, Object[] args)
		throws Throwable {
		Object result;

		try {

			System.out.println("before method");

			result = m.invoke(obj, args);
			
			System.out.println("before method");
			
			return result;

		} catch (InvocationTargetException e) {

			throw e.getTargetException();

		} catch (Throwable e) {
			
			throw e;

		} finally {
			
		}

	}

}
