KickJava   Java API By Example, From Geeks To Geeks.

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


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.EntityManager;
12 import javax.persistence.Transient;
13 import javax.persistence.PersistenceContextType;
14 import org.jboss.ejb3.BeanContext;
15 import org.jboss.ejb3.Container;
16 import org.jboss.ejb3.EJBContainer;
17 import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
18
19 /**
20  * Comment
21  *
22  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
23  * @version $Revision: 1.3.2.3 $
24  *
25  **/

26 public class EntityManagerMethodInjector extends EntityManagerInjector
27 {
28    private Method JavaDoc setMethod;
29
30    public EntityManagerMethodInjector(Method JavaDoc setMethod, Container container, ManagedEntityManagerFactory factory, PersistenceContextType type)
31    {
32       super(container, factory, type);
33       this.setMethod = setMethod;
34    }
35
36    public void inject(BeanContext ctx)
37    {
38       try
39       {
40          boolean isTransient = ((EJBContainer)container).resolveAnnotation(setMethod, Transient.class) != null;
41          EntityManager entityManager = getEntityManager(ctx, isTransient);
42          Object JavaDoc[] args = {entityManager};
43          setMethod.invoke(ctx.getInstance(), args);
44       }
45       catch (IllegalAccessException JavaDoc e)
46       {
47          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
48
}
49       catch (IllegalArgumentException JavaDoc e)
50       {
51          throw new RuntimeException JavaDoc("Failed in setting EntityManager on setter method: " + setMethod.toString());
52       }
53       catch (InvocationTargetException JavaDoc e)
54       {
55          throw new RuntimeException JavaDoc(e.getCause()); //To change body of catch statement use Options | File Templates.
56
}
57    }
58 }
59
Popular Tags