KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > injection > DependsMethodInjector


1 /*
2  * JBoss, the OpenSource EJB server
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 JavaDoc;
14 import javax.management.MBeanServerFactory JavaDoc;
15 import javax.management.MBeanServer JavaDoc;
16 import java.lang.reflect.Method JavaDoc;
17 import java.lang.reflect.InvocationTargetException JavaDoc;
18
19 /**
20  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
21  * @version $Revision: 1.1.4.2 $
22  */

23 public class DependsMethodInjector implements Injector
24 {
25    Method JavaDoc method;
26    ObjectName JavaDoc on;
27
28    public DependsMethodInjector(Method JavaDoc method, ObjectName JavaDoc on)
29    {
30       this.method = method;
31       this.on = on;
32    }
33
34    public void inject(BeanContext ctx)
35    {
36       Class JavaDoc clazz = method.getParameterTypes()[0];
37       Object JavaDoc value = null;
38
39       if (clazz == ObjectName JavaDoc.class)
40       {
41          value = on;
42       }
43       else
44       {
45          MBeanServer JavaDoc server = (MBeanServer JavaDoc)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 JavaDoc e)
54       {
55          throw new RuntimeException JavaDoc(e);
56       }
57       catch (IllegalAccessException JavaDoc e)
58       {
59          throw new RuntimeException JavaDoc(e);
60       }
61    }
62 }
63
Popular Tags