1 28 29 package com.caucho.config.j2ee; 30 31 import com.caucho.config.BuilderProgram; 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.NodeBuilder; 34 import com.caucho.util.L10N; 35 36 import javax.naming.InitialContext ; 37 import java.lang.reflect.InvocationTargetException ; 38 import java.lang.reflect.Method ; 39 40 public class JndiInjectProgram extends BuilderProgram { 41 private static final L10N L = new L10N(JndiInjectProgram.class); 42 43 private String _jndiName; 44 private Method _method; 45 46 JndiInjectProgram(String jndiName, Method method) 47 { 48 _jndiName = jndiName; 49 _method = method; 50 51 method.setAccessible(true); 52 } 53 54 @Override 55 public void configureImpl(NodeBuilder builder, Object bean) 56 throws ConfigException 57 { 58 try { 59 Object value = new InitialContext ().lookup(_jndiName); 60 61 63 _method.invoke(bean, value); 64 } catch (RuntimeException e) { 65 throw e; 66 } catch (InvocationTargetException e) { 67 throw new ConfigException(e.getCause()); 68 } catch (Exception e) { 69 throw new ConfigException(e); 70 } 71 } 72 73 @Override 74 public Object configureImpl(NodeBuilder builder, Class type) 75 throws ConfigException 76 { 77 throw new UnsupportedOperationException (getClass().getName()); 78 } 79 80 @Override 81 public String toString() 82 { 83 return getClass().getSimpleName() + "[" + _jndiName + "," + _method + "]"; 84 } 85 } 86 | Popular Tags |