1 7 8 package test.compliance.server.support; 9 10 import java.lang.reflect.InvocationHandler; 11 import java.lang.reflect.Method; 12 import java.lang.reflect.Proxy; 13 14 import javax.management.MBeanServer; 15 16 22 public class MBeanServerWrapper 23 implements InvocationHandler 24 { 25 public MBeanServer server; 26 27 public boolean invoked = false; 28 29 private static Method EQUALS; 30 31 static 32 { 33 try 34 { 35 EQUALS = Object.class.getClass().getMethod("equals", new Class[] { Object.class }); 36 } 37 catch (Exception e) 38 { 39 throw new RuntimeException(e.toString()); 40 } 41 } 42 43 public static MBeanServer getWrapper() 44 { 45 return (MBeanServer) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), 46 new Class[] { MBeanServer.class }, 47 new MBeanServerWrapper()); 48 } 49 50 public static MBeanServerWrapper getHandler(MBeanServer proxy) 51 { 52 return (MBeanServerWrapper) Proxy.getInvocationHandler(proxy); 53 } 54 55 public Object invoke(Object proxy, Method method, Object[] args) 56 throws Throwable 57 { 58 invoked = true; 59 if (method.equals(EQUALS)) 60 return new Boolean(proxy == args[0]); 61 if (method.getName().equals("queryMBeans")) 62 throw new MBeanServerReplaced(); 63 return method.invoke(server, args); 64 } 65 } 66 | Popular Tags |