KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
10 import java.lang.reflect.Method JavaDoc;
11 import javax.persistence.EntityManagerFactory;
12 import org.jboss.ejb3.BeanContext;
13 import org.jboss.ejb3.Container;
14 import org.jboss.logging.Logger;
15
16 /**
17  * Comment
18  *
19  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
20  * @version $Revision: 1.2.2.2 $
21  *
22  **/

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