1 22 package org.jboss.injection; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import org.jboss.ejb3.BeanContext; 27 28 34 public class EJBContextMethodInjector implements Injector, PojoInjector 35 { 36 private Method setMethod; 37 38 public EJBContextMethodInjector(Method setMethod) 39 { 40 this.setMethod = setMethod; 41 setMethod.setAccessible(true); 42 } 43 44 public void inject(BeanContext ctx) 45 { 46 inject(ctx, ctx.getInstance()); 47 } 48 49 public void inject(BeanContext ctx, Object instance) 50 { 51 52 Object [] args = {ctx.getEJBContext()}; 53 try 54 { 55 setMethod.invoke(instance, args); 56 } 57 catch (IllegalAccessException e) 58 { 59 throw new RuntimeException (e); } 61 catch (IllegalArgumentException e) 62 { 63 throw new RuntimeException ("Failed in setting EntityManager on setter method: " + setMethod.toString()); 64 } 65 catch (InvocationTargetException e) 66 { 67 throw new RuntimeException (e.getCause()); } 69 } 70 71 public void inject(Object instance) 72 { 73 throw new RuntimeException ("Illegal operation"); 74 } 75 76 77 public Class getInjectionClass() 78 { 79 return setMethod.getParameterTypes()[0]; 80 } 81 } 82 | Popular Tags |