1 7 package org.jboss.ejb3.injection; 8 9 import org.jboss.ejb3.BeanContext; 10 import org.jboss.mx.util.MBeanProxyExt; 11 import org.jboss.system.ServiceControllerMBean; 12 13 import javax.management.ObjectName ; 14 import javax.management.MBeanServerFactory ; 15 import javax.management.MBeanServer ; 16 import java.lang.reflect.Method ; 17 import java.lang.reflect.InvocationTargetException ; 18 19 23 public class DependsMethodInjector implements Injector 24 { 25 Method method; 26 ObjectName on; 27 28 public DependsMethodInjector(Method method, ObjectName on) 29 { 30 this.method = method; 31 this.on = on; 32 } 33 34 public void inject(BeanContext ctx) 35 { 36 Class clazz = method.getParameterTypes()[0]; 37 Object value = null; 38 39 if (clazz == ObjectName .class) 40 { 41 value = on; 42 } 43 else 44 { 45 MBeanServer server = (MBeanServer )MBeanServerFactory.findMBeanServer(null).get(0); 46 value = MBeanProxyExt.create(clazz, on, server); 47 } 48 49 try 50 { 51 method.invoke(ctx.getInstance(), value); 52 } 53 catch (InvocationTargetException e) 54 { 55 throw new RuntimeException (e); 56 } 57 catch (IllegalAccessException e) 58 { 59 throw new RuntimeException (e); 60 } 61 } 62 } 63 | Popular Tags |