1 16 17 package org.apache.naming.core; 18 19 import java.util.Hashtable ; 20 21 import javax.naming.CompositeName ; 22 import javax.naming.Context ; 23 import javax.naming.Name ; 24 import javax.naming.NameParser ; 25 import javax.naming.NamingEnumeration ; 26 import javax.naming.NamingException ; 27 import javax.naming.NotContextException ; 28 import javax.naming.OperationNotSupportedException ; 29 import javax.naming.directory.SearchControls ; 30 31 34 50 public class BaseContext extends BaseNaming implements Context { 51 52 public BaseContext() { 53 super(); 54 } 55 56 public BaseContext(Hashtable env) { 57 super(env); 58 } 59 60 61 63 73 public Object lookup(Name name) 74 throws NamingException { 75 return lookup(name, true); 76 } 77 78 85 public Object lookup(String name) 86 throws NamingException { 87 return lookup(string2Name(name), true); 88 } 89 90 91 101 public void bind(Name name, Object obj) 102 throws NamingException { 103 bind(name, obj, null, false); 104 } 105 106 107 115 public void bind(String name, Object obj) 116 throws NamingException { 117 bind(string2Name(name), obj, null, false); 118 } 119 120 121 134 public void rebind(Name name, Object obj) 135 throws NamingException { 136 bind(name, obj, null, true); 137 } 138 139 140 147 public void rebind(String name, Object obj) 148 throws NamingException { 149 bind(string2Name(name), obj, null, true); 150 } 151 152 153 167 public void unbind(Name name) 168 throws NamingException { 169 unbind(name, false); 170 } 171 172 public void unbind(String name) 173 throws NamingException { 174 unbind(string2Name(name), false); 175 } 176 177 178 189 public void rename(String oldName, String newName) 190 throws NamingException { 191 rename(string2Name(oldName), string2Name(newName)); 192 } 193 194 195 208 public NamingEnumeration list(String name) 209 throws NamingException { 210 return list(string2Name(name)); 211 } 212 213 public NamingEnumeration list(Name name) 214 throws NamingException { 215 return new NamingContextEnumeration(getChildren(), this, false); 216 } 217 218 219 232 public NamingEnumeration listBindings(Name name) 233 throws NamingException { 234 return new NamingContextEnumeration(getChildren(), this, true); 235 } 236 237 public NamingEnumeration listBindings(String name) 238 throws NamingException { 239 return listBindings(string2Name(name)); 240 } 241 242 243 268 public void destroySubcontext(Name name) 269 throws NamingException { 270 unbind(name, true); 271 } 272 273 274 283 public void destroySubcontext(String name) 284 throws NamingException { 285 unbind(string2Name(name), true); 286 } 287 288 289 300 public Context createSubcontext(Name name) 301 throws NamingException { 302 return createSubcontext(name, null); 303 } 304 305 public Context createSubcontext(String name) 306 throws NamingException { 307 return createSubcontext(string2Name(name), null); 308 } 309 310 public void rename(Name oldName, Name newName) 311 throws NamingException 312 { 313 Object value = lookup(oldName, false); 315 bind(newName, value, null, false); 316 unbind(oldName, true); 317 318 } 319 320 330 public Object lookupLink(Name name) 331 throws NamingException { 332 return lookup(name, false); 333 } 334 335 336 345 public Object lookupLink(String name) 346 throws NamingException { 347 return lookupLink(string2Name(name)); 348 } 349 350 351 365 public NameParser getNameParser(Name name) 366 throws NamingException { 367 368 while ((!name.isEmpty()) && (name.get(0).length() == 0)) 369 name = name.getSuffix(1); 370 if (name.isEmpty()) 371 return nameParser; 372 373 if (name.size() > 1) { 374 Object obj = lookup(name.get(0)); 375 if (obj instanceof Context ) { 376 return ((Context ) obj).getNameParser(name.getSuffix(1)); 377 } else { 378 throw new NotContextException (name.toString()); 379 } 380 } 381 382 return nameParser; 383 384 } 385 386 387 395 public NameParser getNameParser(String name) 396 throws NamingException { 397 return getNameParser(new CompositeName (name)); 398 } 399 400 415 public Name composeName(Name name, Name prefix) 416 throws NamingException { 417 prefix = (Name ) name.clone(); 418 return prefix.addAll(name); 419 } 420 421 422 430 public String composeName(String name, String prefix) 431 throws NamingException { 432 return prefix + "/" + name; 433 } 434 435 436 445 public Object addToEnvironment(String propName, Object propVal) 446 throws NamingException { 447 return env.put(propName, propVal); 448 } 449 450 451 458 public Object removeFromEnvironment(String propName) 459 throws NamingException { 460 return env.remove(propName); 461 } 462 463 464 474 public Hashtable getEnvironment() 475 throws NamingException { 476 return env; 477 } 478 479 480 490 public void close() 491 throws NamingException { 492 env.clear(); 494 } 495 496 497 514 public String getNameInNamespace() 515 throws NamingException { 516 throw new OperationNotSupportedException (); 517 } 518 519 534 public NamingEnumeration search 535 (Name name, String filter, SearchControls cons) 536 throws NamingException { 537 return search(name.toString(), filter, cons); 538 } 539 540 541 556 public NamingEnumeration search(String name, String filter, 557 SearchControls cons) 558 throws NamingException { 559 throw new OperationNotSupportedException (); 560 } 561 562 563 583 public NamingEnumeration search(Name name, String filterExpr, 584 Object [] filterArgs, SearchControls cons) 585 throws NamingException { 586 return search(name.toString(), filterExpr, filterArgs, cons); 587 } 588 589 590 610 public NamingEnumeration search(String name, String filterExpr, 611 Object [] filterArgs, 612 SearchControls cons) 613 throws NamingException { 614 throw new OperationNotSupportedException (); 615 } 616 617 618 } 619 620 | Popular Tags |