1 29 30 package com.caucho.config.j2ee; 31 32 import com.caucho.config.BuilderProgram; 33 import com.caucho.config.ConfigException; 34 import com.caucho.config.NodeBuilder; 35 import com.caucho.soa.client.WebServiceClient; 36 import com.caucho.util.L10N; 37 38 import javax.naming.InitialContext ; 39 import javax.naming.NamingException ; 40 import java.util.logging.Level ; 41 import java.util.logging.Logger ; 42 43 44 public class ServiceProxyInjectProgram extends BuilderProgram { 45 private static final Logger log 46 = Logger.getLogger(ServiceProxyInjectProgram.class.getName()); 47 private static final L10N L 48 = new L10N(ServiceProxyInjectProgram.class); 49 50 private String _jndiName; 51 private Class _type; 52 private AccessibleInject _field; 53 54 ServiceProxyInjectProgram(String jndiName, 55 Class type, 56 AccessibleInject field) 57 { 58 _jndiName = jndiName; 59 _type = type; 60 _field = field; 61 } 62 63 public void configureImpl(NodeBuilder builder, Object bean) 64 throws ConfigException 65 { 66 try { 67 Object value = new InitialContext ().lookupLink(_jndiName); 68 69 if (value == null) 70 return; 71 72 if (value instanceof WebServiceClient) { 73 WebServiceClient client = (WebServiceClient) value; 74 75 value = client.createProxy(_type); 76 } 77 78 if (! _field.getType().isAssignableFrom(value.getClass())) { 79 throw new ConfigException(L.l("Resource at '{0}' of type {1} is not assignable to field '{2}' of type {3}.", 80 _jndiName, 81 value.getClass().getName(), 82 _field.getName(), 83 _field.getType().getName())); 84 } 85 86 _field.inject(bean, value); 87 } catch (RuntimeException e) { 88 throw e; 89 } catch (NamingException e) { 90 log.finer(String.valueOf(e)); 91 log.log(Level.FINEST, e.toString(), e); 92 } catch (Exception e) { 93 throw new ConfigException(e); 94 } 95 } 96 97 public Object configure(NodeBuilder builder, Class type) 98 throws ConfigException 99 { 100 throw new UnsupportedOperationException (getClass().getName()); 101 } 102 } 103 | Popular Tags |