1 16 17 package org.springframework.jmx.support; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 22 import javax.management.MBeanServer ; 23 24 import org.springframework.beans.factory.FactoryBean; 25 import org.springframework.beans.factory.InitializingBean; 26 import org.springframework.jmx.MBeanServerNotFoundException; 27 28 45 public class WebSphereMBeanServerFactoryBean implements FactoryBean, InitializingBean { 46 47 private static final String ADMIN_SERVICE_FACTORY_CLASS = "com.ibm.websphere.management.AdminServiceFactory"; 48 49 private static final String GET_MBEAN_FACTORY_METHOD = "getMBeanFactory"; 50 51 private static final String GET_MBEAN_SERVER_METHOD = "getMBeanServer"; 52 53 54 private MBeanServer mbeanServer; 55 56 57 public void afterPropertiesSet() throws MBeanServerNotFoundException { 58 try { 59 62 Class adminServiceClass = getClass().getClassLoader().loadClass(ADMIN_SERVICE_FACTORY_CLASS); 63 Method getMBeanFactoryMethod = adminServiceClass.getMethod(GET_MBEAN_FACTORY_METHOD, new Class [0]); 64 Object mbeanFactory = getMBeanFactoryMethod.invoke(null, new Object [0]); 65 Method getMBeanServerMethod = mbeanFactory.getClass().getMethod(GET_MBEAN_SERVER_METHOD, new Class [0]); 66 this.mbeanServer = (MBeanServer ) getMBeanServerMethod.invoke(mbeanFactory, new Object [0]); 67 } 68 catch (ClassNotFoundException ex) { 69 throw new MBeanServerNotFoundException("Could not find WebSphere's AdminServiceFactory class", ex); 70 } 71 catch (InvocationTargetException ex) { 72 throw new MBeanServerNotFoundException( 73 "WebSphere's AdminServiceFactory.getMBeanFactory/getMBeanServer method failed", ex.getTargetException()); 74 } 75 catch (Exception ex) { 76 throw new MBeanServerNotFoundException( 77 "Could not access WebSphere's AdminServiceFactory.getMBeanFactory/getMBeanServer method", ex); 78 } 79 } 80 81 82 public Object getObject() { 83 return this.mbeanServer; 84 } 85 86 public Class getObjectType() { 87 return (this.mbeanServer != null ? this.mbeanServer.getClass() : MBeanServer .class); 88 } 89 90 public boolean isSingleton() { 91 return true; 92 } 93 94 } 95 | Popular Tags |