1 29 30 package com.caucho.config.j2ee; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.util.L10N; 34 35 import java.lang.reflect.Field ; 36 import java.util.logging.Logger ; 37 38 39 public class FieldInject extends AccessibleInject { 40 private static final Logger log 41 = Logger.getLogger(FieldInject.class.getName()); 42 private static final L10N L = new L10N(FieldInject.class); 43 44 private Field _field; 45 46 FieldInject(Field field) 47 { 48 _field = field; 49 _field.setAccessible(true); 50 } 51 52 String getName() 53 { 54 return _field.getName(); 55 } 56 57 Class getType() 58 { 59 return _field.getType(); 60 } 61 62 void inject(Object bean, Object value) 63 throws ConfigException 64 { 65 try { 66 if (! _field.getType().isAssignableFrom(value.getClass())) { 67 throw new ConfigException(L.l("Resource type {0} is not assignable to field '{1}' of type {2}.", 68 value.getClass().getName(), 69 _field.getName(), 70 _field.getType().getName())); 71 } 72 73 _field.set(bean, value); 74 } catch (RuntimeException e) { 75 throw e; 76 } catch (Exception e) { 77 throw new ConfigException(e); 78 } 79 } 80 } 81 | Popular Tags |