KickJava   Java API By Example, From Geeks To Geeks.

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


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

21 public class EntityManagerFactoryFieldInjector implements Injector
22 {
23    private static final Logger log = Logger.getLogger(EntityManagerFactoryFieldInjector.class);
24    private Field JavaDoc field;
25    private Container container;
26    private EntityManagerFactory factory;
27
28    public EntityManagerFactoryFieldInjector(Field JavaDoc field, Container container, EntityManagerFactory factory)
29    {
30       this.field = field;
31       this.field.setAccessible(true);
32       this.container = container;
33       this.factory = factory;
34    }
35
36    public void inject(BeanContext ctx)
37    {
38       try
39       {
40          field.set(ctx.getInstance(), factory);
41       }
42       catch (IllegalAccessException JavaDoc e)
43       {
44          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
45
}
46       catch (IllegalArgumentException JavaDoc e)
47       {
48          throw new RuntimeException JavaDoc("Failed in setting EntityManager on setter field: " + field.toString());
49       }
50    }
51
52 }
53
Popular Tags