1 7 package org.jboss.ejb3.injection; 8 9 import java.lang.reflect.InvocationTargetException ; 10 import java.lang.reflect.Method ; 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 23 public class EntityManagerFactoryMethodInjector implements Injector 24 { 25 private static final Logger log = Logger.getLogger(EntityManagerFactoryMethodInjector.class); 26 private Method setMethod; 27 private Container container; 28 private EntityManagerFactory factory; 29 30 public EntityManagerFactoryMethodInjector(Method 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 [] args = {factory}; 42 setMethod.invoke(ctx.getInstance(), args); 43 } 44 catch (IllegalAccessException e) 45 { 46 throw new RuntimeException (e); } 48 catch (IllegalArgumentException e) 49 { 50 throw new RuntimeException ("Failed in setting EntityManager on setter method: " + setMethod.toString()); 51 } 52 catch (InvocationTargetException e) 53 { 54 throw new RuntimeException (e.getCause()); } 56 } 57 } 58 | Popular Tags |