001: package org.apache.ojb.odmg.collections;
002:
003: /* Copyright 2003-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import java.util.ListIterator;
019:
020: import org.apache.ojb.odmg.TransactionImpl;
021: import org.apache.ojb.odmg.RuntimeObject;
022: import org.odmg.Transaction;
023:
024: /**
025: * Iterator implementation for {@link org.odmg.DList} implementation.
026: *
027: * @version $Id: DListIterator.java,v 1.8.2.4 2005/12/21 22:29:50 tomdz Exp $
028: */
029: class DListIterator implements ListIterator {
030: protected ListIterator iter;
031: private DListImpl dlist;
032: private DListEntry currentEntry = null;
033:
034: /**
035: * DListIterator constructor comment.
036: */
037: public DListIterator(DListImpl list) {
038: this .dlist = list;
039: this .iter = list.getElements().listIterator();
040: }
041:
042: /**
043: * DListIterator constructor comment.
044: */
045: public DListIterator(DListImpl list, int index) {
046: this .dlist = list;
047: this .iter = list.getElements().listIterator(index);
048: }
049:
050: /**
051: * @see ListIterator#add(Object)
052: */
053: public void add(Object obj) {
054: DListEntry entry = new DListEntry(this .dlist, obj);
055: entry.setPosition(this .nextIndex() - 1);
056: iter.add(entry);
057:
058: TransactionImpl tx = dlist.getTransaction();
059: if (tx != null) {
060: RuntimeObject rt = new RuntimeObject(entry, tx, true);
061: tx.lockAndRegister(rt, Transaction.WRITE, false, tx
062: .getRegistrationList());
063: }
064: }
065:
066: /**
067: * @see java.util.ListIterator#hasNext()
068: */
069: public boolean hasNext() {
070: return iter.hasNext();
071: }
072:
073: /**
074: * @see java.util.ListIterator#hasPrevious()
075: */
076: public boolean hasPrevious() {
077: return iter.hasPrevious();
078: }
079:
080: /**
081: * @see java.util.ListIterator#next()
082: */
083: public Object next() {
084: currentEntry = ((DListEntry) iter.next());
085: return currentEntry.getRealSubject();
086: }
087:
088: /**
089: * @see java.util.ListIterator#nextIndex()
090: */
091: public int nextIndex() {
092: return iter.nextIndex();
093: }
094:
095: /**
096: * @see java.util.ListIterator#previous()
097: */
098: public Object previous() {
099: currentEntry = ((DListEntry) iter.previous());
100: return currentEntry.getRealSubject();
101: }
102:
103: /**
104: * @see java.util.ListIterator#previousIndex()
105: */
106: public int previousIndex() {
107: return iter.previousIndex();
108: }
109:
110: /**
111: * @see java.util.ListIterator#remove()
112: */
113: public void remove() {
114: iter.remove();
115: TransactionImpl tx = dlist.getTransaction();
116: if (tx != null) {
117: tx.markDelete(currentEntry);
118: }
119: currentEntry = null;
120: }
121:
122: /**
123: * @see ListIterator#set(Object)
124: */
125: public void set(Object o) {
126: throw new UnsupportedOperationException(
127: "Method is not supported");
128: // currentEntry.setRealSubject(o);
129: }
130:
131: }
|