1 7 package org.jboss.ejb3.injection; 8 9 import java.lang.reflect.Field ; 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 21 public class EntityManagerFactoryFieldInjector implements Injector 22 { 23 private static final Logger log = Logger.getLogger(EntityManagerFactoryFieldInjector.class); 24 private Field field; 25 private Container container; 26 private EntityManagerFactory factory; 27 28 public EntityManagerFactoryFieldInjector(Field 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 e) 43 { 44 throw new RuntimeException (e); } 46 catch (IllegalArgumentException e) 47 { 48 throw new RuntimeException ("Failed in setting EntityManager on setter field: " + field.toString()); 49 } 50 } 51 52 } 53 | Popular Tags |