1 55 package org.lateralnz.panther.naming; 56 57 import java.util.Hashtable ; 58 59 import javax.naming.Context ; 60 import javax.naming.Name ; 61 import javax.naming.NamingException ; 62 import javax.naming.RefAddr ; 63 64 import javax.naming.Reference ; 65 import javax.naming.spi.InitialContextFactory ; 66 import javax.naming.spi.ObjectFactory ; 67 68 import org.apache.log4j.Logger; 69 70 public class LocalContextFactory implements InitialContextFactory , ObjectFactory { 71 private static final Logger log = Logger.getLogger(LocalContextFactory.class.getName()); 72 private static final String NAME = "name"; 73 74 public LocalContextFactory() { 75 } 76 77 public Context getInitialContext(Hashtable ht) throws NamingException { 78 if (ht != null && ht.containsKey(WLocalContext.NAMING_FACTORY_INITIAL)) { 79 return new WLocalContext(ht); 80 } 81 else { 82 return new LocalContext(ht); 83 } 84 } 85 86 public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable environment) throws Exception { 87 Reference ref = (Reference )obj; 88 if (ref.getClassName().equals(LocalContext.class.getName())) { 89 return LocalContext.getContext(getProperty(ref, NAME)); 90 } 91 else { 92 return null; 93 } 94 } 95 96 protected String getProperty(Reference ref, String s) { 97 RefAddr addr = ref.get(s); 98 if (addr == null) { 99 return null; 100 } 101 return (String )addr.getContent(); 102 } 103 } 104
| Popular Tags
|