1 package org.apache.ojb.odmg.collections; 2 3 17 18 import java.util.ListIterator ; 19 20 import org.apache.ojb.odmg.TransactionImpl; 21 import org.apache.ojb.odmg.RuntimeObject; 22 import org.odmg.Transaction; 23 24 29 class DListIterator implements ListIterator 30 { 31 protected ListIterator iter; 32 private DListImpl dlist; 33 private DListEntry currentEntry = null; 34 35 38 public DListIterator(DListImpl list) 39 { 40 this.dlist = list; 41 this.iter = list.getElements().listIterator(); 42 } 43 44 47 public DListIterator(DListImpl list, int index) 48 { 49 this.dlist = list; 50 this.iter = list.getElements().listIterator(index); 51 } 52 53 56 public void add(Object obj) 57 { 58 DListEntry entry = new DListEntry(this.dlist, obj); 59 entry.setPosition(this.nextIndex() - 1); 60 iter.add(entry); 61 62 TransactionImpl tx = dlist.getTransaction(); 63 if (tx != null) 64 { 65 RuntimeObject rt = new RuntimeObject(entry, tx, true); 66 tx.lockAndRegister(rt, Transaction.WRITE, false, tx.getRegistrationList()); 67 } 68 } 69 70 73 public boolean hasNext() 74 { 75 return iter.hasNext(); 76 } 77 78 81 public boolean hasPrevious() 82 { 83 return iter.hasPrevious(); 84 } 85 86 89 public Object next() 90 { 91 currentEntry = ((DListEntry) iter.next()); 92 return currentEntry.getRealSubject(); 93 } 94 95 98 public int nextIndex() 99 { 100 return iter.nextIndex(); 101 } 102 103 106 public Object previous() 107 { 108 currentEntry = ((DListEntry) iter.previous()); 109 return currentEntry.getRealSubject(); 110 } 111 112 115 public int previousIndex() 116 { 117 return iter.previousIndex(); 118 } 119 120 123 public void remove() 124 { 125 iter.remove(); 126 TransactionImpl tx = dlist.getTransaction(); 127 if (tx != null) 128 { 129 tx.markDelete(currentEntry); 130 } 131 currentEntry = null; 132 } 133 134 137 public void set(Object o) 138 { 139 throw new UnsupportedOperationException ("Method is not supported"); 140 } 142 143 } 144 | Popular Tags |