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 import org.jboss.ejb3.Container; 28 29 35 public class TimerServiceMethodInjector implements Injector 36 { 37 private Method setMethod; 38 private Container container; 39 40 public TimerServiceMethodInjector(Method setMethod, Container container) 41 { 42 this.setMethod = setMethod; 43 setMethod.setAccessible(true); 44 this.container = container; 45 } 46 47 public void inject(Object instance) 48 { 49 throw new RuntimeException ("SHOULD NOT BE INVOKED"); 50 } 51 52 public void inject(BeanContext ctx) 53 { 54 55 Object [] args = {container.getTimerService()}; 56 try 57 { 58 setMethod.invoke(ctx.getInstance(), args); 59 } 60 catch (IllegalAccessException e) 61 { 62 throw new RuntimeException (e); } 64 catch (IllegalArgumentException e) 65 { 66 throw new RuntimeException ("Failed in setting EntityManager on setter method: " + setMethod.toString()); 67 } 68 catch (InvocationTargetException e) 69 { 70 throw new RuntimeException (e.getCause()); } 72 } 73 74 public Class getInjectionClass() 75 { 76 return setMethod.getParameterTypes()[0]; 77 } 78 } 79 | Popular Tags |