1 22 package org.jboss.mx.util; 23 24 import javax.management.MBeanServer ; 25 import javax.management.ObjectName ; 26 import java.lang.reflect.Proxy ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 45 public class MBeanTyper 46 { 47 static final boolean DEBUG = Boolean.getBoolean("jboss.jmx.debug"); 48 49 52 public static final Object typeMBean(MBeanServer server, ObjectName mbean, Class mainInterface) 53 throws Exception 54 { 55 List interfaces = new ArrayList (); 56 if (mainInterface.isInterface()) 57 { 58 interfaces.add(mainInterface); 59 } 60 addInterfaces(mainInterface.getInterfaces(), interfaces); 61 Class cl[] = (Class []) interfaces.toArray(new Class [interfaces.size()]); 62 if (DEBUG) 63 { 64 System.err.println("typeMean->server=" + server + ",mbean=" + mbean + ",mainInterface=" + mainInterface); 65 for (int c = 0; c < cl.length; c++) 66 { 67 System.err.println(" :" + cl[c]); 68 } 69 } 70 71 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), cl, new MBeanTyperInvoker(server, mbean)); 72 } 73 74 private static final void addInterfaces(Class cl[], List list) 75 { 76 if (cl == null) return; 77 for (int c = 0; c < cl.length; c++) 78 { 79 list.add(cl[c]); 80 addInterfaces(cl[c].getInterfaces(), list); 81 } 82 } 83 } 84 | Popular Tags |