KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > collections > DListIterator


1 package org.apache.ojb.odmg.collections;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import java.util.ListIterator JavaDoc;
19
20 import org.apache.ojb.odmg.TransactionImpl;
21 import org.apache.ojb.odmg.RuntimeObject;
22 import org.odmg.Transaction;
23
24 /**
25  * Iterator implementation for {@link org.odmg.DList} implementation.
26  *
27  * @version $Id: DListIterator.java,v 1.8.2.4 2005/12/21 22:29:50 tomdz Exp $
28  */

29 class DListIterator implements ListIterator JavaDoc
30 {
31     protected ListIterator JavaDoc iter;
32     private DListImpl dlist;
33     private DListEntry currentEntry = null;
34
35     /**
36      * DListIterator constructor comment.
37      */

38     public DListIterator(DListImpl list)
39     {
40         this.dlist = list;
41         this.iter = list.getElements().listIterator();
42     }
43
44     /**
45      * DListIterator constructor comment.
46      */

47     public DListIterator(DListImpl list, int index)
48     {
49         this.dlist = list;
50         this.iter = list.getElements().listIterator(index);
51     }
52
53     /**
54      * @see ListIterator#add(Object)
55      */

56     public void add(Object JavaDoc 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     /**
71      * @see java.util.ListIterator#hasNext()
72      */

73     public boolean hasNext()
74     {
75         return iter.hasNext();
76     }
77
78     /**
79      * @see java.util.ListIterator#hasPrevious()
80      */

81     public boolean hasPrevious()
82     {
83         return iter.hasPrevious();
84     }
85
86     /**
87      * @see java.util.ListIterator#next()
88      */

89     public Object JavaDoc next()
90     {
91         currentEntry = ((DListEntry) iter.next());
92         return currentEntry.getRealSubject();
93     }
94
95     /**
96      * @see java.util.ListIterator#nextIndex()
97      */

98     public int nextIndex()
99     {
100         return iter.nextIndex();
101     }
102
103     /**
104      * @see java.util.ListIterator#previous()
105      */

106     public Object JavaDoc previous()
107     {
108         currentEntry = ((DListEntry) iter.previous());
109         return currentEntry.getRealSubject();
110     }
111
112     /**
113      * @see java.util.ListIterator#previousIndex()
114      */

115     public int previousIndex()
116     {
117         return iter.previousIndex();
118     }
119
120     /**
121      * @see java.util.ListIterator#remove()
122      */

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     /**
135      * @see ListIterator#set(Object)
136      */

137     public void set(Object JavaDoc o)
138     {
139         throw new UnsupportedOperationException JavaDoc("Method is not supported");
140         // currentEntry.setRealSubject(o);
141
}
142
143 }
144
Popular Tags