1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.proxy;
24
25 import java.util.Iterator;
26
27 import lotus.domino.Base;
28 import lotus.domino.Document;
29 import lotus.domino.NotesException;
30 import lotus.domino.View;
31 import de.bea.domingo.DBase;
32 import de.bea.domingo.DNotesMonitor;
33 import de.bea.domingo.DView;
34
35 /***
36 * Abstract base class for all implementations of interfaces derived from
37 * <code>DBase</code>.
38 */
39 public abstract class BaseCollectionProxy extends BaseProxy {
40
41 /***
42 * Constructor.
43 *
44 * @param theFactory the controlling factory
45 * @param theParent the parent object
46 * @param object the notes object
47 * @param monitor the monitor
48 */
49 protected BaseCollectionProxy(final NotesProxyFactory theFactory, final DBase theParent,
50 final Base object, final DNotesMonitor monitor) {
51 super(theFactory, theParent, object, monitor);
52 }
53
54
55
56
57
58
59 /***
60 * Iterator for all documents in a view.
61 *
62 * <p>A Mapper instance is used to map Notes document into a business
63 * object. If no Mapper is provided, a simple default mapper is used that
64 * maps the Notes document into a simple data structure that implements
65 * the DDocument interface.</p>
66 *
67 * @see de.bea.domingo.DDocument
68 *
69 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
70 */
71 public final class ViewIterator implements Iterator {
72
73 /*** Reference to the view to iterate over. */
74 private ViewProxy view = null;
75
76 /*** Reference to current document within the view. */
77 private BaseDocumentProxy document = null;
78
79 /***
80 * Constructor.
81 *
82 * @param theView the View
83 */
84 protected ViewIterator(final DView theView) {
85 view = (ViewProxy) theView;
86 initialize();
87 }
88
89 /***
90 * initialization.
91 */
92 private void initialize() {
93 getFactory().preprocessMethod();
94 try {
95 final Document notesDocument = ((View) view.getNotesObject()).getFirstDocument();
96 document = BaseDocumentProxy.getInstance(getFactory(), view.getParent(), notesDocument, getMonitor());
97 } catch (NotesException e) {
98 throw newRuntimeException("Cannot initialize ViewIterator", e);
99 }
100 }
101
102 /***
103 * {@inheritDoc}
104 * @see java.util.Iterator#hasNext()
105 */
106 public boolean hasNext() {
107 return document != null;
108 }
109
110 /***
111 * {@inheritDoc}
112 * @see java.util.Iterator#next()
113 */
114 public Object next() {
115 getFactory().preprocessMethod();
116 final Object result = document;
117 try {
118 final Document nextNotesDocument =
119 ((View) view.getNotesObject()).getNextDocument((Document) document.getNotesObject());
120 document = BaseDocumentProxy.getInstance(
121 getFactory(), view.getParent(), nextNotesDocument, getMonitor());
122 } catch (NotesException e) {
123 return null;
124 }
125 return result;
126 }
127
128 /***
129 * The <tt>remove</tt> operation is not supported by this Iterator.
130 * An <code>UnsupportedOperationException</code> is thrown if this
131 * method is called.
132 *
133 * @see java.util.Iterator#remove()
134 */
135 public void remove() {
136 throw new UnsupportedOperationException();
137 }
138 }
139 }