1 7 8 package javax.naming; 9 10 import java.util.Enumeration ; 11 import java.util.Properties ; 12 13 131 132 public class CompoundName implements Name { 133 134 139 protected transient NameImpl impl; 140 147 protected transient Properties mySyntax; 148 149 163 protected CompoundName(Enumeration <String > comps, Properties syntax) { 164 if (syntax == null) { 165 throw new NullPointerException (); 166 } 167 mySyntax = syntax; 168 impl = new NameImpl (syntax, comps); 169 } 170 171 182 public CompoundName(String n, Properties syntax) throws InvalidNameException { 183 if (syntax == null) { 184 throw new NullPointerException (); 185 } 186 mySyntax = syntax; 187 impl = new NameImpl (syntax, n); 188 } 189 190 202 public String toString() { 203 return (impl.toString()); 204 } 205 206 229 public boolean equals(Object obj) { 230 return (obj != null && 232 obj instanceof CompoundName && 233 impl.equals(((CompoundName )obj).impl)); 234 } 235 236 247 public int hashCode() { 248 return impl.hashCode(); 249 } 250 251 259 public Object clone() { 260 return (new CompoundName (getAll(), mySyntax)); 261 } 262 263 294 public int compareTo(Object obj) { 295 if (!(obj instanceof CompoundName )) { 296 throw new ClassCastException ("Not a CompoundName"); 297 } 298 return impl.compareTo(((CompoundName )obj).impl); 299 } 300 301 306 public int size() { 307 return (impl.size()); 308 } 309 310 316 public boolean isEmpty() { 317 return (impl.isEmpty()); 318 } 319 320 329 public Enumeration <String > getAll() { 330 return (impl.getAll()); 331 } 332 333 342 public String get(int posn) { 343 return (impl.get(posn)); 344 } 345 346 361 public Name getPrefix(int posn) { 362 Enumeration comps = impl.getPrefix(posn); 363 return (new CompoundName (comps, mySyntax)); 364 } 365 366 381 public Name getSuffix(int posn) { 382 Enumeration comps = impl.getSuffix(posn); 383 return (new CompoundName (comps, mySyntax)); 384 } 385 386 399 public boolean startsWith(Name n) { 400 if (n instanceof CompoundName ) { 401 return (impl.startsWith(n.size(), n.getAll())); 402 } else { 403 return false; 404 } 405 } 406 407 420 public boolean endsWith(Name n) { 421 if (n instanceof CompoundName ) { 422 return (impl.endsWith(n.size(), n.getAll())); 423 } else { 424 return false; 425 } 426 } 427 428 440 public Name addAll(Name suffix) throws InvalidNameException { 441 if (suffix instanceof CompoundName ) { 442 impl.addAll(suffix.getAll()); 443 return this; 444 } else { 445 throw new InvalidNameException ("Not a compound name: " + 446 suffix.toString()); 447 } 448 } 449 450 470 public Name addAll(int posn, Name n) throws InvalidNameException { 471 if (n instanceof CompoundName ) { 472 impl.addAll(posn, n.getAll()); 473 return this; 474 } else { 475 throw new InvalidNameException ("Not a compound name: " + 476 n.toString()); 477 } 478 } 479 480 488 public Name add(String comp) throws InvalidNameException { 489 impl.add(comp); 490 return this; 491 } 492 493 509 public Name add(int posn, String comp) throws InvalidNameException { 510 impl.add(posn, comp); 511 return this; 512 } 513 514 529 public Object remove(int posn) throws InvalidNameException { 530 return impl.remove(posn); 531 } 532 533 539 private void writeObject(java.io.ObjectOutputStream s) 540 throws java.io.IOException { 541 s.writeObject(mySyntax); 542 s.writeInt(size()); 543 Enumeration comps = getAll(); 544 while (comps.hasMoreElements()) { 545 s.writeObject(comps.nextElement()); 546 } 547 } 548 549 552 private void readObject(java.io.ObjectInputStream s) 553 throws java.io.IOException , ClassNotFoundException { 554 mySyntax = (Properties )s.readObject(); 555 impl = new NameImpl (mySyntax); 556 int n = s.readInt(); try { 558 while (--n >= 0) { 559 add((String )s.readObject()); 560 } 561 } catch (InvalidNameException e) { 562 throw (new java.io.StreamCorruptedException ("Invalid name")); 563 } 564 } 565 566 569 private static final long serialVersionUID = 3513100557083972036L; 570 571 607 } 608 609 | Popular Tags |