1 22 package org.jboss.test.jmx.compliance.server.support; 23 24 import java.lang.reflect.InvocationHandler ; 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Proxy ; 27 28 import javax.management.MBeanServer ; 29 30 36 public class MBeanServerWrapper 37 implements InvocationHandler 38 { 39 public MBeanServer server; 40 41 public boolean invoked = false; 42 43 private static Method EQUALS; 44 45 static 46 { 47 try 48 { 49 EQUALS = Object .class.getClass().getMethod("equals", new Class [] { Object .class }); 50 } 51 catch (Exception e) 52 { 53 throw new RuntimeException (e.toString()); 54 } 55 } 56 57 public static MBeanServer getWrapper() 58 { 59 return (MBeanServer ) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), 60 new Class [] { MBeanServer .class }, 61 new MBeanServerWrapper()); 62 } 63 64 public static MBeanServerWrapper getHandler(MBeanServer proxy) 65 { 66 return (MBeanServerWrapper) Proxy.getInvocationHandler(proxy); 67 } 68 69 public Object invoke(Object proxy, Method method, Object [] args) 70 throws Throwable 71 { 72 invoked = true; 73 if (method.equals(EQUALS)) 74 return new Boolean (proxy == args[0]); 75 if (method.getName().equals("queryMBeans")) 76 throw new MBeanServerReplaced(); 77 return method.invoke(server, args); 78 } 79 } 80 | Popular Tags |