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.InvocationTargetException ; 19 import java.lang.reflect.Method ; 20 21 27 public class UserTransactionMethodInjector implements Injector 28 { 29 private Method setMethod; 30 31 public UserTransactionMethodInjector(Method setMethod, Container container) 32 { 33 TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) container)); 34 if (type != TransactionManagementType.BEAN) throw new IllegalStateException ("Container " + container.getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean"); 35 this.setMethod = setMethod; 36 } 37 38 public void inject(BeanContext ctx) 39 { 40 UserTransaction ut = new UserTransactionImpl(); 41 Object [] args = {ut}; 42 try 43 { 44 setMethod.invoke(ctx.getInstance(), args); 45 } 46 catch (IllegalAccessException e) 47 { 48 throw new RuntimeException (e); } 50 catch (IllegalArgumentException e) 51 { 52 throw new RuntimeException ("Failed in setting EntityManager on setter method: " + setMethod.toString()); 53 } 54 catch (InvocationTargetException e) 55 { 56 throw new RuntimeException (e.getCause()); } 58 } 59 } 60 | Popular Tags |