1 7 package org.jboss.ejb3.injection; 8 9 import java.lang.reflect.InvocationTargetException ; 10 import java.lang.reflect.Method ; 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 26 public class EntityManagerMethodInjector extends EntityManagerInjector 27 { 28 private Method setMethod; 29 30 public EntityManagerMethodInjector(Method 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 [] args = {entityManager}; 43 setMethod.invoke(ctx.getInstance(), args); 44 } 45 catch (IllegalAccessException e) 46 { 47 throw new RuntimeException (e); } 49 catch (IllegalArgumentException e) 50 { 51 throw new RuntimeException ("Failed in setting EntityManager on setter method: " + setMethod.toString()); 52 } 53 catch (InvocationTargetException e) 54 { 55 throw new RuntimeException (e.getCause()); } 57 } 58 } 59 | Popular Tags |