1 7 package org.jboss.ejb3.injection; 8 9 import org.jboss.aop.Advisor; 10 import org.jboss.ejb3.BeanContext; 11 import org.jboss.ejb3.Container; 12 import org.jboss.ejb3.tx.TxUtil; 13 import org.jboss.ejb3.tx.UserTransactionImpl; 14 15 import javax.ejb.TransactionManagementType ; 16 import javax.transaction.UserTransaction ; 17 18 import java.lang.reflect.Field ; 19 20 26 public class UserTransactionFieldInjector implements Injector 27 { 28 private Field field; 29 30 public UserTransactionFieldInjector(Field field, Container container) 31 { 32 TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) container)); 33 if (type != TransactionManagementType.BEAN) throw new IllegalStateException ("Container " + container.getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean"); 34 this.field = field; 35 this.field.setAccessible(true); 36 } 37 38 public void inject(BeanContext ctx) 39 { 40 UserTransaction ut = new UserTransactionImpl(); 41 try 42 { 43 field.set(ctx.getInstance(), ut); 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 field: " + field.toString()); 52 } 53 } 54 } 55 | Popular Tags |