package com.sun.enterprise.monitor; import java.lang.reflect.*; /** * dynamic proxy for returning monitoring statistic data types * @author Sreenivas Munnangi */ public class StatsProxy implements java.lang.reflect.InvocationHandler { private Object obj; public static Object newInstance(Object obj) { return java.lang.reflect.Proxy.newProxyInstance( obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new StatsProxy(obj)); } private StatsProxy(Object obj) { this.obj = obj; } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { Object result; try { System.out.println("statsproxy before method " + m.getName()); result = m.invoke(obj, args); System.out.println("result = " + result); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (Exception e) { throw new RuntimeException("unexpected invocation exception: " + e.getMessage()); } finally { System.out.println("statsproxy after method " + m.getName()); } return result; } }