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.io.IOException;
26  import java.io.Writer;
27  import java.util.ArrayList;
28  import java.util.Calendar;
29  import java.util.Collections;
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.TimeZone;
33  import java.util.Vector;
34  
35  import lotus.domino.Base;
36  import lotus.domino.Database;
37  import lotus.domino.DateRange;
38  import lotus.domino.DateTime;
39  import lotus.domino.Document;
40  import lotus.domino.EmbeddedObject;
41  import lotus.domino.Item;
42  import lotus.domino.NotesError;
43  import lotus.domino.NotesException;
44  import lotus.domino.RichTextItem;
45  import de.bea.domingo.DBase;
46  import de.bea.domingo.DBaseDocument;
47  import de.bea.domingo.DBaseItem;
48  import de.bea.domingo.DDatabase;
49  import de.bea.domingo.DDateRange;
50  import de.bea.domingo.DDocument;
51  import de.bea.domingo.DEmbeddedObject;
52  import de.bea.domingo.DItem;
53  import de.bea.domingo.DNotesException;
54  import de.bea.domingo.DNotesMonitor;
55  import de.bea.domingo.DProfileDocument;
56  import de.bea.domingo.DRichTextItem;
57  import de.bea.domingo.util.DateUtil;
58  import de.bea.domingo.util.GregorianDateTimeRange;
59  import de.bea.domingo.util.Timezones;
60  
61  /***
62   * Represents a document in a database.
63   */
64  public abstract class BaseDocumentProxy extends BaseProxy implements DBaseDocument {
65  
66      /***
67       * Constructor for DDocumentImpl.
68       *
69       * @param theFactory the controlling factory
70       * @param parent the parent object
71       * @param document the notes document
72       * @param monitor the monitor
73       */
74      protected BaseDocumentProxy(final NotesProxyFactory theFactory, final DBase parent,
75                                  final Document document, final DNotesMonitor monitor) {
76          super(theFactory, parent, document, monitor);
77          if (document == null) {
78              throw new RuntimeException("Document not defined");
79          }
80      }
81  
82      /***
83       * Creates or returns a cached implementation of the requested document
84       * interface.
85       *
86       * @param theFactory the controlling factory
87       * @param parent the parent object
88       * @param document the associated Notes document
89       * @param monitor the monitor
90       *
91       * @return implementation of interface DDocument or null
92       */
93      static BaseDocumentProxy getInstance(final NotesProxyFactory theFactory, final DBase parent,
94                                           final Document document, final DNotesMonitor monitor) {
95          if (document == null) {
96              return null;
97          }
98          BaseDocumentProxy documentProxy = (BaseDocumentProxy) theFactory.getBaseCache().get(document);
99          if (documentProxy == null) {
100             boolean isProfile = false;
101             try {
102                 isProfile = document.isProfile();
103             } catch (NotesException e) {
104                 isProfile = false;
105             }
106             if (isProfile) {
107                 documentProxy = new ProfileDocumentProxy(theFactory, parent, document, monitor);
108             } else {
109                 documentProxy = new DocumentProxy(theFactory, parent, document, monitor);
110             }
111             documentProxy.setMonitor(monitor);
112             theFactory.getBaseCache().put(document, documentProxy);
113         }
114         return documentProxy;
115     }
116 
117     /***
118      * {@inheritDoc}
119      * @see de.bea.domingo.DBaseDocument#getParentDatabase()
120      */
121     public final DDatabase getParentDatabase() {
122         getFactory().preprocessMethod();
123         try {
124             final Database database = getDocument().getParentDatabase();
125             return DatabaseProxy.getInstance(getFactory(), null, database, getMonitor(), true);
126         } catch (NotesException e) {
127             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.parentdatabase"), e);
128         }
129     }
130 
131     /***
132      * {@inheritDoc}
133      * @see de.bea.domingo.DBaseDocument#getFirstItem(String)
134      */
135     public final DBaseItem getFirstItem(final String itemName) {
136         getFactory().preprocessMethod();
137         try {
138             final Item item = getDocument().getFirstItem(itemName);
139             if (item != null) {
140                 return BaseItemProxy.getInstance(getFactory(), this, item, getMonitor());
141             }
142         } catch (NotesException e) {
143             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.firstitem.1", itemName), e);
144         }
145         return null;
146     }
147 
148     /***
149      * {@inheritDoc}
150      * @see de.bea.domingo.DBaseDocument#getCreated()
151      */
152     public final Calendar getCreated() {
153         getFactory().preprocessMethod();
154         try {
155             final DateTime dateTime = getDocument().getCreated();
156             final Calendar calendar = createCalendar(dateTime);
157             getFactory().recycle(dateTime);
158             return calendar;
159         } catch (NotesException e) {
160             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.createddate"), e);
161         }
162     }
163 
164     /***
165      * {@inheritDoc}
166      * @see de.bea.domingo.DBaseDocument#save()
167      */
168     public final boolean save() {
169         getFactory().preprocessMethod();
170         try {
171             return getDocument().save();
172         } catch (NotesException e) {
173             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.save.document"), e);
174         }
175     }
176 
177     /***
178      * {@inheritDoc}
179      * @see de.bea.domingo.DBaseDocument#save(boolean, boolean)
180      */
181     public final boolean save(final boolean force, final boolean makeresponse) {
182         getFactory().preprocessMethod();
183         try {
184             return getDocument().save(force, makeresponse);
185         } catch (NotesException e) {
186             throw newRuntimeException("Cannot save document", e);
187         }
188     }
189 
190     /***
191      * {@inheritDoc}
192      * @see de.bea.domingo.DBaseDocument#appendItemValue(java.lang.String)
193      */
194     public final DItem appendItemValue(final String name) {
195         getFactory().preprocessMethod();
196         try {
197             final Item item = getDocument().appendItemValue(name, "");
198             return (DItem) BaseItemProxy.getInstance(getFactory(), this, item, getMonitor());
199         } catch (NotesException e) {
200             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.append.value.1") + name, e);
201         }
202     }
203 
204     /***
205      * {@inheritDoc}
206      * @see de.bea.domingo.DBaseDocument#appendItemValue(java.lang.String, int)
207      */
208     public final DItem appendItemValue(final String name, final int value) {
209         getFactory().preprocessMethod();
210         try {
211             final Item item = getDocument().appendItemValue(name, value);
212             return (DItem) BaseItemProxy.getInstance(getFactory(), this, item, getMonitor());
213         } catch (NotesException e) {
214             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.append.value.integer.1") + name, e);
215         }
216     }
217 
218     /***
219      * {@inheritDoc}
220      * @see de.bea.domingo.DBaseDocument#appendItemValue(java.lang.String, double)
221      */
222     public final DItem appendItemValue(final String name, final double value) {
223         getFactory().preprocessMethod();
224         try {
225             final Item item = getDocument().appendItemValue(name, value);
226             return (DItem) BaseItemProxy.getInstance(getFactory(), this, item, getMonitor());
227         } catch (NotesException e) {
228             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.append.value.double.1", name), e);
229         }
230     }
231 
232     /***
233      * {@inheritDoc}
234      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.util.Calendar)
235      */
236     public final DItem replaceItemValue(final String name, final Calendar value) {
237         if (value == null) {
238             return replaceItemValue(name, EMPTY_STRING);
239         }
240         getFactory().preprocessMethod();
241         try {
242             final DateTime dateTime = createDateTime(value);
243             final Item notesItem = getDocument().replaceItemValue(name, dateTime);
244             getFactory().recycle(dateTime);
245             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
246         } catch (NotesException e) {
247             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.set.value.calendar.1", name), e);
248         }
249     }
250 
251     /***
252      * {@inheritDoc}
253      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.util.TimeZone)
254      */
255     public final DItem replaceItemValue(final String name, final TimeZone value) {
256         String s = EMPTY_STRING;
257         if (value == null) {
258             getMonitor().warn("time zone is null; storing an empty string in item " + name);
259         } else {
260             s = Timezones.getLotusTimeZoneString(value);
261             if (s.startsWith("Unknown")) {
262                 getMonitor().warn("Unknown time zone identifier (using default): " + s);
263                 s = TimeZone.getDefault().getID();
264                 s = Timezones.getLotusTimeZoneString(s);
265             }
266         }
267         return replaceItemValue(name, s);
268     }
269 
270     /***
271      * {@inheritDoc}
272      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, de.bea.domingo.DDateRange)
273      */
274     public final DItem replaceItemValue(final String name, final DDateRange value) {
275         return replaceItemValue(name, value.getFrom(), value.getTo());
276     }
277 
278     /***
279      * {@inheritDoc}
280      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.util.Calendar, java.util.Calendar)
281      */
282     public final DItem replaceItemValue(final String name, final Calendar calendar1, final Calendar calendar2) {
283         if (calendar1 == null && calendar2 == null) {
284             return replaceItemValue(name, EMPTY_STRING);
285         } else if (calendar1 == null) {
286             return replaceItemValue(name, calendar2);
287         } else if (calendar2 == null) {
288             return replaceItemValue(name, calendar1);
289         }
290         getFactory().preprocessMethod();
291         try {
292             final DateRange dateRange = createDateRange(calendar1, calendar2);
293             final Item notesItem = getDocument().replaceItemValue(name, dateRange);
294             getFactory().recycle(dateRange);
295             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
296         } catch (NotesException e) {
297             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.set.daterange"), e);
298         }
299     }
300 
301     /***
302      * {@inheritDoc}
303      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.util.List)
304      */
305     public final DItem replaceItemValue(final String name, final List values) {
306         if (values == null || values.size() == 0) {
307             return replaceItemValue(name, EMPTY_STRING);
308         }
309         getFactory().preprocessMethod();
310         final List convertedKeys = convertCalendarsToNotesDateTime(values);
311         final Vector vector = convertListToVector(convertedKeys);
312         try {
313             final Item notesItem = getDocument().replaceItemValue(name, vector);
314             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
315         } catch (NotesException e) {
316             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.replace.value.1", name), e);
317         } finally {
318             recycleDateTimeList(convertedKeys);
319         }
320     }
321 
322     /***
323      * {@inheritDoc}
324      * @see de.bea.domingo.DBaseDocument#save(boolean)
325      */
326     public final boolean save(final boolean force) {
327         getFactory().preprocessMethod();
328         try {
329             return getDocument().save(force);
330         } catch (NotesException e) {
331             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.save"), e);
332         }
333     }
334 
335     /***
336      * {@inheritDoc}
337      * @see de.bea.domingo.DBaseDocument#createRichTextItem(String)
338      */
339     public final DRichTextItem createRichTextItem(final String name) {
340         getFactory().preprocessMethod();
341         try {
342             final RichTextItem item = getDocument().createRichTextItem(name);
343             return (DRichTextItem) BaseItemProxy.getInstance(getFactory(), this, item, getMonitor());
344         } catch (NotesException e) {
345             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.create.rti.1", name), e);
346         }
347     }
348 
349     /***
350      * {@inheritDoc}
351      * @see de.bea.domingo.DBaseDocument#remove()
352      */
353     public final boolean remove() {
354         return remove(false);
355     }
356 
357     /***
358      * {@inheritDoc}
359      * @see de.bea.domingo.DBaseDocument#remove(boolean)
360      */
361     public final boolean remove(final boolean force) {
362         getFactory().preprocessMethod();
363         try {
364             return getDocument().remove(force);
365         } catch (NotesException e) {
366             if (e.id == NotesError.NOTES_ERR_DELETED) {
367                 return false;
368             }
369             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.remove"), e);
370         }
371     }
372 
373     /***
374      * {@inheritDoc}
375      * @see de.bea.domingo.DBaseDocument#getAttachment(String)
376      */
377     public final DEmbeddedObject getAttachment(final String attachmentName) {
378         getFactory().preprocessMethod();
379         try {
380             final EmbeddedObject eo = getDocument().getAttachment(attachmentName);
381             final DEmbeddedObject proxy =
382                 EmbeddedObjectProxy.getInstance(getFactory(), this, eo, getMonitor());
383             return proxy;
384         } catch (NotesException e) {
385             String msg = RESOURCES.getString("basedocument.cannot.get.attachment.1", attachmentName);
386             throw newRuntimeException(msg, e);
387         }
388     }
389 
390     /***
391      * {@inheritDoc}
392      * @see de.bea.domingo.DBaseDocument#removeItem(String)
393      */
394     public final void removeItem(final String name) {
395         getFactory().preprocessMethod();
396         try {
397             getDocument().removeItem(name);
398         } catch (NotesException e) {
399             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.remove.item.1", name), e);
400         }
401     }
402 
403     /***
404      * {@inheritDoc}
405      * @see de.bea.domingo.DBaseDocument#getItemValue(String)
406      */
407     public final List getItemValue(final String name) {
408         getFactory().preprocessMethod();
409         try {
410             Vector vector = null;
411             final Item item = getDocument().getFirstItem(name);
412             if (item != null && (item.getType() == Item.DATETIMES)) {
413                 vector = ((Document) getNotesObject()).getItemValueDateTimeArray(name);
414                 List list = convertNotesDateTimesToCalendar(vector);
415                 final String text = getDocument().getFirstItem(name).abstractText(DATETIME_STRING_LENGTH + 2, false, false);
416                 if (text != null && text.length() > 0) {
417                     if (text.indexOf('-') >= 0) { // we have a date/time range
418                         GregorianDateTimeRange range = new GregorianDateTimeRange((Calendar) list.get(0), (Calendar) list.get(1));
419                         List result = new ArrayList(1);
420                         result.add(range);
421                         return result;
422                     } else { // we have a list of dates/times
423                         return list;
424                     }
425                 }
426                 return new ArrayList(0);
427             } else {
428                 vector = getDocument().getItemValue(name);
429             }
430             if (vector == null) {
431                 vector = new Vector();
432             }
433             return Collections.unmodifiableList(vector);
434         } catch (NotesException e) {
435             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.value.1", name), e);
436         }
437     }
438 
439     /***
440      * {@inheritDoc}
441      * @see de.bea.domingo.DBaseDocument#getItemValueString(java.lang.String)
442      */
443     public final String getItemValueString(final String name) {
444         getFactory().preprocessMethod();
445         try {
446             final String value = getDocument().getItemValueString(name);
447             if (value != null) {
448                 return value;
449             }
450         } catch (NotesException e) {
451             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.value.string.1", name), e);
452         }
453         return EMPTY_STRING;
454     }
455 
456     /***
457      * {@inheritDoc}
458      * @see de.bea.domingo.DBaseDocument#hasItem(String)
459      */
460     public final boolean hasItem(final String name) {
461         getFactory().preprocessMethod();
462         try {
463             return getDocument().hasItem(name);
464         } catch (NotesException e) {
465             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.existence.1", name), e);
466         }
467     }
468 
469     /***
470      * Returns the associated Notes document.
471      *
472      * @return the Notes document object
473      */
474     final Document getDocument() {
475         return (Document) getNotesObject();
476     }
477 
478     /***
479      * {@inheritDoc}
480      * @see de.bea.domingo.DBaseDocument#getItemValueDate(java.lang.String)
481      */
482     public final Calendar getItemValueDate(final String name) {
483         getFactory().preprocessMethod();
484         try {
485             Vector vector = ((Document) getNotesObject()).getItemValueDateTimeArray(name);
486             Calendar calendar = null;
487             if (vector != null && vector.size() > 0) {
488                 calendar = createCalendar((DateTime) vector.get(0));
489                 recycleDateTimeList(vector);
490             }
491             return calendar;
492         } catch (NotesException e) {
493             if (e.id == NotesError.NOTES_ERR_NOT_A_DATE_ITEM) {
494                 return null;
495             }
496             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.value.calendar.1", name), e);
497         }
498     }
499 
500     /***
501      * {@inheritDoc}
502      * @see de.bea.domingo.DBaseDocument#getItemValueDateRange(java.lang.String)
503      */
504     public final DDateRange getItemValueDateRange(final String name) {
505         getFactory().preprocessMethod();
506         try {
507             Vector vector = ((Document) getNotesObject()).getItemValue(name);
508             if (vector == null || vector.size() == 0) {
509                 return null;
510             }
511             Calendar start = null;
512             Calendar end = null;
513             Object object = vector.get(0);
514             if (object instanceof DateRange) {
515                 start = createCalendar(((DateRange) object).getStartDateTime());
516                 end = createCalendar(((DateRange) object).getEndDateTime());
517             } else if (object instanceof DateTime) {
518                 start = createCalendar((DateTime) object);
519                 end = null;
520                 if (vector.size() > 1) {
521                     end = createCalendar((DateTime) vector.get(1));
522                 }
523             }
524             DDateRange range = null;
525             range = new GregorianDateTimeRange(start, end);
526             recycleDateTimeList(vector);
527             return range;
528         } catch (NotesException e) {
529             if (e.id == NotesError.NOTES_ERR_NOT_A_DATE_ITEM) {
530                 return null;
531             }
532             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.value.calendar.1", name), e);
533         }
534     }
535 
536     /***
537      * {@inheritDoc}
538      * @see de.bea.domingo.DBaseDocument#getItemValueInteger(java.lang.String)
539      */
540     public final Integer getItemValueInteger(final String name) {
541         getFactory().preprocessMethod();
542         try {
543             if (!getDocument().hasItem(name)) {
544                 return null;
545             }
546             final Item item = getDocument().getFirstItem(name);
547             if (item == null) {
548                 return null;
549             }
550             if (item.getType() == Item.NUMBERS) {
551                 final double value = getDocument().getItemValueDouble(name);
552                 return new Integer((int) Math.round(value));
553             } else if (item.getType() == Item.TEXT) {
554                 final String value = getDocument().getItemValueString(name);
555                 if (value == null || value.length() == 0) {
556                     return null;
557                 }
558                 try {
559                     return new Integer(value);
560                 } catch (NumberFormatException e) {
561                     getMonitor().warn(RESOURCES.getString("basedocument.cannot.parse.integer.1", value));
562                     return null;
563                 }
564             } else {
565                 return null;
566             }
567         } catch (NotesException e) {
568             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.value.integer.1", name), e);
569         }
570     }
571 
572     /***
573      * {@inheritDoc}
574      * @see de.bea.domingo.DBaseDocument#getItemValueDouble(java.lang.String)
575      */
576     public final Double getItemValueDouble(final String name) {
577         getFactory().preprocessMethod();
578         try {
579             if (!getDocument().hasItem(name)) {
580                 return null;
581             }
582             final Item item = getDocument().getFirstItem(name);
583             if (item == null) {
584                 return null;
585             }
586             if (item.getType() == Item.NUMBERS) {
587                 final double value = getDocument().getItemValueDouble(name);
588                 return new Double(value);
589             } else if (item.getType() == Item.TEXT) {
590                 final String value = getDocument().getItemValueString(name);
591                 if (value == null || value.length() == 0) {
592                     return null;
593                 }
594                 try {
595                     return new Double(value);
596                 } catch (NumberFormatException e) {
597                     getMonitor().warn(RESOURCES.getString("basedocument.cannot.parse.double.1", value));
598                     return null;
599                 }
600             } else {
601                 return null;
602             }
603         } catch (NotesException e) {
604             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.value.double.1", name), e);
605         }
606     }
607 
608     /***
609      * {@inheritDoc}
610      * @see de.bea.domingo.DBaseDocument#getAuthors()
611      */
612     public final List getAuthors() {
613         getFactory().preprocessMethod();
614         try {
615             Vector authors = getDocument().getAuthors();
616             return authors == null ? new ArrayList(0) : new ArrayList(authors);
617         } catch (NotesException e) {
618             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.authors"), e);
619         }
620     }
621 
622     /***
623      * {@inheritDoc}
624      * @see de.bea.domingo.DBaseDocument#getLastAccessed()
625      */
626     public final Calendar getLastAccessed() {
627         getFactory().preprocessMethod();
628         try {
629             final DateTime dateTime = getDocument().getLastAccessed();
630             if (dateTime != null) {
631                 final Calendar calendar = createCalendar(dateTime);
632                 getFactory().recycle(dateTime);
633                 return calendar;
634             }
635             return null;
636         } catch (NotesException e) {
637             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.lastaccessed"), e);
638         }
639     }
640 
641     /***
642      * Notes formula expression to evaluate the last modified date
643      * in a standard (local independent) string format.
644      */
645     private static final String MODIFIED_FORMULA = "_date := @Modified; "
646             + "@Text(@Year(_date)) + \"-\" + "
647             + "@Right(\"0\" + @Text(@Month(_date)); 2) + \"-\" + "
648             + "@Right(\"0\" + @Text(@Day(_date)); 2) + \" \" + "
649             + "@Right(\"0\" + @Text(@Hour(_date)); 2) + \":\" + "
650             + "@Right(\"0\" + @Text(@Minute(_date)); 2) + \":\" + "
651             + "@Right(\"0\" + @Text(@Second(_date)); 2)";
652 
653     /***
654      * {@inheritDoc}
655      * @see de.bea.domingo.DBaseDocument#getLastModified()
656      */
657     public final Calendar getLastModified() {
658         getFactory().preprocessMethod();
659         try {
660             final String temp = (String) this.getParentDatabase().getSession().evaluate(MODIFIED_FORMULA, this).get(0);
661             final Calendar lastModified = DateUtil.parseDate(temp, false);
662             return lastModified;
663         } catch (DNotesException e) {
664             getMonitor().warn("Cannot get last modified date; trying to get last modified in file.");
665             try {
666                 final DateTime dateTime = getDocument().getLastModified();
667                 if (dateTime != null) {
668                     final Calendar calendar = createCalendar(dateTime);
669                     getFactory().recycle(dateTime);
670                     return calendar;
671                 }
672             } catch (NotesException e1) {
673                 getMonitor().fatalError(RESOURCES.getString("basedocument.cannot.get.lastmodified"), e);
674             }
675         }
676         return null;
677     }
678 
679     /***
680      * {@inheritDoc}
681      * @see de.bea.domingo.DBaseDocument#getItems()
682      */
683     public final Iterator getItems() {
684         getFactory().preprocessMethod();
685         Vector items = null;
686         try {
687             items = getDocument().getItems();
688             return new ItemsIterator(items);
689         } catch (NotesException e) {
690             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.items"), e);
691         }
692     }
693 
694     /***
695      * {@inheritDoc}
696      * @see de.bea.domingo.DBaseDocument#appendItemValue(java.lang.String, java.util.List)
697      */
698     public final DItem appendItemValue(final String name, final List values) {
699         if (values == null) {
700             return replaceItemValue(name, EMPTY_STRING);
701         }
702         getFactory().preprocessMethod();
703         final List convertedKeys = convertCalendarsToNotesDateTime(values);
704         final Vector vector = convertListToVector(convertedKeys);
705         try {
706             final Item item = getDocument().appendItemValue(name, vector);
707             return (DItem) BaseItemProxy.getInstance(getFactory(), this, item, getMonitor());
708         } catch (NotesException e) {
709             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.append.value.list.1", name), e);
710         } finally {
711             recycleDateTimeList(convertedKeys);
712         }
713     }
714 
715     /***
716      * {@inheritDoc}
717      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, int)
718      */
719     public final DItem replaceItemValue(final String name, final int value) {
720         return replaceItemValue(name, new Integer(value));
721     }
722 
723     /***
724      * {@inheritDoc}
725      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.lang.Integer)
726      */
727     public final DItem replaceItemValue(final String name, final Integer value) {
728         if (value == null) {
729             return replaceItemValue(name, EMPTY_STRING);
730         }
731         getFactory().preprocessMethod();
732         try {
733             final Item notesItem;
734             notesItem = getDocument().replaceItemValue(name, value);
735             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
736         } catch (NotesException e) {
737             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.replace.value.list.1", name), e);
738         }
739     }
740 
741     /***
742      * {@inheritDoc}
743      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, double)
744      */
745     public final DItem replaceItemValue(final String name, final double value) {
746         return replaceItemValue(name, new Double(value));
747     }
748 
749     /***
750      * {@inheritDoc}
751      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.lang.Double)
752      */
753     public final DItem replaceItemValue(final String name, final Double value) {
754         if (value == null) {
755             return replaceItemValue(name, EMPTY_STRING);
756         }
757         getFactory().preprocessMethod();
758         try {
759             final Item notesItem = getDocument().replaceItemValue(name, value);
760             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
761         } catch (NotesException e) {
762             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.replace.value.double.1", name), e);
763         }
764     }
765 
766     /***
767      * {@inheritDoc}
768      * @see de.bea.domingo.DBaseDocument#appendItemValue(java.lang.String, java.lang.String)
769      */
770     public final DItem appendItemValue(final String name, final String value) {
771         if (value == null) {
772             return replaceItemValue(name, EMPTY_STRING);
773         }
774         getFactory().preprocessMethod();
775         try {
776             final Item notesItem = this.getDocument().appendItemValue(name, value);
777             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
778         } catch (NotesException e) {
779             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.append.value.string.1", name), e);
780         }
781     }
782 
783     /***
784      * {@inheritDoc}
785      * @see de.bea.domingo.DBaseDocument#appendItemValue(java.lang.String, java.util.Calendar)
786      */
787     public final DItem appendItemValue(final String name, final Calendar value) {
788         if (value == null) {
789             return appendItemValue(name, EMPTY_STRING);
790         }
791         Item notesItem;
792         try {
793             final DateTime dateTime = createDateTime(value);
794             notesItem = getDocument().appendItemValue(name, dateTime);
795             getFactory().recycle(dateTime);
796             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
797         } catch (NotesException e) {
798             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.append.value.calendar.1", name), e);
799         }
800     }
801 
802     /***
803      * {@inheritDoc}
804      * @see de.bea.domingo.DBaseDocument#replaceItemValue(java.lang.String, java.lang.String)
805      */
806     public final DItem replaceItemValue(final String name, final String value) {
807         if (value == null) {
808             return replaceItemValue(name, EMPTY_STRING);
809         }
810         try {
811             final Item notesItem = getDocument().replaceItemValue(name, value);
812             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
813         } catch (NotesException e) {
814             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.replace.value.string.1", name), e);
815         }
816     }
817 
818     /***
819      * {@inheritDoc}
820      * @see de.bea.domingo.DBaseDocument#getEmbeddedObjects()
821      */
822     public final Iterator getEmbeddedObjects() {
823         getFactory().preprocessMethod();
824         try {
825             final Vector vector = getDocument().getEmbeddedObjects();
826             final List list = new ArrayList();
827             for (final Iterator it = vector.iterator(); it.hasNext();) {
828                 final EmbeddedObject eo = (EmbeddedObject) it.next();
829                 final DEmbeddedObject deo = EmbeddedObjectProxy.getInstance(getFactory(), this, eo, getMonitor());
830                 list.add(deo);
831             }
832             return list.iterator();
833         } catch (NotesException e) {
834             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.embeddedobject"), e);
835         }
836     }
837 
838     /***
839      * {@inheritDoc}
840      * @see de.bea.domingo.DBaseDocument#getAttachments()
841      */
842     public final List getAttachments() {
843         getFactory().preprocessMethod();
844         List list = new ArrayList();
845         try {
846             if (getDocument().hasEmbedded()) {
847                 Iterator iterator = getDocument().getItems().iterator();
848                 while (iterator.hasNext()) {
849                     Item it = (Item) iterator.next();
850                     if (it.getType() == Item.ATTACHMENT) {
851                         list.add(getDocument().getAttachment(it.getValueString()).getName());
852                     }
853                 }
854             }
855         } catch (NotesException e) {
856             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.attachments"), e);
857         }
858         return list;
859     }
860 
861     /***
862      * {@inheritDoc}
863      * @see de.bea.domingo.DBaseDocument#getItemValueSize(java.lang.String)
864      */
865     public final int getItemValueSize(final String name) {
866         getFactory().preprocessMethod();
867         try {
868             return ((Document) getNotesObject()).getFirstItem(name).getValues().size();
869         } catch (NotesException e) {
870             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.valuesize.1", name), e);
871         }
872     }
873 
874 
875     /***
876      * {@inheritDoc}
877      * @see de.bea.domingo.DBaseDocument#copyAllItems(de.bea.domingo.DBaseDocument, boolean)
878      */
879     public final void copyAllItems(final DBaseDocument doc, final boolean replace) {
880         if (!(doc instanceof BaseProxy)) {
881             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.copy.allitems"), new ClassCastException(doc.getClass().getName()));
882         }
883         getFactory().preprocessMethod();
884         try {
885             final Base notesDoc = ((BaseProxy) doc).getNotesObject();
886             ((Document) getNotesObject()).copyAllItems((Document) notesDoc, replace);
887         } catch (NotesException e) {
888             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.copy.allitems"), e);
889         }
890     }
891 
892     /***
893      * {@inheritDoc}
894      * @see de.bea.domingo.DBaseDocument#computeWithForm(boolean)
895      */
896     public final boolean computeWithForm(final boolean raiseError) {
897         getFactory().preprocessMethod();
898         try {
899             return ((Document) getNotesObject()).computeWithForm(true, raiseError);
900         } catch (NotesException e) {
901             throw newRuntimeException("Cannot copy all items", e);
902         }
903     }
904 
905     /***
906      * {@inheritDoc}
907      * @see de.bea.domingo.DBaseDocument#copyItem(de.bea.domingo.DBaseItem, java.lang.String)
908      */
909     public final DBaseItem copyItem(final DBaseItem item, final String s) {
910         getFactory().preprocessMethod();
911         if (!(item instanceof ItemProxy)) {
912             throw newRuntimeException("invalid item");
913         }
914         try {
915             final Item notesItem = (Item) ((BaseProxy) item).getNotesObject();
916             final Item newItem = ((Document) getNotesObject()).copyItem(notesItem, s);
917             return (DItem) BaseItemProxy.getInstance(getFactory(), this, newItem, getMonitor());
918         } catch (NotesException e) {
919             throw newRuntimeException("Cannot copy item", e);
920         }
921     }
922 
923     /***
924      * {@inheritDoc}
925      * @see de.bea.domingo.DBaseDocument#copyItem(de.bea.domingo.DBaseItem)
926      */
927     public final DBaseItem copyItem(final DBaseItem item) {
928         getFactory().preprocessMethod();
929         try {
930             final Item notesItem = (Item) ((BaseProxy) item).getNotesObject();
931             final Item newItem = ((Document) getNotesObject()).copyItem(notesItem);
932             return (DItem) BaseItemProxy.getInstance(getFactory(), this, newItem, getMonitor());
933         } catch (NotesException e) {
934             throw newRuntimeException("Cannot copy item", e);
935         }
936     }
937 
938     /***
939      * {@inheritDoc}
940      * @see de.bea.domingo.DBaseDocument#createReplyMessage(boolean)
941      */
942     public final DDocument createReplyMessage(final boolean flag) {
943         getFactory().preprocessMethod();
944         try {
945             Document document = ((Document) getNotesObject()).createReplyMessage(flag);
946             return (DDocument) BaseDocumentProxy.getInstance(getFactory(), this, document, getMonitor());
947         } catch (NotesException e) {
948             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.create.reply"), e);
949         }
950     }
951 
952     /***
953      * {@inheritDoc}
954      * @see de.bea.domingo.DBaseDocument#encrypt()
955      */
956     public final void encrypt() {
957         getFactory().preprocessMethod();
958         try {
959              ((Document) getNotesObject()).encrypt();
960         } catch (NotesException e) {
961             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.encrypt.document"), e);
962         }
963     }
964 
965     /***
966      * {@inheritDoc}
967      * @see de.bea.domingo.DBaseDocument#generateXML()
968      */
969     public final String generateXML() {
970         getFactory().preprocessMethod();
971         try {
972             return ((Document) getNotesObject()).generateXML();
973         } catch (NotesException e) {
974             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.generate.xml"), e);
975         }
976     }
977 
978     /***
979      * {@inheritDoc}
980      * @see de.bea.domingo.DBaseDocument#generateXML(java.io.Writer)
981      */
982     public final void generateXML(final Writer writer) {
983         getFactory().preprocessMethod();
984         try {
985             ((Document) getNotesObject()).generateXML(writer);
986         } catch (NotesException e) {
987             throw newRuntimeException("Cannot generate XML", e);
988         } catch (IOException e) {
989             throw newRuntimeException("Cannot generate XML", e);
990         }
991     }
992 
993     /***
994      * {@inheritDoc}
995      * @see de.bea.domingo.DBaseDocument#getColumnValues()
996      */
997     public final List getColumnValues() {
998         getFactory().preprocessMethod();
999         try {
1000             final Vector vector = ((Document) getNotesObject()).getColumnValues();
1001             final List convertedValues = convertNotesDateTimesToCalendar(vector);
1002             recycleDateTimeList(vector);
1003             return Collections.unmodifiableList(convertedValues);
1004         } catch (NotesException e) {
1005             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.columnvalues"), e);
1006         }
1007     }
1008 
1009     /***
1010      * {@inheritDoc}
1011      * @see de.bea.domingo.DBaseDocument#getEncryptionKeys()
1012      */
1013     public final List getEncryptionKeys() {
1014         getFactory().preprocessMethod();
1015         try {
1016             return ((Document) getNotesObject()).getEncryptionKeys();
1017         } catch (NotesException e) {
1018             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.encryptionkeys"), e);
1019         }
1020     }
1021 
1022     /***
1023      * {@inheritDoc}
1024      * @see de.bea.domingo.DBaseDocument#getItemValueCustomData(java.lang.String, java.lang.String)
1025      */
1026     public final Object getItemValueCustomData(final String name, final String s1) {
1027         getFactory().preprocessMethod();
1028         try {
1029             return ((Document) getNotesObject()).getItemValueCustomData(name, s1);
1030         } catch (NotesException e) {
1031             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.customdata"), e);
1032         } catch (IOException e) {
1033             throw newRuntimeException("Cannot get custom data", e);
1034         } catch (ClassNotFoundException e) {
1035             throw newRuntimeException("Cannot get custom data", e);
1036         }
1037     }
1038 
1039     /***
1040      * {@inheritDoc}
1041      * @see de.bea.domingo.DBaseDocument#getItemValueCustomData(java.lang.String)
1042      */
1043     public final Object getItemValueCustomData(final String name) {
1044         getFactory().preprocessMethod();
1045         try {
1046             return ((Document) getNotesObject()).getItemValueCustomData(name);
1047         } catch (NotesException e) {
1048             throw newRuntimeException("Cannot get custom data", e);
1049         } catch (IOException e) {
1050             throw newRuntimeException("Cannot get custom data", e);
1051         } catch (ClassNotFoundException e) {
1052             throw newRuntimeException("Cannot get custom data", e);
1053         }
1054     }
1055 
1056     /***
1057      * {@inheritDoc}
1058      * @see de.bea.domingo.DBaseDocument#getItemValueCustomDataBytes(java.lang.String, java.lang.String)
1059      */
1060     public final byte[] getItemValueCustomDataBytes(final String name, final String s1) {
1061         getFactory().preprocessMethod();
1062         try {
1063             return ((Document) getNotesObject()).getItemValueCustomDataBytes(name, s1);
1064         } catch (NotesException e) {
1065             throw newRuntimeException("Cannot get custom data", e);
1066         } catch (IOException e) {
1067             throw newRuntimeException("Cannot get custom data", e);
1068         }
1069     }
1070 
1071     /***
1072      * {@inheritDoc}
1073      * @see de.bea.domingo.DBaseDocument#getItemValueDateTimeArray(java.lang.String)
1074      */
1075     public final List getItemValueDateTimeArray(final String name) {
1076         getFactory().preprocessMethod();
1077         try {
1078             Vector vector = ((Document) getNotesObject()).getItemValueDateTimeArray(name);
1079             final List convertedValues = convertNotesDateTimesToCalendar(vector);
1080             recycleDateTimeList(vector);
1081             return Collections.unmodifiableList(convertedValues);
1082         } catch (NotesException e) {
1083             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.datetimearray"), e);
1084         }
1085     }
1086 
1087     /***
1088      * {@inheritDoc}
1089      * @see de.bea.domingo.DBaseDocument#getLockHolders()
1090      */
1091     public final List getLockHolders() {
1092         getFactory().preprocessMethod();
1093         try {
1094             return ((Document) getNotesObject()).getLockHolders();
1095         } catch (NotesException e) {
1096             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.lockholders"), e);
1097         }
1098     }
1099 
1100     /***
1101      * {@inheritDoc}
1102      * @see de.bea.domingo.DBaseDocument#getReceivedItemText()
1103      */
1104     public final List getReceivedItemText() {
1105         getFactory().preprocessMethod();
1106         try {
1107             return ((Document) getNotesObject()).getReceivedItemText();
1108         } catch (NotesException e) {
1109             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.receiveditemtext"), e);
1110         }
1111     }
1112 
1113     /***
1114      * {@inheritDoc}
1115      * @see de.bea.domingo.DBaseDocument#getSigner()
1116      */
1117     public final String getSigner() {
1118         getFactory().preprocessMethod();
1119         try {
1120             return ((Document) getNotesObject()).getSigner();
1121         } catch (NotesException e) {
1122             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.signer"), e);
1123         }
1124     }
1125 
1126     /***
1127      * {@inheritDoc}
1128      * @see de.bea.domingo.DBaseDocument#getSize()
1129      */
1130     public final int getSize() {
1131         getFactory().preprocessMethod();
1132         try {
1133             return ((Document) getNotesObject()).getSize();
1134         } catch (NotesException e) {
1135             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.size"), e);
1136         }
1137     }
1138 
1139     /***
1140      * {@inheritDoc}
1141      * @see de.bea.domingo.DBaseDocument#getVerifier()
1142      */
1143     public final String getVerifier() {
1144         getFactory().preprocessMethod();
1145         try {
1146             return ((Document) getNotesObject()).getVerifier();
1147         } catch (NotesException e) {
1148             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.get.verifier"), e);
1149         }
1150     }
1151 
1152     /***
1153      * {@inheritDoc}
1154      * @see de.bea.domingo.DBaseDocument#hasEmbedded()
1155      */
1156     public final boolean hasEmbedded() {
1157         getFactory().preprocessMethod();
1158         try {
1159             return ((Document) getNotesObject()).hasEmbedded();
1160         } catch (NotesException e) {
1161             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.embedded"), e);
1162         }
1163     }
1164 
1165     /***
1166      * {@inheritDoc}
1167      * @see de.bea.domingo.DBaseDocument#isDeleted()
1168      */
1169     public final boolean isDeleted() {
1170         getFactory().preprocessMethod();
1171         try {
1172             return ((Document) getNotesObject()).isDeleted();
1173         } catch (NotesException e) {
1174             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.deleted"), e);
1175         }
1176     }
1177 
1178     /***
1179      * {@inheritDoc}
1180      * @see de.bea.domingo.DBaseDocument#isEncrypted()
1181      */
1182     public final boolean isEncrypted() {
1183         getFactory().preprocessMethod();
1184         try {
1185             return ((Document) getNotesObject()).isEncrypted();
1186         } catch (NotesException e) {
1187             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.encrypted"), e);
1188         }
1189     }
1190 
1191     /***
1192      * {@inheritDoc}
1193      * @see de.bea.domingo.DBaseDocument#isEncryptOnSend()
1194      */
1195     public final boolean isEncryptOnSend() {
1196         getFactory().preprocessMethod();
1197         try {
1198             return ((Document) getNotesObject()).isEncryptOnSend();
1199         } catch (NotesException e) {
1200             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.shouldbe.encrypted"), e);
1201         }
1202     }
1203 
1204     /***
1205      * {@inheritDoc}
1206      * @see de.bea.domingo.DBaseDocument#isProfile()
1207      */
1208     public final boolean isProfile() {
1209         return this instanceof DProfileDocument;
1210     }
1211 
1212     /***
1213      * {@inheritDoc}
1214      * @see de.bea.domingo.DBaseDocument#isSaveMessageOnSend()
1215      */
1216     public final boolean isSaveMessageOnSend() {
1217         getFactory().preprocessMethod();
1218         try {
1219             return ((Document) getNotesObject()).isSaveMessageOnSend();
1220         } catch (NotesException e) {
1221             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.shouldbe.savedonsend"), e);
1222         }
1223     }
1224 
1225     /***
1226      * {@inheritDoc}
1227      * @see de.bea.domingo.DBaseDocument#isSentByAgent()
1228      */
1229     public final boolean isSentByAgent() {
1230         getFactory().preprocessMethod();
1231         try {
1232             return ((Document) getNotesObject()).isSentByAgent();
1233         } catch (NotesException e) {
1234             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.sentbyagent"), e);
1235         }
1236     }
1237 
1238     /***
1239      * {@inheritDoc}
1240      * @see de.bea.domingo.DBaseDocument#isSigned()
1241      */
1242     public final boolean isSigned() {
1243         getFactory().preprocessMethod();
1244         try {
1245             return ((Document) getNotesObject()).isSigned();
1246         } catch (NotesException e) {
1247             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.signed"), e);
1248         }
1249     }
1250 
1251     /***
1252      * {@inheritDoc}
1253      * @see de.bea.domingo.DBaseDocument#isSignOnSend()
1254      */
1255     public final boolean isSignOnSend() {
1256         getFactory().preprocessMethod();
1257         try {
1258             return ((Document) getNotesObject()).isSignOnSend();
1259         } catch (NotesException e) {
1260             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.shouldbe.signedonsend"), e);
1261         }
1262     }
1263 
1264     /***
1265      * {@inheritDoc}
1266      * @see de.bea.domingo.DBaseDocument#isValid()
1267      */
1268     public final boolean isValid() {
1269         getFactory().preprocessMethod();
1270         try {
1271             return ((Document) getNotesObject()).isValid();
1272         } catch (NotesException e) {
1273             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.check.valid"), e);
1274         }
1275     }
1276 
1277     /***
1278      * {@inheritDoc}
1279      * @see de.bea.domingo.DBaseDocument#lock()
1280      */
1281     public final boolean lock() {
1282         getFactory().preprocessMethod();
1283         try {
1284             return ((Document) getNotesObject()).lock();
1285         } catch (NotesException e) {
1286             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.lock"), e);
1287         }
1288     }
1289 
1290     /***
1291      * {@inheritDoc}
1292      * @see de.bea.domingo.DBaseDocument#lock(boolean)
1293      */
1294     public final boolean lock(final boolean provisionalOk) {
1295         getFactory().preprocessMethod();
1296         try {
1297             return ((Document) getNotesObject()).lock(provisionalOk);
1298         } catch (NotesException e) {
1299             throw newRuntimeException("Cannot lock", e);
1300         }
1301     }
1302 
1303     /***
1304      * {@inheritDoc}
1305      * @see de.bea.domingo.DBaseDocument#lock(java.util.List, boolean)
1306      */
1307     public final boolean lock(final List names, final boolean provisionalOk) {
1308         getFactory().preprocessMethod();
1309         try {
1310             return ((Document) getNotesObject()).lock(convertListToVector(names), provisionalOk);
1311         } catch (NotesException e) {
1312             throw newRuntimeException("Cannot lock", e);
1313         }
1314     }
1315 
1316     /***
1317      * {@inheritDoc}
1318      * @see de.bea.domingo.DBaseDocument#lock(java.util.List)
1319      */
1320     public final boolean lock(final List names) {
1321         getFactory().preprocessMethod();
1322         try {
1323             return ((Document) getNotesObject()).lock(convertListToVector(names));
1324         } catch (NotesException e) {
1325             throw newRuntimeException("Cannot lock", e);
1326         }
1327     }
1328 
1329     /***
1330      * {@inheritDoc}
1331      * @see de.bea.domingo.DBaseDocument#lock(java.lang.String, boolean)
1332      */
1333     public final boolean lock(final String name, final boolean provisionalOk) {
1334         getFactory().preprocessMethod();
1335         try {
1336             return ((Document) getNotesObject()).lock(name, provisionalOk);
1337         } catch (NotesException e) {
1338             throw newRuntimeException("Cannot lock", e);
1339         }
1340     }
1341 
1342     /***
1343      * {@inheritDoc}
1344      * @see de.bea.domingo.DBaseDocument#lock(java.lang.String)
1345      */
1346     public final boolean lock(final String name) {
1347         getFactory().preprocessMethod();
1348         try {
1349             return ((Document) getNotesObject()).lock(name);
1350         } catch (NotesException e) {
1351             throw newRuntimeException("Cannot lock", e);
1352         }
1353     }
1354 
1355     /***
1356      * {@inheritDoc}
1357      * @see de.bea.domingo.DBaseDocument#lockProvisional()
1358      */
1359     public final boolean lockProvisional() {
1360         getFactory().preprocessMethod();
1361         try {
1362             return ((Document) getNotesObject()).lockProvisional();
1363         } catch (NotesException e) {
1364             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.lock.provisional"), e);
1365         }
1366     }
1367 
1368     /***
1369      * {@inheritDoc}
1370      * @see de.bea.domingo.DBaseDocument#lockProvisional(java.util.List)
1371      */
1372     public final boolean lockProvisional(final List names) {
1373         getFactory().preprocessMethod();
1374         try {
1375             return ((Document) getNotesObject()).lockProvisional(convertListToVector(names));
1376         } catch (NotesException e) {
1377             throw newRuntimeException("Cannot lock provisional", e);
1378         }
1379     }
1380 
1381     /***
1382      * {@inheritDoc}
1383      * @see de.bea.domingo.DBaseDocument#lockProvisional(java.lang.String)
1384      */
1385     public final boolean lockProvisional(final String name) {
1386         getFactory().preprocessMethod();
1387         try {
1388             return ((Document) getNotesObject()).lockProvisional(name);
1389         } catch (NotesException e) {
1390             throw newRuntimeException("Cannot lock provisional", e);
1391         }
1392     }
1393 
1394     /***
1395      * {@inheritDoc}
1396      * @see de.bea.domingo.DBaseDocument#removePermanently(boolean)
1397      */
1398     public final boolean removePermanently(final boolean force) {
1399         getFactory().preprocessMethod();
1400         try {
1401             return ((Document) getNotesObject()).removePermanently(force);
1402         } catch (NotesException e) {
1403             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.remove.permanently"), e);
1404         }
1405     }
1406 
1407     /***
1408      * {@inheritDoc}
1409      * @see de.bea.domingo.DBaseDocument#renderToRTItem(de.bea.domingo.DRichTextItem)
1410      */
1411     public final boolean renderToRTItem(final DRichTextItem richTextItem) {
1412         getFactory().preprocessMethod();
1413         try {
1414             final RichTextItem rtItem = (RichTextItem) ((RichTextItemProxy) richTextItem).getNotesObject();
1415             return ((Document) getNotesObject()).renderToRTItem(rtItem);
1416         } catch (NotesException e) {
1417             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.render.rti"), e);
1418         }
1419     }
1420 
1421     /***
1422      * {@inheritDoc}
1423      * @see de.bea.domingo.DBaseDocument#replaceItemValueCustomData(java.lang.String, java.lang.Object)
1424      */
1425     public final DItem replaceItemValueCustomData(final String name, final Object obj) {
1426         getFactory().preprocessMethod();
1427         try {
1428             final Item notesItem = ((Document) getNotesObject()).replaceItemValueCustomData(name, obj);
1429             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
1430         } catch (NotesException e) {
1431             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.replce.value.customdata"), e);
1432         } catch (IOException e) {
1433             throw newRuntimeException("Cannot replace item values custom data", e);
1434         }
1435     }
1436 
1437     /***
1438      * {@inheritDoc}
1439      * @see de.bea.domingo.DBaseDocument#replaceItemValueCustomData(java.lang.String, java.lang.String, java.lang.Object)
1440      */
1441     public final DItem replaceItemValueCustomData(final String name, final String type, final Object obj) {
1442         getFactory().preprocessMethod();
1443         try {
1444             final Item notesItem = ((Document) getNotesObject()).replaceItemValueCustomData(name, type, obj);
1445             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
1446         } catch (NotesException e) {
1447             throw newRuntimeException("Cannot replace item values custom data", e);
1448         } catch (IOException e) {
1449             throw newRuntimeException("Cannot replace item values custom data", e);
1450         }
1451     }
1452 
1453     /***
1454      * {@inheritDoc}
1455      * @see de.bea.domingo.DBaseDocument#replaceItemValueCustomDataBytes(java.lang.String, java.lang.String, byte[])
1456      */
1457     public final DItem replaceItemValueCustomDataBytes(final String s, final String s1, final byte[] abyte0) {
1458         getFactory().preprocessMethod();
1459         try {
1460             final Item notesItem = ((Document) getNotesObject()).replaceItemValueCustomDataBytes(s, s1, abyte0);
1461             return (DItem) BaseItemProxy.getInstance(getFactory(), this, notesItem, getMonitor());
1462         } catch (NotesException e) {
1463             throw newRuntimeException("Cannot replace item values custom data", e);
1464         } catch (IOException e) {
1465             throw newRuntimeException("Cannot replace item values custom data", e);
1466         }
1467     }
1468 
1469     /***
1470      * {@inheritDoc}
1471      * @see de.bea.domingo.DBaseDocument#setEncryptionKeys(java.util.List)
1472      */
1473     public final void setEncryptionKeys(final List keys) {
1474         getFactory().preprocessMethod();
1475         try {
1476             ((Document) getNotesObject()).setEncryptionKeys(convertListToVector(keys));
1477         } catch (NotesException e) {
1478             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.set.encryptionkeys"), e);
1479         }
1480     }
1481 
1482     /***
1483      * {@inheritDoc}
1484      * @see de.bea.domingo.DBaseDocument#setUniversalID(java.lang.String)
1485      */
1486     public final void setUniversalID(final String unid) {
1487         getFactory().preprocessMethod();
1488         try {
1489             ((Document) getNotesObject()).setUniversalID(unid);
1490         } catch (NotesException e) {
1491             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.set.universalid"), e);
1492         }
1493     }
1494 
1495     /***
1496      * {@inheritDoc}
1497      * @see de.bea.domingo.DBaseDocument#unlock()
1498      */
1499     public final void unlock() {
1500         getFactory().preprocessMethod();
1501         try {
1502             ((Document) getNotesObject()).unlock();
1503         } catch (NotesException e) {
1504             throw newRuntimeException(RESOURCES.getString("basedocument.cannot.unlock"), e);
1505         }
1506     }
1507 
1508     /***
1509      * {@inheritDoc}
1510      * @see de.bea.domingo.DBaseDocument#computeWithForm()
1511      */
1512     public final boolean computeWithForm() {
1513         return computeWithForm(true);
1514     }
1515 
1516     ////////////////////////////////////////////////
1517     //    Iterator classes
1518     ////////////////////////////////////////////////
1519 
1520     /***
1521      * A <code>ItemsIterator</code> allows iteration over a set of
1522      * <code>lotus.domino.Item</code>.
1523      *
1524      * #see getItems
1525      *
1526      * @author MarcusT
1527      */
1528     protected final class ItemsIterator implements Iterator {
1529 
1530         /*** The iterator of the notes items.*/
1531         private final Iterator items;
1532 
1533         /***
1534          * Constructs an Iterator by use of a vector of
1535          * <code>lotus.domino.Item</code>s.
1536          *
1537          * @param itemsVector a vector of <code>lotus.domino.Item</code>s
1538          */
1539         protected ItemsIterator(final Vector itemsVector) {
1540             this.items = itemsVector.iterator();
1541         }
1542 
1543         /***
1544          * Indicates whether this iterator has a next element or not.
1545          *
1546          * @return boolean true if there is a next
1547          */
1548         public boolean hasNext() {
1549             return items.hasNext();
1550         }
1551 
1552         /***
1553          * Returns the next element of this iterator (hasNext()==true)
1554          * or <code>null</code> if hasNext()==false.
1555          *
1556          * @return an <code>DItem</code>
1557          */
1558         public Object next() {
1559             final Item notesItem = (Item) items.next();
1560             final DBaseItem proxy = BaseItemProxy.getInstance(getFactory(),
1561                     BaseDocumentProxy.this, notesItem, getMonitor());
1562             return proxy;
1563         }
1564 
1565         /***
1566          * Throws an UnsupportedOperationException: The <tt>remove</tt>
1567          * operation is not supported by this Iterator.
1568          */
1569         public void remove() {
1570             throw new UnsupportedOperationException();
1571         }
1572     }
1573 
1574     /***
1575      * @see de.bea.domingo.DBaseDocument#recycle()
1576      */
1577     public final void recycle() {
1578         getFactory().recycle(this);
1579         clearNotesObject();
1580     }
1581 }