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  package de.bea.domingo.proxy;
23  
24  import java.util.List;
25  
26  import lotus.domino.Form;
27  import lotus.domino.NotesException;
28  import de.bea.domingo.DDatabase;
29  import de.bea.domingo.DForm;
30  import de.bea.domingo.DNotesMonitor;
31  
32  /***
33   * A notes Form.
34   *
35   * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
36   */
37  public final class FormProxy extends BaseProxy implements DForm {
38  
39      /*** serial version ID for serialization. */
40      private static final long serialVersionUID = 6895768801526231827L;
41  
42      /*** The name of the view for fast access. */
43      private String fName = null;
44  
45      /***
46       * Constructor for DFormProxy.
47       *
48       * @param theFactory the controlling factory
49       * @param database Notes database
50       * @param form the Notes Form
51       * @param monitor the monitor
52       */
53      private FormProxy(final NotesProxyFactory theFactory, final DDatabase database,
54                        final Form form, final DNotesMonitor monitor) {
55          super(theFactory, database, form, monitor);
56          fName = getNameIntern();
57      }
58  
59      /***
60       * Returns a form object.
61       *
62       * @param theFactory the controlling factory
63       * @param database Notes database
64       * @param form the notes form object
65       * @param monitor the monitor
66       * @return a view object
67       */
68      static FormProxy getInstance(final NotesProxyFactory theFactory, final DDatabase database,
69                                   final Form form, final DNotesMonitor monitor) {
70          if (form == null) {
71              return null;
72          }
73          FormProxy formProxy = (FormProxy) theFactory.getBaseCache().get(form);
74          if (formProxy == null) {
75              formProxy = new FormProxy(theFactory, database, form, monitor);
76              formProxy.setMonitor(monitor);
77              theFactory.getBaseCache().put(form, formProxy);
78          }
79          return formProxy;
80      }
81  
82      /***
83       * Returns the associated Notes form.
84       *
85       * @return associated Notes form
86       */
87      private Form getForm() {
88          return (Form) getNotesObject();
89      }
90  
91      /***
92       * {@inheritDoc}
93       * @see de.bea.domingo.proxy.BaseProxy#toString()
94       */
95      public String toString() {
96          return fName;
97      }
98  
99      /***
100      * {@inheritDoc}
101      * @see de.bea.domingo.DForm#getAliases()
102      */
103     public List getAliases() {
104         getFactory().preprocessMethod();
105         try {
106             return getForm().getAliases();
107         } catch (NotesException e) {
108             throw newRuntimeException("Cannot get aliases", e);
109         }
110     }
111 
112     /***
113      * {@inheritDoc}
114      * @see de.bea.domingo.DForm#getFieldType(java.lang.String)
115      */
116     public int getFieldType(final String fieldName) {
117         getFactory().preprocessMethod();
118         try {
119             return getForm().getFieldType(fieldName);
120         } catch (NotesException e) {
121             throw newRuntimeException("Cannot get field name", e);
122         }
123     }
124 
125     /***
126      * {@inheritDoc}
127      * @see de.bea.domingo.DForm#getFields()
128      */
129     public List getFields() {
130         getFactory().preprocessMethod();
131         try {
132             return getForm().getFields();
133         } catch (NotesException e) {
134             throw newRuntimeException("Cannot get fields", e);
135         }
136     }
137 
138     /***
139      * {@inheritDoc}
140      * @see de.bea.domingo.DForm#getFormUsers()
141      */
142     public List getFormUsers() {
143         getFactory().preprocessMethod();
144         try {
145             return getForm().getFormUsers();
146         } catch (NotesException e) {
147             throw newRuntimeException("Cannot get form users", e);
148         }
149     }
150 
151     /***
152      * {@inheritDoc}
153      * @see de.bea.domingo.DForm#getHttpURL()
154      */
155     public String getHttpURL() {
156         getFactory().preprocessMethod();
157         try {
158             return getForm().getHttpURL();
159         } catch (NotesException e) {
160             throw newRuntimeException("Cannot get Http URL", e);
161         }
162     }
163 
164     /***
165      * {@inheritDoc}
166      * @see de.bea.domingo.DForm#getLockHolders()
167      */
168     public List getLockHolders() {
169         getFactory().preprocessMethod();
170         try {
171             return getForm().getLockHolders();
172         } catch (NotesException e) {
173             throw newRuntimeException("Cannot get lock holders", e);
174         }
175     }
176 
177     /***
178      * {@inheritDoc}
179      * @see de.bea.domingo.DForm#getName()
180      */
181     public String getName() {
182         return fName;
183     }
184 
185     /***
186      * {@inheritDoc}
187      * @see de.bea.domingo.DForm#getNotesURL()
188      */
189     public String getNotesURL() {
190         getFactory().preprocessMethod();
191         try {
192             return getForm().getNotesURL();
193         } catch (NotesException e) {
194             throw newRuntimeException("Cannot get notes URL", e);
195         }
196     }
197 
198     /***
199      * {@inheritDoc}
200      * @see de.bea.domingo.DForm#getReaders()
201      */
202     public List getReaders() {
203         getFactory().preprocessMethod();
204         try {
205             return getForm().getReaders();
206         } catch (NotesException e) {
207             throw newRuntimeException("Cannot get readers", e);
208         }
209     }
210 
211     /***
212      * {@inheritDoc}
213      * @see de.bea.domingo.DForm#getURL()
214      */
215     public String getURL() {
216         getFactory().preprocessMethod();
217         try {
218             return getForm().getURL();
219         } catch (NotesException e) {
220             throw newRuntimeException("Cannot get URL", e);
221         }
222     }
223 
224     /***
225      * {@inheritDoc}
226      * @see de.bea.domingo.DForm#isProtectReaders()
227      */
228     public boolean isProtectReaders() {
229         getFactory().preprocessMethod();
230         try {
231             return getForm().isProtectReaders();
232         } catch (NotesException e) {
233             throw newRuntimeException("Cannot get protect readers", e);
234         }
235     }
236 
237     /***
238      * {@inheritDoc}
239      * @see de.bea.domingo.DForm#isProtectUsers()
240      */
241     public boolean isProtectUsers() {
242         getFactory().preprocessMethod();
243         try {
244             return getForm().isProtectUsers();
245         } catch (NotesException e) {
246             throw newRuntimeException("Cannot get protect users", e);
247         }
248     }
249 
250     /***
251      * {@inheritDoc}
252      * @see de.bea.domingo.DForm#isSubForm()
253      */
254     public boolean isSubForm() {
255         getFactory().preprocessMethod();
256         try {
257             return getForm().isSubForm();
258         } catch (NotesException e) {
259             throw newRuntimeException("Cannot get is subform", e);
260         }
261     }
262 
263     /***
264      * {@inheritDoc}
265      * @see de.bea.domingo.DForm#lock()
266      */
267     public boolean lock() {
268         getFactory().preprocessMethod();
269         try {
270             return getForm().lock();
271         } catch (NotesException e) {
272             throw newRuntimeException("Cannot .lock", e);
273         }
274     }
275 
276     /***
277      * {@inheritDoc}
278      * @see de.bea.domingo.DForm#lock(boolean)
279      */
280     public boolean lock(final boolean provisionalok) {
281         getFactory().preprocessMethod();
282         try {
283             return getForm().lock(provisionalok);
284         } catch (NotesException e) {
285             throw newRuntimeException("Cannot lock", e);
286         }
287     }
288 
289     /***
290      * {@inheritDoc}
291      * @see de.bea.domingo.DForm#lock(java.lang.String)
292      */
293     public boolean lock(final String name) {
294         getFactory().preprocessMethod();
295         try {
296             return getForm().lock(name);
297         } catch (NotesException e) {
298             throw newRuntimeException("Cannot lock", e);
299         }
300     }
301 
302     /***
303      * {@inheritDoc}
304      * @see de.bea.domingo.DForm#lock(java.lang.String, boolean)
305      */
306     public boolean lock(final String name, final boolean provisionalok) {
307         getFactory().preprocessMethod();
308         try {
309             return getForm().lock(name, provisionalok);
310         } catch (NotesException e) {
311             throw newRuntimeException("Cannot lock", e);
312         }
313     }
314 
315     /***
316      * {@inheritDoc}
317      * @see de.bea.domingo.DForm#lock(java.util.List)
318      */
319     public boolean lock(final List names) {
320         getFactory().preprocessMethod();
321         try {
322             return getForm().lock(convertListToVector(names));
323         } catch (NotesException e) {
324             throw newRuntimeException("Cannot lock", e);
325         }
326     }
327 
328     /***
329      * {@inheritDoc}
330      * @see de.bea.domingo.DForm#lock(java.util.List, boolean)
331      */
332     public boolean lock(final List names, final boolean provisionalok) {
333         getFactory().preprocessMethod();
334         try {
335             return getForm().lock(convertListToVector(names), provisionalok);
336         } catch (NotesException e) {
337             throw newRuntimeException("Cannot lock", e);
338         }
339     }
340 
341     /***
342      * {@inheritDoc}
343      * @see de.bea.domingo.DForm#lockProvisional()
344      */
345     public boolean lockProvisional() {
346         getFactory().preprocessMethod();
347         try {
348             return getForm().lockProvisional();
349         } catch (NotesException e) {
350             throw newRuntimeException("Cannot lock", e);
351         }
352     }
353 
354     /***
355      * {@inheritDoc}
356      * @see de.bea.domingo.DForm#lockProvisional(java.lang.String)
357      */
358     public boolean lockProvisional(final String name) {
359         getFactory().preprocessMethod();
360         try {
361             return getForm().lockProvisional(name);
362         } catch (NotesException e) {
363             throw newRuntimeException("Cannot lock provisional", e);
364         }
365     }
366 
367     /***
368      * {@inheritDoc}
369      * @see de.bea.domingo.DForm#lockProvisional(java.util.List)
370      */
371     public boolean lockProvisional(final List names) {
372         getFactory().preprocessMethod();
373         try {
374             return getForm().lockProvisional(convertListToVector(names));
375         } catch (NotesException e) {
376             throw newRuntimeException("Cannot lock provisional", e);
377         }
378     }
379 
380     /***
381      * {@inheritDoc}
382      * @see de.bea.domingo.DForm#remove()
383      */
384     public void remove() {
385         getFactory().preprocessMethod();
386         try {
387             getForm().remove();
388         } catch (NotesException e) {
389             throw newRuntimeException("Cannot remove form", e);
390         }
391     }
392 
393     /***
394      * {@inheritDoc}
395      * @see de.bea.domingo.DForm#setFormUsers(java.util.List)
396      */
397     public void setFormUsers(final List users) {
398         getFactory().preprocessMethod();
399         try {
400             getForm().setFormUsers(convertListToVector(users));
401         } catch (NotesException e) {
402             throw newRuntimeException("Cannot set form users", e);
403         }
404     }
405 
406     /***
407      * {@inheritDoc}
408      * @see de.bea.domingo.DForm#setProtectReaders(boolean)
409      */
410     public void setProtectReaders(final boolean flag) {
411         getFactory().preprocessMethod();
412         try {
413             getForm().setProtectReaders(flag);
414         } catch (NotesException e) {
415             throw newRuntimeException("Cannot set protect readers", e);
416         }
417     }
418 
419     /***
420      * {@inheritDoc}
421      * @see de.bea.domingo.DForm#setProtectUsers(boolean)
422      */
423     public void setProtectUsers(final boolean flag) {
424         getFactory().preprocessMethod();
425         try {
426             getForm().setProtectUsers(flag);
427         } catch (NotesException e) {
428             throw newRuntimeException("Cannot set protect users", e);
429         }
430     }
431 
432     /***
433      * {@inheritDoc}
434      * @see de.bea.domingo.DForm#setReaders(java.util.List)
435      */
436     public void setReaders(final List readers) {
437         getFactory().preprocessMethod();
438         try {
439             getForm().setReaders(convertListToVector(readers));
440         } catch (NotesException e) {
441             throw newRuntimeException("Cannot set readers", e);
442         }
443     }
444 
445     /***
446      * {@inheritDoc}
447      * @see de.bea.domingo.DForm#unlock()
448      */
449     public void unlock() {
450         getFactory().preprocessMethod();
451         try {
452             getForm().unlock();
453         } catch (NotesException e) {
454             throw newRuntimeException("Cannot unlock", e);
455         }
456     }
457 
458     /***
459      * {@inheritDoc}
460      * @see de.bea.domingo.DView#getName()
461      */
462     private String getNameIntern() {
463         getFactory().preprocessMethod();
464         try {
465             return getForm().getName();
466         } catch (NotesException e) {
467             throw newRuntimeException("Cannot get name", e);
468         }
469     }
470 }