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.Method ; 36 import java.util.logging.Logger ; 37 38 39 public class PropertyInject extends AccessibleInject { 40 private static final Logger log 41 = Logger.getLogger(PropertyInject.class.getName()); 42 private static final L10N L = new L10N(PropertyInject.class); 43 44 private Method _method; 45 private Class _type; 46 47 PropertyInject(Method method) 48 { 49 _method = method; 50 51 Class []paramTypes = method.getParameterTypes(); 52 _type = paramTypes[0]; 53 54 _method.setAccessible(true); 55 } 56 57 String getName() 58 { 59 return _method.getName(); 60 } 61 62 Class getType() 63 { 64 return _type; 65 } 66 67 void inject(Object bean, Object value) 68 throws ConfigException 69 { 70 try { 71 if (! _type.isAssignableFrom(value.getClass())) { 72 throw new ConfigException(L.l("Resource type {0} is not assignable to method '{1}' of type {2}.", 73 value.getClass().getName(), 74 _method.getName(), 75 _type.getName())); 76 } 77 78 _method.invoke(bean, value); 79 } catch (RuntimeException e) { 80 throw e; 81 } catch (Exception e) { 82 throw new ConfigException(e); 83 } 84 } 85 } 86 | Popular Tags |