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 import java.lang.reflect.Field ; 19 20 24 public class DependsFieldInjector implements Injector 25 { 26 Field field; 27 ObjectName on; 28 29 public DependsFieldInjector(Field field, ObjectName on) 30 { 31 this.field = field; 32 this.on = on; 33 } 34 35 public void inject(BeanContext ctx) 36 { 37 Class clazz = field.getType(); 38 Object value = null; 39 40 if (clazz == ObjectName .class) 41 { 42 value = on; 43 } 44 else 45 { 46 MBeanServer server = (MBeanServer )MBeanServerFactory.findMBeanServer(null).get(0); 47 value = MBeanProxyExt.create(clazz, on, server); 48 } 49 50 try 51 { 52 field.set(ctx.getInstance(), value); 53 } 54 catch (IllegalAccessException e) 55 { 56 throw new RuntimeException (e); 57 } 58 } 59 } 60 | Popular Tags |