1 29 30 package com.caucho.naming.java; 31 32 import com.caucho.loader.EnvironmentLocal; 33 import com.caucho.log.Log; 34 import com.caucho.naming.AbstractModel; 35 import com.caucho.naming.ContextImpl; 36 import com.caucho.naming.MemoryModel; 37 import com.caucho.util.L10N; 38 39 import javax.naming.Context ; 40 import javax.naming.Name ; 41 import javax.naming.NamingException ; 42 import javax.naming.spi.ObjectFactory ; 43 import java.util.Hashtable ; 44 import java.util.logging.Level ; 45 import java.util.logging.Logger ; 46 47 50 public class javaURLContextFactory implements ObjectFactory { 51 private static L10N L = new L10N(javaURLContextFactory.class); 52 private static Logger dbg = Log.open(javaURLContextFactory.class); 53 54 private static EnvironmentLocal<AbstractModel> _javaModel = 55 new EnvironmentLocal<AbstractModel>("caucho.naming.model.java"); 56 57 60 public static AbstractModel getContextModel() 61 { 62 return _javaModel.get(); 63 } 64 65 68 public static void setContextModel(AbstractModel model) 69 { 70 _javaModel.set(model); 71 } 72 73 public Object getObjectInstance(Object obj, 74 Name name, 75 Context parentContext, 76 Hashtable <?,?> env) 77 throws NamingException 78 { 79 AbstractModel model = _javaModel.getLevel(); 80 81 if (model == null) { 82 if (dbg.isLoggable(Level.FINER)) { 83 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 84 85 dbg.finer(L.l("creating JNDI java: model for {0} parent:{1}", 86 loader, 87 (loader != null ? loader.getParent() : null))); 88 } 89 90 model = _javaModel.get(); 91 92 if (model != null) 93 model = model.copy(); 94 else 95 model = new MemoryModel(); 96 97 if (model.lookup("java:comp") == null) 98 model.createSubcontext("java:comp"); 99 100 if (model.lookup("java:") == null) 101 model.createSubcontext("java:"); 102 103 106 _javaModel.set(model); 107 } 108 109 Context context = new ContextImpl(model, env); 110 111 if (obj != null) 112 return context.lookup((String ) obj); 113 else 114 return context; 115 } 116 } 117 | Popular Tags |