1 17 18 19 package org.apache.naming.java; 20 21 import java.util.Hashtable ; 22 import javax.naming.Name ; 23 import javax.naming.Context ; 24 import javax.naming.NamingException ; 25 import javax.naming.spi.ObjectFactory ; 26 import javax.naming.spi.InitialContextFactory ; 27 import org.apache.naming.SelectorContext; 28 import org.apache.naming.NamingContext; 29 import org.apache.naming.ContextBindings; 30 31 49 50 public class javaURLContextFactory 51 implements ObjectFactory , InitialContextFactory { 52 53 54 56 57 59 60 public static final String MAIN = "initialContext"; 61 62 63 65 66 69 protected static Context initialContext = null; 70 71 72 74 75 77 78 81 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 82 Hashtable environment) 83 throws NamingException { 84 if ((ContextBindings.isThreadBound()) || 85 (ContextBindings.isClassLoaderBound())) { 86 return new SelectorContext(environment); 87 } else { 88 return null; 89 } 90 } 91 92 93 96 public Context getInitialContext(Hashtable environment) 97 throws NamingException { 98 if (ContextBindings.isThreadBound() || 99 (ContextBindings.isClassLoaderBound())) { 100 return new SelectorContext(environment, true); 102 } else { 103 if (initialContext == null) 105 initialContext = new NamingContext(environment, MAIN); 106 return initialContext; 107 } 108 } 109 110 111 } 112 113 | Popular Tags |