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.Calendar;
25  
26  import lotus.domino.Agent;
27  import lotus.domino.DateTime;
28  import lotus.domino.NotesException;
29  import de.bea.domingo.DAgent;
30  import de.bea.domingo.DBase;
31  import de.bea.domingo.DNotesMonitor;
32  
33  /***
34   * Represents a notes agent.
35   *
36   * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
37   */
38  public final class AgentProxy extends BaseProxy implements DAgent {
39  
40      /*** serial version ID for serialization. */
41      private static final long serialVersionUID = 3257562923407520313L;
42  
43      /*** The name of the agent. */
44      private final String name;
45  
46      /***
47       * Constructor.
48       *
49       * @param theFactory the controlling factory
50       * @param theParent the parent
51       * @param agent the notes agent object
52       * @param monitor the monitor
53       */
54      public AgentProxy(final NotesProxyFactory theFactory, final DBase theParent,
55                        final Agent agent, final DNotesMonitor monitor) {
56          super(theFactory, theParent, agent, monitor);
57          try {
58              name = agent.getName();
59          } catch (Throwable t) {
60              throw new NullPointerException(RESOURCES.getString("agent.error"));
61          }
62      }
63  
64      /***
65       * Factory method for instances of this class.
66       *
67       * @param theFactory the controlling factory
68       * @param database the database that contains the agent
69       * @param theAgent Notes agent object
70       * @param monitor the monitor that handles logging
71       *
72       * @return Returns a DDatabase instance of type DatabaseProxy
73       */
74      public static DAgent getInstance(final NotesProxyFactory theFactory, final DatabaseProxy database,
75                                       final Agent theAgent, final DNotesMonitor monitor) {
76          if (theAgent == null) {
77              return null;
78          }
79          AgentProxy agent = (AgentProxy) theFactory.getBaseCache().get(theAgent);
80          if (agent == null) {
81              agent = new AgentProxy(theFactory, database, theAgent, monitor);
82              theFactory.getBaseCache().put(theAgent, agent);
83          }
84          return agent;
85      }
86  
87      /*** Returns the associated notes agent object.
88       *
89       * @return associated notes agent object
90       */
91      private Agent getAgent() {
92          return (Agent) getNotesObject();
93      }
94  
95      /***
96       * {@inheritDoc}
97       * @see de.bea.domingo.DAgent#getComment()
98       */
99      public String getComment() {
100         getFactory().preprocessMethod();
101         try {
102             return getAgent().getComment();
103         } catch (NotesException e) {
104             throw newRuntimeException(RESOURCES.getString(RESOURCES.getString("agent.cannot.get.comment")), e);
105         }
106     }
107 
108     /***
109      * {@inheritDoc}
110      * @see de.bea.domingo.DAgent#getCommonOwner()
111      */
112     public String getCommonOwner() {
113         getFactory().preprocessMethod();
114         try {
115             return getAgent().getCommonOwner();
116         } catch (NotesException e) {
117             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.common.owner"), e);
118         }
119     }
120 
121     /***
122      * {@inheritDoc}
123      * @see de.bea.domingo.DAgent#isEnabled()
124      */
125     public boolean isEnabled() {
126         getFactory().preprocessMethod();
127         try {
128             return getAgent().isEnabled();
129         } catch (NotesException e) {
130             throw newRuntimeException(RESOURCES.getString("agent.cannot.check.enabled"), e);
131         }
132     }
133 
134     /***
135      * {@inheritDoc}
136      * @see de.bea.domingo.DAgent#setEnabled(boolean)
137      */
138     public void setEnabled(final boolean enabled) {
139         getFactory().preprocessMethod();
140         try {
141             getAgent().setEnabled(enabled);
142         } catch (NotesException e) {
143             throw newRuntimeException(RESOURCES.getString("agent.cannot.enable"), e);
144         }
145     }
146 
147     /***
148      * {@inheritDoc}
149      * @see de.bea.domingo.DAgent#isNotesAgent()
150      */
151     public boolean isNotesAgent() {
152         getFactory().preprocessMethod();
153         try {
154             return getAgent().isNotesAgent();
155         } catch (NotesException e) {
156             throw newRuntimeException(RESOURCES.getString("agent.cannot.check.notes"), e);
157         }
158     }
159 
160     /***
161      * {@inheritDoc}
162      * @see de.bea.domingo.DAgent#isPublic()
163      */
164     public boolean isPublic() {
165         getFactory().preprocessMethod();
166         try {
167             return getAgent().isPublic();
168         } catch (NotesException e) {
169             throw newRuntimeException(RESOURCES.getString("agent.cannot.check.public"), e);
170         }
171     }
172 
173     /***
174      * {@inheritDoc}
175      * @see de.bea.domingo.DAgent#isWebAgent()
176      */
177     public boolean isWebAgent() {
178         getFactory().preprocessMethod();
179         try {
180             return getAgent().isWebAgent();
181         } catch (NotesException e) {
182             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.enabled"), e);
183         }
184     }
185 
186     /***
187      * {@inheritDoc}
188      * @see de.bea.domingo.DAgent#getLastRun()
189      */
190     public Calendar getLastRun() {
191         getFactory().preprocessMethod();
192         try {
193             final DateTime dateTime = getAgent().getLastRun();
194             final Calendar lastRun = createCalendar(dateTime);
195             dateTime.recycle();
196             return lastRun;
197         } catch (NotesException e) {
198             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.lastrun"), e);
199         }
200     }
201 
202     /***
203      * {@inheritDoc}
204      * @see de.bea.domingo.DAgent#getName()
205      */
206     public String getName() {
207         getFactory().preprocessMethod();
208         try {
209             return getAgent().getName();
210         } catch (NotesException e) {
211             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.name"), e);
212         }
213     }
214 
215     /***
216      * {@inheritDoc}
217      * @see de.bea.domingo.DAgent#getOwner()
218      */
219     public String getOwner() {
220         getFactory().preprocessMethod();
221         try {
222             return getAgent().getOwner();
223         } catch (NotesException e) {
224             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.owner"), e);
225         }
226     }
227 
228     /***
229      * {@inheritDoc}
230      * @see de.bea.domingo.DAgent#getParameterDocID()
231      */
232     public String getParameterDocID() {
233         getFactory().preprocessMethod();
234         try {
235             return getAgent().getParameterDocID();
236         } catch (NotesException e) {
237             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.noteid"), e);
238         }
239     }
240 
241     /***
242      * {@inheritDoc}
243      * @see de.bea.domingo.DAgent#getQuery()
244      */
245     public String getQuery() {
246         getFactory().preprocessMethod();
247         try {
248             return getAgent().getQuery();
249         } catch (NotesException e) {
250             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.query"), e);
251         }
252     }
253 
254     /***
255      * {@inheritDoc}
256      * @see de.bea.domingo.DAgent#getServerName()
257      */
258     public String getServerName() {
259         getFactory().preprocessMethod();
260         try {
261             return getAgent().getServerName();
262         } catch (NotesException e) {
263             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.server"), e);
264         }
265     }
266 
267     /***
268      * {@inheritDoc}
269      * @see de.bea.domingo.DAgent#setServerName(java.lang.String)
270      */
271     public void setServerName(final String serverName) {
272         getFactory().preprocessMethod();
273         try {
274             getAgent().setServerName(serverName);
275         } catch (NotesException e) {
276             throw newRuntimeException(RESOURCES.getString("agent.cannot.set.server"), e);
277         }
278     }
279 
280     /***
281      * {@inheritDoc}
282      * @see de.bea.domingo.DAgent#getTarget()
283      */
284     public int getTarget() {
285         getFactory().preprocessMethod();
286         try {
287             return getAgent().getTarget();
288         } catch (NotesException e) {
289             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.target"), e);
290         }
291     }
292 
293     /***
294      * {@inheritDoc}
295      * @see de.bea.domingo.DAgent#getTrigger()
296      */
297     public int getTrigger() {
298         getFactory().preprocessMethod();
299         try {
300             return getAgent().getTrigger();
301         } catch (NotesException e) {
302             throw newRuntimeException(RESOURCES.getString("agent.cannot.get.trigger"), e);
303         }
304     }
305 
306     /***
307      * {@inheritDoc}
308      * @see de.bea.domingo.DAgent#remove()
309      */
310     public void remove() {
311         getFactory().preprocessMethod();
312         try {
313             getAgent().remove();
314         } catch (NotesException e) {
315             throw newRuntimeException(RESOURCES.getString("agent.cannot.remove.agent"), e);
316         }
317     }
318 
319     /***
320      * {@inheritDoc}
321      * @see de.bea.domingo.DAgent#run()
322      */
323     public void run() {
324         getFactory().preprocessMethod();
325         try {
326             getAgent().run();
327         } catch (NotesException e) {
328             throw newRuntimeException(RESOURCES.getString("agent.cannot.run.agent"), e);
329         }
330     }
331 
332     /***
333      * {@inheritDoc}
334      * @see de.bea.domingo.DAgent#run(java.lang.String)
335      */
336     public void run(final String noteId) {
337         getFactory().preprocessMethod();
338         try {
339             getAgent().run(noteId);
340         } catch (NotesException e) {
341             throw newRuntimeException(RESOURCES.getString("agent.cannot.run.agent"), e);
342         }
343     }
344 
345     /***
346      * {@inheritDoc}
347      * @see de.bea.domingo.DAgent#runOnServer()
348      */
349     public int runOnServer() {
350         getFactory().preprocessMethod();
351         try {
352             return getAgent().runOnServer();
353         } catch (NotesException e) {
354             throw newRuntimeException(RESOURCES.getString("agent.cannot.run.on.server"), e);
355         }
356     }
357 
358     /***
359      * {@inheritDoc}
360      * @see de.bea.domingo.DAgent#runOnServer(java.lang.String)
361      */
362     public int runOnServer(final String noteId) {
363         getFactory().preprocessMethod();
364         try {
365             return getAgent().runOnServer(noteId);
366         } catch (NotesException e) {
367             throw newRuntimeException(RESOURCES.getString("agent.cannot.run.on.server"), e);
368         }
369     }
370 
371     /***
372      * {@inheritDoc}
373      * @see de.bea.domingo.DAgent#save()
374      */
375     public void save() {
376         getFactory().preprocessMethod();
377         try {
378             getAgent().save();
379         } catch (NotesException e) {
380             throw newRuntimeException(RESOURCES.getString("agent.cannot.save"), e);
381         }
382     }
383 
384     /***
385      * @see de.bea.domingo.proxy.BaseProxy#toString()
386      * @return the name of the agent
387      */
388     public String toString() {
389         return name;
390     }
391 }