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.EmbeddedObject;
26  import lotus.domino.NotesException;
27  import de.bea.domingo.DBase;
28  import de.bea.domingo.DEmbeddedObject;
29  import de.bea.domingo.DNotesMonitor;
30  
31  /***
32   * This class represents the Domino-Class <code>EmbeddedObject</code>.
33   *
34   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
35   */
36  public final class EmbeddedObjectProxy extends BaseProxy implements DEmbeddedObject {
37  
38      /*** serial version ID for serialization. */
39      private static final long serialVersionUID = 3545519508262432819L;
40  
41      /***
42       * Constructor for DEmbeddedObjectImpl.
43       *
44       * @param theFactory the controlling factory
45       * @param parent the parent object (mostly a Document or a RichTextItem)
46       * @param embeddedObject the notes object to attach
47       * @param monitor the monitor
48       */
49      private EmbeddedObjectProxy(final NotesProxyFactory theFactory, final DBase parent,
50                                  final EmbeddedObject embeddedObject, final DNotesMonitor monitor) {
51          super(theFactory, parent, embeddedObject, monitor);
52      }
53  
54      /***
55       * Creates a new DEmbeddedObject and enables logging.
56       *
57       * @param theFactory the controlling factory
58       * @param parent the objects parent
59       * @param embeddedObject the corresponding notes object
60       * @param monitor the monitor
61       * @return a new DEmbeddedObject
62       */
63      static DEmbeddedObject getInstance(final NotesProxyFactory theFactory, final DBase parent,
64                                         final EmbeddedObject embeddedObject, final DNotesMonitor monitor) {
65          if (embeddedObject == null) {
66              return null;
67          }
68          EmbeddedObjectProxy embeddedObjectProxy = (EmbeddedObjectProxy) theFactory.getBaseCache().get(embeddedObject);
69          if (embeddedObjectProxy == null) {
70              embeddedObjectProxy = new EmbeddedObjectProxy(theFactory, parent, embeddedObject, monitor);
71              theFactory.getBaseCache().put(embeddedObject, embeddedObjectProxy);
72          }
73          return embeddedObjectProxy;
74      }
75  
76      /***
77       * Returns the associated notes document embedded object object.
78       *
79       * @return notes database object
80       */
81      private EmbeddedObject getEmbeddedObject() {
82          return (EmbeddedObject) getNotesObject();
83      }
84  
85      /***
86       * {@inheritDoc}
87       * @see de.bea.domingo.DEmbeddedObject#extractFile(String)
88       */
89      public void extractFile(final String path) {
90          getFactory().preprocessMethod();
91          try {
92              getEmbeddedObject().extractFile(path);
93          } catch (NotesException e) {
94              throw newRuntimeException("Cannot extract file " + path, e);
95          }
96      }
97  
98      /***
99       * {@inheritDoc}
100      * @see de.bea.domingo.DEmbeddedObject#getName()
101      */
102     public String getName() {
103         try {
104             return getEmbeddedObject().getName();
105         } catch (NotesException e) {
106             throw newRuntimeException("Cannot get name", e);
107         }
108     }
109 
110     /***
111      * @see de.bea.domingo.DEmbeddedObject#remove()
112      */
113     public void remove() {
114         getFactory().preprocessMethod();
115         try {
116             getEmbeddedObject().remove();
117         } catch (NotesException e) {
118             throw newRuntimeException("Cannot remove embedded object", e);
119         }
120     }
121 
122     /***
123      * @see de.bea.domingo.proxy.BaseProxy#toString()
124      * @return the name of the embedded object
125      */
126     public String toString() {
127         return getName();
128     }
129 
130     /***
131      * {@inheritDoc}
132      * @see de.bea.domingo.DEmbeddedObject#getSource()
133      */
134     public String getSource() {
135         try {
136             return getEmbeddedObject().getSource();
137         } catch (NotesException e) {
138             throw newRuntimeException("Cannot get source", e);
139         }
140     }
141 
142     /***
143      * {@inheritDoc}
144      * @see de.bea.domingo.DEmbeddedObject#getType()
145      */
146     public int getType() {
147         try {
148             return getEmbeddedObject().getType();
149         } catch (NotesException e) {
150             throw newRuntimeException("Cannot get type", e);
151         }
152     }
153 }