1 24 25 package com.rift.coad.lib.naming.cos; 27 28 import org.apache.log4j.Logger; 30 31 import java.util.Hashtable ; 33 import javax.naming.Context ; 34 import javax.naming.Name ; 35 import javax.naming.NameParser ; 36 import javax.naming.NamingEnumeration ; 37 import javax.naming.NamingException ; 38 39 45 public class URLContext implements Context { 46 47 protected Logger log = 49 Logger.getLogger(URLContext.class.getName()); 50 51 private Hashtable env = null; 53 private MasterContext masterContext = null; 54 private Name prefix = null; 55 56 61 public URLContext(Hashtable env) throws NamingException { 62 try { 63 this.env = env; 64 masterContext = CosNamingContextManager.getInstance(). 65 getMasterContext(); 66 prefix = new NamingParser().parse(""); 67 } catch (Exception ex) { 68 throw new NamingException ("Failed to create a new URL context"); 69 } 70 } 71 72 79 public URLContext(Name name, Hashtable env) throws NamingException { 80 try { 81 this.env = env; 82 masterContext = CosNamingContextManager.getInstance(). 83 getMasterContext(); 84 this.prefix = name; 85 } catch (Exception ex) { 86 throw new NamingException ("Failed to create a new URL context"); 87 } 88 } 89 90 91 98 public URLContext(Hashtable env,MasterContext masterContext,Name prefix) 99 throws NamingException { 100 this.env = env; 101 this.masterContext = masterContext; 102 this.prefix = prefix; 103 } 104 105 106 107 114 public Object addToEnvironment(String propName, Object propVal) throws 115 NamingException { 116 return masterContext.addToEnvironment(propName,propVal); 117 } 118 119 120 127 public void bind(Name name, Object obj) throws NamingException { 128 Name composedName = masterContext.composeName(name,prefix); 129 masterContext.bind(composedName,obj); 130 } 131 132 133 136 public void bind(String name, Object obj) throws NamingException { 137 Name composedName = masterContext.composeName( 138 new NamingParser().parse(name),prefix); 139 masterContext.bind(composedName,obj); 140 } 141 142 143 146 public void close() throws NamingException { 147 masterContext.close(); 148 } 149 150 151 159 public Name composeName(Name name, Name prefix) throws NamingException { 160 return masterContext.composeName(name,prefix); 161 } 162 163 164 171 public String composeName(String name, String prefix) throws 172 NamingException { 173 return masterContext.composeName(name,prefix); 174 } 175 176 177 184 public Context createSubcontext(Name name) throws NamingException { 185 Name composedName = masterContext.composeName(name,prefix); 186 masterContext.createSubcontext(composedName); 187 return new URLContext(env,masterContext,composedName); 188 } 189 190 191 198 public Context createSubcontext(String name) throws NamingException { 199 Name composedName = masterContext.composeName( 200 new NamingParser().parse(name),prefix); 201 masterContext.createSubcontext(composedName); 202 return new URLContext(env,masterContext,composedName); 203 } 204 205 206 212 public void destroySubcontext(Name name) throws NamingException { 213 Name composedName = masterContext.composeName(name,prefix); 214 masterContext.destroySubcontext(composedName); 215 } 216 217 218 223 public void destroySubcontext(String name) throws NamingException { 224 Name composedName = masterContext.composeName( 225 new NamingParser().parse(name),prefix); 226 masterContext.destroySubcontext(composedName); 227 } 228 229 230 236 public Hashtable getEnvironment() throws NamingException { 237 return masterContext.getEnvironment(); 238 } 239 240 241 244 public String getNameInNamespace() throws NamingException { 245 return masterContext.getNameInNamespace(); 246 } 247 248 249 256 public NameParser getNameParser(Name name) throws NamingException { 257 return masterContext.getNameParser(name); 258 } 259 260 261 264 public NameParser getNameParser(String name) throws NamingException { 265 return masterContext.getNameParser(name); 266 } 267 268 269 273 public NamingEnumeration list(Name name) throws NamingException { 274 Name composedName = masterContext.composeName(name,prefix); 275 return masterContext.list(composedName); 276 } 277 278 279 287 public NamingEnumeration list(String name) throws NamingException { 288 Name composedName = masterContext.composeName( 289 new NamingParser().parse(name),prefix); 290 return masterContext.list(composedName); 291 } 292 293 294 302 public NamingEnumeration listBindings(Name name) throws NamingException { 303 Name composedName = masterContext.composeName(name,prefix); 304 return masterContext.listBindings(composedName); 305 } 306 307 308 316 public NamingEnumeration listBindings(String name) throws NamingException { 317 Name composedName = masterContext.composeName( 318 new NamingParser().parse(name),prefix); 319 return masterContext.listBindings(composedName); 320 } 321 322 323 330 public Object lookup(Name name) throws NamingException { 331 Name composedName = masterContext.composeName(name,prefix); 332 Object result = masterContext.lookup(composedName); 333 if (result instanceof Context ) { 334 return new URLContext(env,masterContext,composedName); 335 } 336 return result; 337 } 338 339 340 347 public Object lookup(String name) throws NamingException { 348 Name composedName = masterContext.composeName( 349 new NamingParser().parse(name),prefix); 350 Object result = masterContext.lookup(composedName); 351 if (result instanceof Context ) { 352 return new URLContext(env,masterContext,composedName); 353 } 354 return result; 355 } 356 357 358 366 public Object lookupLink(Name name) throws NamingException { 367 Name composedName = masterContext.composeName(name,prefix); 368 Object result = masterContext.lookupLink(composedName); 369 if (result instanceof Context ) { 370 return new URLContext(env,masterContext,composedName); 371 } 372 return result; 373 } 374 375 376 384 public Object lookupLink(String name) throws NamingException { 385 Name composedName = masterContext.composeName( 386 new NamingParser().parse(name),prefix); 387 Object result = masterContext.lookupLink(composedName); 388 if (result instanceof Context ) { 389 return new URLContext(env,masterContext,composedName); 390 } 391 return result; 392 } 393 394 395 402 public void rebind(Name name, Object obj) throws NamingException { 403 Name composedName = masterContext.composeName(name,prefix); 404 masterContext.rebind(composedName,obj); 405 } 406 407 408 415 public void rebind(String name, Object obj) throws NamingException { 416 Name composedName = masterContext.composeName( 417 new NamingParser().parse(name),prefix); 418 masterContext.rebind(composedName,obj); 419 } 420 421 422 428 public Object removeFromEnvironment(String propName) throws NamingException { 429 return masterContext.removeFromEnvironment(propName); 430 } 431 432 433 441 public void rename(Name oldName, Name newName) throws NamingException { 442 Name oldComposedName = masterContext.composeName(oldName,prefix); 443 Name newComposedName = masterContext.composeName(newName,prefix); 444 masterContext.rename(oldComposedName,newComposedName); 445 } 446 447 448 456 public void rename(String oldName, String newName) throws NamingException { 457 Name oldComposedName = masterContext.composeName( 458 new NamingParser().parse(oldName),prefix); 459 Name newComposedName = masterContext.composeName( 460 new NamingParser().parse(newName),prefix); 461 masterContext.rename(oldComposedName,newComposedName); 462 } 463 464 465 471 public void unbind(Name name) throws NamingException { 472 Name composedName = masterContext.composeName(name,prefix); 473 masterContext.unbind(composedName); 474 } 475 476 477 483 public void unbind(String name) throws NamingException { 484 Name composedName = masterContext.composeName( 485 new NamingParser().parse(name),prefix); 486 masterContext.unbind(composedName); 487 } 488 489 490 } 491 | Popular Tags |