1 21 package oracle.toplink.essentials.indirection; 23 24 import java.util.*; 25 import oracle.toplink.essentials.internal.indirection.*; 26 27 46 public class IndirectList extends Vector implements IndirectContainer { 47 48 49 protected Vector delegate; 50 51 52 protected ValueHolderInterface valueHolder; 53 54 55 private transient String attributeName; 56 57 58 protected int initialCapacity = 10; 59 60 65 public IndirectList() { 66 this(10); 67 } 68 69 78 public IndirectList(int initialCapacity) { 79 this(initialCapacity, 0); 80 } 81 82 93 public IndirectList(int initialCapacity, int capacityIncrement) { 94 super(0); 95 this.initialize(initialCapacity, capacityIncrement); 96 } 97 98 105 public IndirectList(Collection c) { 106 super(0); 107 this.initialize(c); 108 } 109 110 113 public void add(int index, Object element) { 114 this.getDelegate().add(index, element); 115 raiseAddChangeEvent(element); 116 } 117 118 121 protected void raiseAddChangeEvent(Object element) { 122 if (hasBeenRegistered()) { 123 ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceSet(element, null); 124 } 125 } 126 127 130 protected void raiseRemoveChangeEvent(Object element) { 131 if (hasBeenRegistered()) { 132 ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceRemove(element); 133 } 134 } 135 136 139 public synchronized boolean add(Object o) { 140 this.getDelegate().add(o); 141 raiseAddChangeEvent(o); 142 return true; 143 } 144 145 148 public synchronized boolean addAll(int index, Collection c) { 149 Iterator objects = c.iterator(); 150 if (hasBeenRegistered()) { 152 while (objects.hasNext()) { 153 this.add(index, objects.next()); 154 index++; 155 } 156 return true; 157 } 158 159 return this.getDelegate().addAll(index, c); 160 161 } 162 163 166 public synchronized boolean addAll(Collection c) { 167 if (hasBeenRegistered()) { 169 Iterator objects = c.iterator(); 170 while (objects.hasNext()) { 171 this.add(objects.next()); 172 } 173 return true; 174 } 175 176 return getDelegate().addAll(c); 177 } 178 179 182 public synchronized void addElement(Object obj) { 183 this.add(obj); 184 } 185 186 192 protected Vector buildDelegate() { 193 return (Vector)getValueHolder().getValue(); 194 } 195 196 199 public int capacity() { 200 return this.getDelegate().capacity(); 201 } 202 203 206 public void clear() { 207 if (hasBeenRegistered()) { 208 Iterator objects = this.iterator(); 209 while (objects.hasNext()) { 210 Object o = objects.next(); 211 objects.remove(); 212 this.raiseRemoveChangeEvent(o); 213 } 214 } else { 215 this.getDelegate().clear(); 216 } 217 } 218 219 224 225 237 public synchronized Object clone() { 238 IndirectList result = (IndirectList)super.clone(); 239 result.delegate = (Vector)this.getDelegate().clone(); 240 result.attributeName = null; 241 return result; 242 } 243 244 248 public boolean contains(Object elem) { 249 return this.getDelegate().contains(elem); 250 } 251 252 255 public synchronized boolean containsAll(Collection c) { 256 return this.getDelegate().containsAll(c); 257 } 258 259 262 public synchronized void copyInto(Object [] anArray) { 263 this.getDelegate().copyInto(anArray); 264 } 265 266 269 public synchronized Object elementAt(int index) { 270 return this.getDelegate().elementAt(index); 271 } 272 273 276 public Enumeration elements() { 277 return this.getDelegate().elements(); 278 } 279 280 283 public synchronized void ensureCapacity(int minCapacity) { 284 this.getDelegate().ensureCapacity(minCapacity); 285 } 286 287 290 public synchronized boolean equals(Object o) { 291 return this.getDelegate().equals(o); 292 } 293 294 297 public synchronized Object firstElement() { 298 return this.getDelegate().firstElement(); 299 } 300 301 304 public synchronized Object get(int index) { 305 return this.getDelegate().get(index); 306 } 307 308 313 protected synchronized Vector getDelegate() { 314 if (delegate == null) { 315 delegate = this.buildDelegate(); 316 } 317 return delegate; 318 } 319 320 324 public synchronized ValueHolderInterface getValueHolder() { 325 if (valueHolder == null) { 327 valueHolder = new ValueHolder(new Vector(this.initialCapacity, this.capacityIncrement)); 328 } 329 return valueHolder; 330 } 331 332 336 public boolean hasBeenRegistered() { 337 return getValueHolder() instanceof oracle.toplink.essentials.internal.indirection.UnitOfWorkQueryValueHolder; 338 } 339 340 344 public synchronized int hashCode() { 345 return this.getDelegate().hashCode(); 346 } 347 348 351 public int indexOf(Object elem) { 352 return this.getDelegate().indexOf(elem); 353 } 354 355 358 public synchronized int indexOf(Object elem, int index) { 359 return this.getDelegate().indexOf(elem, index); 360 } 361 362 365 protected void initialize(int initialCapacity, int capacityIncrement) { 366 this.initialCapacity = initialCapacity; 367 this.capacityIncrement = capacityIncrement; 368 this.delegate = null; 369 this.valueHolder = null; 370 } 371 372 375 protected void initialize(Collection c) { 376 this.delegate = null; 377 Vector temp = new Vector(c); 378 this.valueHolder = new ValueHolder(temp); 379 } 380 381 384 public synchronized void insertElementAt(Object obj, int index) { 385 this.getDelegate().insertElementAt(obj, index); 386 this.raiseAddChangeEvent(obj); 387 } 388 389 392 public boolean isEmpty() { 393 return this.getDelegate().isEmpty(); 394 } 395 396 400 public boolean isInstantiated() { 401 return this.getValueHolder().isInstantiated(); 402 } 403 404 407 public Iterator iterator() { 408 return new Iterator() { 410 Iterator delegateIterator = IndirectList.this.getDelegate().iterator(); 411 Object currentObject; 412 413 public boolean hasNext() { 414 return this.delegateIterator.hasNext(); 415 } 416 417 public Object next() { 418 this.currentObject = this.delegateIterator.next(); 419 return this.currentObject; 420 } 421 422 public void remove() { 423 this.delegateIterator.remove(); 424 IndirectList.this.raiseRemoveChangeEvent(this.currentObject); 425 } 426 }; 427 } 428 429 432 public synchronized Object lastElement() { 433 return this.getDelegate().lastElement(); 434 } 435 436 439 public int lastIndexOf(Object elem) { 440 return this.getDelegate().lastIndexOf(elem); 441 } 442 443 446 public synchronized int lastIndexOf(Object elem, int index) { 447 return this.getDelegate().lastIndexOf(elem, index); 448 } 449 450 453 public ListIterator listIterator() { 454 return this.listIterator(0); 455 } 456 457 460 public ListIterator listIterator(final int index) { 461 return new ListIterator() { 463 ListIterator delegateIterator = IndirectList.this.getDelegate().listIterator(index); 464 Object currentObject; 465 466 public boolean hasNext() { 467 return this.delegateIterator.hasNext(); 468 } 469 470 public boolean hasPrevious() { 471 return this.delegateIterator.hasPrevious(); 472 } 473 474 public int previousIndex() { 475 return this.delegateIterator.previousIndex(); 476 } 477 478 public int nextIndex() { 479 return this.delegateIterator.nextIndex(); 480 } 481 482 public Object next() { 483 this.currentObject = this.delegateIterator.next(); 484 return this.currentObject; 485 } 486 487 public Object previous() { 488 this.currentObject = this.delegateIterator.previous(); 489 return this.currentObject; 490 } 491 492 public void remove() { 493 this.delegateIterator.remove(); 494 IndirectList.this.raiseRemoveChangeEvent(this.currentObject); 495 } 496 497 public void set(Object object) { 498 this.delegateIterator.set(object); 499 IndirectList.this.raiseRemoveChangeEvent(this.currentObject); 500 IndirectList.this.raiseAddChangeEvent(object); 501 } 502 503 public void add(Object object) { 504 this.delegateIterator.add(object); 505 IndirectList.this.raiseAddChangeEvent(object); 506 } 507 }; 508 } 509 510 513 public synchronized Object remove(int index) { 514 Object value = this.getDelegate().remove(index); 515 this.raiseRemoveChangeEvent(value); 516 return value; 517 } 518 519 522 public boolean remove(Object o) { 523 if (this.getDelegate().remove(o)) { 524 this.raiseRemoveChangeEvent(o); 525 return true; 526 } 527 return false; 528 } 529 530 533 public synchronized boolean removeAll(Collection c) { 534 if (hasBeenRegistered()) { 536 Iterator objects = c.iterator(); 537 while (objects.hasNext()) { 538 this.remove(objects.next()); 539 } 540 return true; 541 } 542 return this.getDelegate().removeAll(c); 543 } 544 545 548 public synchronized void removeAllElements() { 549 if (hasBeenRegistered()) { 551 Iterator objects = this.iterator(); 552 while (objects.hasNext()) { 553 Object object = objects.next(); 554 objects.remove(); 555 this.raiseRemoveChangeEvent(object); 556 } 557 return; 558 } 559 this.getDelegate().removeAllElements(); 560 } 561 562 565 public synchronized boolean removeElement(Object obj) { 566 return this.remove(obj); 567 } 568 569 572 public synchronized void removeElementAt(int index) { 573 this.remove(index); 574 } 575 576 579 public synchronized boolean retainAll(Collection c) { 580 if (hasBeenRegistered()) { 582 Iterator objects = getDelegate().iterator(); 583 while (objects.hasNext()) { 584 Object object = objects.next(); 585 if (!c.contains(object)) { 586 objects.remove(); 587 this.raiseRemoveChangeEvent(object); 588 } 589 } 590 return true; 591 } 592 return this.getDelegate().retainAll(c); 593 } 594 595 598 public synchronized Object set(int index, Object element) { 599 Object oldValue = this.getDelegate().set(index, element); 600 this.raiseRemoveChangeEvent(oldValue); 601 this.raiseAddChangeEvent(element); 602 return oldValue; 603 } 604 605 608 public synchronized void setElementAt(Object obj, int index) { 609 this.set(index, obj); 610 } 611 612 615 public synchronized void setSize(int newSize) { 616 if (hasBeenRegistered()) { 618 if (newSize > this.size()) { 619 for (int index = size(); index > newSize; index--) { 620 this.remove(index - 1); 621 } 622 } 623 } 624 this.getDelegate().setSize(newSize); 625 } 626 627 631 public void setValueHolder(ValueHolderInterface valueHolder) { 632 this.delegate = null; 633 this.valueHolder = valueHolder; 634 } 635 636 639 public int size() { 640 return this.getDelegate().size(); 641 } 642 643 646 public List subList(int fromIndex, int toIndex) { 647 return this.getDelegate().subList(fromIndex, toIndex); 648 } 649 650 653 public synchronized Object [] toArray() { 654 return this.getDelegate().toArray(); 655 } 656 657 660 public synchronized Object [] toArray(Object [] a) { 661 return this.getDelegate().toArray(a); 662 } 663 664 671 public String toString() { 672 if (ValueHolderInterface.shouldToStringInstantiate) { 673 return this.getDelegate().toString(); 674 } 675 if (this.isInstantiated()) { 676 return "{" + this.getDelegate().toString() + "}"; 677 } else { 678 return "{" + oracle.toplink.essentials.internal.helper.Helper.getShortClassName(this.getClass()) + ": not instantiated}"; 679 } 680 } 681 682 685 public synchronized void trimToSize() { 686 this.getDelegate().trimToSize(); 687 } 688 689 692 public String getTopLinkAttributeName() { 693 return attributeName; 694 } 695 696 700 public void setTopLinkAttributeName(String attributeName) { 701 this.attributeName = attributeName; 702 } 703 } 704 | Popular Tags |