1 7 8 package javax.naming.spi; 9 10 import java.util.Hashtable ; 11 12 import javax.naming.Context ; 13 import javax.naming.Name ; 14 import javax.naming.Reference ; 15 import javax.naming.Referenceable ; 16 import javax.naming.NamingException ; 17 import javax.naming.CannotProceedException ; 18 import javax.naming.directory.DirContext ; 19 import javax.naming.directory.Attributes ; 20 21 import com.sun.naming.internal.ResourceManager; 22 import com.sun.naming.internal.FactoryEnumeration; 23 24 25 50 51 public class DirectoryManager extends NamingManager { 52 53 56 DirectoryManager() {} 57 58 70 public static DirContext getContinuationDirContext( 71 CannotProceedException cpe) throws NamingException { 72 73 Hashtable env = cpe.getEnvironment(); 74 if (env == null) { 75 env = new Hashtable (7); 76 } else { 77 env = (Hashtable ) env.clone(); 79 } 80 env.put(CPE, cpe); 81 82 return (new ContinuationDirContext (cpe, env)); 83 } 84 85 136 public static Object 137 getObjectInstance(Object refInfo, Name name, Context nameCtx, 138 Hashtable <?,?> environment, Attributes attrs) 139 throws Exception { 140 141 ObjectFactory factory; 142 143 ObjectFactoryBuilder builder = getObjectFactoryBuilder(); 144 if (builder != null) { 145 factory = builder.createObjectFactory(refInfo, environment); 147 if (factory instanceof DirObjectFactory ) { 148 return ((DirObjectFactory )factory).getObjectInstance( 149 refInfo, name, nameCtx, environment, attrs); 150 } else { 151 return factory.getObjectInstance(refInfo, name, nameCtx, 152 environment); 153 } 154 } 155 156 Reference ref = null; 158 if (refInfo instanceof Reference ) { 159 ref = (Reference ) refInfo; 160 } else if (refInfo instanceof Referenceable ) { 161 ref = ((Referenceable )(refInfo)).getReference(); 162 } 163 164 Object answer; 165 166 if (ref != null) { 167 String f = ref.getFactoryClassName(); 168 if (f != null) { 169 171 factory = getObjectFactoryFromReference(ref, f); 172 if (factory instanceof DirObjectFactory ) { 173 return ((DirObjectFactory )factory).getObjectInstance( 174 ref, name, nameCtx, environment, attrs); 175 } else if (factory != null) { 176 return factory.getObjectInstance(ref, name, nameCtx, 177 environment); 178 } 179 return refInfo; 183 184 } else { 185 189 answer = processURLAddrs(ref, name, nameCtx, environment); 190 if (answer != null) { 191 return answer; 192 } 193 } 194 } 195 196 answer = createObjectFromFactories(refInfo, name, nameCtx, 198 environment, attrs); 199 return (answer != null) ? answer : refInfo; 200 } 201 202 private static Object createObjectFromFactories(Object obj, Name name, 203 Context nameCtx, Hashtable environment, Attributes attrs) 204 throws Exception { 205 206 FactoryEnumeration factories = ResourceManager.getFactories( 207 Context.OBJECT_FACTORIES, environment, nameCtx); 208 209 if (factories == null) 210 return null; 211 212 ObjectFactory factory; 213 Object answer = null; 214 while (answer == null && factories.hasMore()) { 216 factory = (ObjectFactory )factories.next(); 217 if (factory instanceof DirObjectFactory ) { 218 answer = ((DirObjectFactory )factory). 219 getObjectInstance(obj, name, nameCtx, environment, attrs); 220 } else { 221 answer = 222 factory.getObjectInstance(obj, name, nameCtx, environment); 223 } 224 } 225 return answer; 226 } 227 228 285 public static DirStateFactory.Result 286 getStateToBind(Object obj, Name name, Context nameCtx, 287 Hashtable <?,?> environment, Attributes attrs) 288 throws NamingException { 289 290 FactoryEnumeration factories = ResourceManager.getFactories( 292 Context.STATE_FACTORIES, environment, nameCtx); 293 294 if (factories == null) { 295 return new DirStateFactory.Result (obj, attrs); 297 } 298 299 StateFactory factory; 301 Object objanswer; 302 DirStateFactory.Result answer = null; 303 while (answer == null && factories.hasMore()) { 304 factory = (StateFactory )factories.next(); 305 if (factory instanceof DirStateFactory ) { 306 answer = ((DirStateFactory )factory). 307 getStateToBind(obj, name, nameCtx, environment, attrs); 308 } else { 309 objanswer = 310 factory.getStateToBind(obj, name, nameCtx, environment); 311 if (objanswer != null) { 312 answer = new DirStateFactory.Result (objanswer, attrs); 313 } 314 } 315 } 316 317 return (answer != null) ? answer : 318 new DirStateFactory.Result (obj, attrs); } 320 } 321 | Popular Tags |