1 21 22 package com.rift.coad.util.connection; 24 25 import java.util.Map ; 27 import java.util.concurrent.ConcurrentHashMap ; 28 import javax.naming.Context ; 29 30 import org.apache.log4j.Logger; 32 33 34 39 public class ProxyConnection implements Connection { 40 41 protected static Logger log = 43 Logger.getLogger(ProxyConnection.class.getName()); 44 45 private Context context = null; 47 private String jndiURL = null; 48 private Object ref = null; 49 50 56 public ProxyConnection(Context context, String jndiURL) { 57 this.context = context; 58 this.jndiURL = jndiURL; 59 } 60 61 62 70 public synchronized Object getConnection(Class type) throws 71 ConnectionException,java.lang.ClassCastException { 72 try { 73 if (ref == null) { 74 ref = context.lookup(jndiURL); 75 } 76 return ref; 77 } catch (Exception ex) { 78 log.error("Failed to retrieve a connection : " + ex.getMessage(), 79 ex); 80 throw new ConnectionException("Failed to retrieve a connection : " + 81 ex.getMessage(),ex); 82 } 83 } 84 85 86 93 public static boolean isLocalURL(String jndiURL) { 94 if (jndiURL.trim().indexOf("java:comp") == 0) { 95 return true; 96 } 97 return false; 98 } 99 } 100 | Popular Tags |