1 7 8 package javax.naming; 9 10 import java.util.Enumeration ; 11 import java.util.Properties ; 12 13 184 185 186 public class CompositeName implements Name { 187 188 private transient NameImpl impl; 189 200 protected CompositeName(Enumeration <String > comps) { 201 impl = new NameImpl (null, comps); } 203 204 213 public CompositeName(String n) throws InvalidNameException { 214 impl = new NameImpl (null, n); } 216 217 221 public CompositeName() { 222 impl = new NameImpl (null); } 224 225 240 public String toString() { 241 return impl.toString(); 242 } 243 244 257 public boolean equals(Object obj) { 258 return (obj != null && 259 obj instanceof CompositeName && 260 impl.equals(((CompositeName )obj).impl)); 261 } 262 263 271 public int hashCode() { 272 return impl.hashCode(); 273 } 274 275 276 303 public int compareTo(Object obj) { 304 if (!(obj instanceof CompositeName )) { 305 throw new ClassCastException ("Not a CompositeName"); 306 } 307 return impl.compareTo(((CompositeName )obj).impl); 308 } 309 310 317 public Object clone() { 318 return (new CompositeName (getAll())); 319 } 320 321 326 public int size() { 327 return (impl.size()); 328 } 329 330 336 public boolean isEmpty() { 337 return (impl.isEmpty()); 338 } 339 340 350 public Enumeration <String > getAll() { 351 return (impl.getAll()); 352 } 353 354 363 public String get(int posn) { 364 return (impl.get(posn)); 365 } 366 367 379 public Name getPrefix(int posn) { 380 Enumeration comps = impl.getPrefix(posn); 381 return (new CompositeName (comps)); 382 } 383 384 397 public Name getSuffix(int posn) { 398 Enumeration comps = impl.getSuffix(posn); 399 return (new CompositeName (comps)); 400 } 401 402 412 public boolean startsWith(Name n) { 413 if (n instanceof CompositeName ) { 414 return (impl.startsWith(n.size(), n.getAll())); 415 } else { 416 return false; 417 } 418 } 419 420 431 public boolean endsWith(Name n) { 432 if (n instanceof CompositeName ) { 433 return (impl.endsWith(n.size(), n.getAll())); 434 } else { 435 return false; 436 } 437 } 438 439 447 public Name addAll(Name suffix) 448 throws InvalidNameException 449 { 450 if (suffix instanceof CompositeName ) { 451 impl.addAll(suffix.getAll()); 452 return this; 453 } else { 454 throw new InvalidNameException ("Not a composite name: " + 455 suffix.toString()); 456 } 457 } 458 459 474 public Name addAll(int posn, Name n) 475 throws InvalidNameException 476 { 477 if (n instanceof CompositeName ) { 478 impl.addAll(posn, n.getAll()); 479 return this; 480 } else { 481 throw new InvalidNameException ("Not a composite name: " + 482 n.toString()); 483 } 484 } 485 486 494 public Name add(String comp) throws InvalidNameException { 495 impl.add(comp); 496 return this; 497 } 498 499 515 public Name add(int posn, String comp) 516 throws InvalidNameException 517 { 518 impl.add(posn, comp); 519 return this; 520 } 521 522 537 public Object remove(int posn) throws InvalidNameException { 538 return impl.remove(posn); 539 } 540 541 546 private void writeObject(java.io.ObjectOutputStream s) 547 throws java.io.IOException { 548 s.writeInt(size()); 549 Enumeration comps = getAll(); 550 while (comps.hasMoreElements()) { 551 s.writeObject(comps.nextElement()); 552 } 553 } 554 555 558 private void readObject(java.io.ObjectInputStream s) 559 throws java.io.IOException , ClassNotFoundException { 560 impl = new NameImpl (null); int n = s.readInt(); try { 563 while (--n >= 0) { 564 add((String )s.readObject()); 565 } 566 } catch (InvalidNameException e) { 567 throw (new java.io.StreamCorruptedException ("Invalid name")); 568 } 569 } 570 571 574 private static final long serialVersionUID = 1667768148915813118L; 575 576 592 593 613 } 614 | Popular Tags |