View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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      //    Iterator classes
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 }