1 22 package org.jboss.injection; 23 24 import java.lang.reflect.Field ; 25 import org.jboss.ejb3.BeanContext; 26 27 33 public class EJBContextFieldInjector implements Injector, PojoInjector 34 { 35 private Field field; 36 37 public EJBContextFieldInjector(Field field) 38 { 39 this.field = field; 40 field.setAccessible(true); 41 } 42 43 public void inject(BeanContext ctx) 44 { 45 inject(ctx, ctx.getInstance()); 46 } 47 48 public void inject(BeanContext ctx, Object instance) 49 { 50 try 51 { 52 field.set(instance, ctx.getEJBContext()); 53 } 54 catch (IllegalAccessException e) 55 { 56 throw new RuntimeException (e); 57 } 58 } 59 60 public void inject(Object instance) 61 { 62 throw new RuntimeException ("Illegal operation"); 63 } 64 65 public Class getInjectionClass() 66 { 67 return field.getType(); 68 } 69 } 70 | Popular Tags |