KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JBoss, the OpenSource J2EE webOS
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
11 import java.lang.reflect.InvocationTargetException JavaDoc;
12 import java.lang.reflect.Method JavaDoc;
13
14 /**
15  * Comment
16  *
17  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
18  * @version $Revision: 1.1.2.3 $
19  */

20 public class EJBContextMethodInjector implements Injector
21 {
22    private Method JavaDoc setMethod;
23
24    public EJBContextMethodInjector(Method JavaDoc setMethod)
25    {
26       this.setMethod = setMethod;
27    }
28
29    public void inject(BeanContext ctx)
30    {
31
32       Object JavaDoc[] args = {ctx};
33       try
34       {
35          setMethod.invoke(ctx.getInstance(), args);
36       }
37       catch (IllegalAccessException JavaDoc e)
38       {
39          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
40
}
41       catch (IllegalArgumentException JavaDoc e)
42       {
43          throw new RuntimeException JavaDoc("Failed in setting EntityManager on setter method: " + setMethod.toString());
44       }
45       catch (InvocationTargetException JavaDoc e)
46       {
47          throw new RuntimeException JavaDoc(e.getCause()); //To change body of catch statement use Options | File Templates.
48
}
49    }
50 }
51
Popular Tags