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 lotus.domino.Item;
26  import lotus.domino.NotesException;
27  import lotus.domino.RichTextItem;
28  import de.bea.domingo.DBase;
29  import de.bea.domingo.DBaseItem;
30  import de.bea.domingo.DNotesMonitor;
31  
32  /***
33   * This class represents the Domino-Class <code>Item</code>.
34   */
35  public abstract class BaseItemProxy extends BaseProxy implements DBaseItem {
36  
37      /***
38       * Constructor for DItemImpl.
39       *
40       * @param theFactory the controlling factory
41       * @param parent the parent object
42       * @param item the Notes item object
43       * @param monitor the monitor
44       */
45      protected BaseItemProxy(final NotesProxyFactory theFactory, final DBase parent,
46                              final Item item, final DNotesMonitor monitor) {
47          super(theFactory, parent, item, monitor);
48      }
49  
50      /***
51       * Creates or returns a cached implementation of the requested item
52       * interface.
53       *
54       * @param theFactory the controlling factory
55       * @param parent the parent object
56       * @param item the associated Notes Item
57       * @param monitor the monitor
58       *
59       * @return implementation of interface DBaseItem or null
60       */
61      static BaseItemProxy getInstance(final NotesProxyFactory theFactory, final DBase parent,
62                                       final Item item, final DNotesMonitor monitor) {
63          if (item == null) {
64              return null;
65          }
66          BaseItemProxy itemProxy = (BaseItemProxy) theFactory.getBaseCache().get(item);
67          if (itemProxy == null) {
68              if (item instanceof RichTextItem) {
69                  itemProxy = new RichTextItemProxy(theFactory, parent, (RichTextItem) item, monitor);
70              } else {
71                  itemProxy = new ItemProxy(theFactory, parent, item, monitor);
72              }
73              itemProxy.setMonitor(monitor);
74              theFactory.getBaseCache().put(item, itemProxy);
75          }
76          return itemProxy;
77      }
78  
79      /***
80       * Returns the associated notes item object.
81       *
82       * @return notes item object
83       */
84      protected final Item getItem() {
85          return (Item) getNotesObject();
86      }
87  
88      /***
89       * {@inheritDoc}
90       * @see de.bea.domingo.DBaseItem#getName()
91       */
92      public final String getName() {
93          getFactory().preprocessMethod();
94          try {
95              return getItem().getName();
96          } catch (NotesException e) {
97              throw newRuntimeException("Cannot get name", e);
98          }
99      }
100 
101     /***
102      * {@inheritDoc}
103      * @see de.bea.domingo.DBaseItem#remove()
104      */
105     public final void remove() {
106         getFactory().preprocessMethod();
107         try {
108             getItem().remove();
109         } catch (NotesException e) {
110             throw newRuntimeException("Cannot remove item", e);
111         }
112     }
113 
114     /***
115      * @see de.bea.domingo.proxy.BaseProxy#toString()
116      * @return the name of the item
117      */
118     public final String toString() {
119         return getName();
120     }
121 }