1 22 package org.jboss.util.naming; 23 24 import java.util.Hashtable ; 25 import javax.naming.Context ; 26 import javax.naming.Name ; 27 import javax.naming.Reference ; 28 import javax.naming.RefAddr ; 29 import javax.naming.LinkRef ; 30 import javax.naming.spi.ObjectFactory ; 31 32 import org.jboss.logging.Logger; 33 34 40 public class ENCThreadLocalKey 41 implements ObjectFactory 42 { 43 private static final Logger log = Logger.getLogger(ENCThreadLocalKey.class); 44 45 48 private final static ThreadLocal key = new ThreadLocal (); 49 50 public static void setKey(String tlkey) 51 { 52 key.set(tlkey); 53 } 54 55 public static String getKey() 56 { 57 return (String ) key.get(); 58 } 59 60 public Object getObjectInstance(Object obj, 61 Name name, 62 Context nameCtx, 63 Hashtable environment) 64 throws Exception 65 { 66 Reference ref = (Reference ) obj; 67 String reftype = (String ) key.get(); 68 boolean trace = log.isTraceEnabled(); 69 70 if (reftype == null) 71 { 72 if (trace) 73 log.trace("using default in ENC"); 74 reftype = "default"; 75 } 76 77 RefAddr addr = ref.get(reftype); 78 if (addr == null) 79 { 80 if (trace) 81 log.trace("using default in ENC"); 82 addr = ref.get("default"); } 84 if (addr != null) 85 { 86 String target = (String ) addr.getContent(); 87 if (trace) 88 log.trace("found Reference " + reftype + " with content " + target); 89 return new LinkRef (target); 90 } 91 return null; 92 } 93 94 } 95 | Popular Tags |