1 19 package gcc.naming; 20 21 import gcc.properties.*; 22 import gcc.adapter.Adapter; 23 24 import java.util.*; 25 import javax.naming.*; 26 27 public class NamingContext 28 { 29 public static final NamingContext getInstance(Class baseClass) 30 { 31 NamingContext context; 32 synchronized (_contextMap) 33 { 34 context = (NamingContext)_contextMap.get(baseClass); 35 if (context == null) 36 { 37 context = new NamingContext(); 38 _contextMap.put(baseClass, context); 39 context.init(baseClass); 40 } 41 } 42 return context; 43 } 44 45 private static ThreadLocal _current = new ThreadLocal(); 46 private static HashMap _contextMap = new HashMap(); 47 private static boolean _quiet = false; private static boolean _verbose = true; private String _logContext; 50 private HashMap _map = new HashMap(); 51 52 public static final NamingContext getCurrent() 53 { 54 return (NamingContext)_current.get(); 55 } 56 57 public static final NamingContext push(NamingContext that) 58 { 59 NamingContext restore = getCurrent(); 60 _current.set(that); 61 return restore; 62 } 63 64 public static void pop(NamingContext restore) 65 { 66 _current.set(restore); 67 } 68 69 public HashMap getMap() 70 { 71 return _map; 72 } 73 74 public Object lookup(String name, String prefix) throws NamingException 75 { 76 if (prefix != null) 77 { 78 name += prefix + "/" + name; 79 } 80 81 87 Object value = _map.get(name); 88 89 if (value == null) 90 { 91 value = dynamicLookup(name); 92 if (value != null) 93 { 94 _map.put(name, value); } 96 } 97 98 if (value == null) 99 { 100 NameNotFoundException notFound = new NameNotFoundException(name.length() == 0 ? formatEmptyName() : name); 101 if (! _quiet) 102 { 103 NameServiceLog.getInstance().warnNameNotFound(_logContext, notFound); 104 } 105 throw notFound; 106 } 107 else 108 { 109 return value; 110 } 111 } 112 113 public Object lookupReturnNullIfNotFound(String name, String prefix) 114 { 115 if (prefix != null) 116 { 117 name += prefix + "/" + name; 118 } 119 return _map.get(name); 120 } 121 122 protected void init(Class baseClass) 123 { 124 } 127 128 protected void bindAdapter(Adapter adp) 129 { 130 _map.put( adp.getBindName(), adp ); 131 } 132 133 protected boolean adapterExists(String name) 134 { 135 System.out.println( "TODO: NamingComponent.componentExists(): name = " + name ); 136 137 140 return false; 141 } 142 143 protected Object dynamicLookup(String name) 144 { 145 return null; 146 } 147 148 154 155 161 162 167 168 protected String formatEmptyName() 169 { 170 return "formatEmptyName:"; 171 } 172 173 } 174 | Popular Tags |