KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > mail > POP3StoreGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.mail;
18
19 import java.util.Properties JavaDoc;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26
27
28 /**
29  * A GBean that provides for the configuration of a JavaMail POP3 message store
30  * protocol.
31  * <p/>
32  * POP3 store properties that are common to all POP3 stores are
33  * provided via member variables of this class. Values that are set in the
34  * individual member variables will override any of the corresponding values
35  * that have been set in the properties set.
36  *
37  * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
38  * @see MailGBean
39  */

40 public class POP3StoreGBean extends ProtocolGBean {
41
42     // the POP3 configuration property names
43
static public final String JavaDoc POP3_PORT = "mail.pop3.port";
44     static public final String JavaDoc POP3_CONNECTION_TIMEOUT = "mail.pop3.connectiontimeout";
45     static public final String JavaDoc POP3_TIMEOUT = "mail.pop3.timeout";
46     static public final String JavaDoc POP3_FACTORY_CLASS = "mail.pop3.socketFactory.class";
47     static public final String JavaDoc POP3_FACTORY_FALLBACK = "mail.pop3.socketFactory.fallback";
48     static public final String JavaDoc POP3_FACTORY_PORT = "mail.pop3.socketFactory.port";
49     static public final String JavaDoc POP3_LOCALHOST = "mail.pop3.localhost";
50     static public final String JavaDoc POP3_LOCALADDRESS = "mail.pop3.localaddress";
51     static public final String JavaDoc POP3_LOCALPORT = "mail.pop3.localport";
52     static public final String JavaDoc POP3_RESET = "mail.pop3.resetbeforequit";
53     static public final String JavaDoc POP3_MESSAGE_CLASS = "mail.pop3.message.class";
54     static public final String JavaDoc POP3_APOP = "mail.pop3.apop.enable";
55
56     static public final String JavaDoc GBEAN_RESET = "rsetBeforeQuit";
57     static public final String JavaDoc GBEAN_APOP = "apopEnable";
58     static public final String JavaDoc GBEAN_MESSAGE_CLASS = "messageClass";
59
60     private final Log log = LogFactory.getLog(POP3StoreGBean.class);
61
62     private Integer JavaDoc port;
63     private Integer JavaDoc connectionTimeout;
64     private Integer JavaDoc timeout;
65     private Boolean JavaDoc rsetBeforeQuit;
66     private String JavaDoc messageClass;
67     private String JavaDoc localaddress;
68     private Integer JavaDoc localport;
69     private Boolean JavaDoc apopEnable;
70     private String JavaDoc socketFactoryClass;
71     private Boolean JavaDoc socketFactoryFallback;
72     private Integer JavaDoc socketFactoryPort;
73
74
75     /**
76      * Construct an instance of POP3StoreGBean
77      * <p/>
78      * Values that are set in the individual member variables will override any of
79      * the corresponding values that have been set in the properties set.
80      *
81      * @param objectName the object name of the protocol
82      * @param properties the set of default properties for the protocol
83      * @param host the host the protocol connects to
84      * @param user the default name for the protocol
85      * @param port the POP3 server port
86      * @param connectionTimeout the socket connection timeout value in milliseconds
87      * @param timeout the socket I/O timeout value in milliseconds
88      * @param rsetBeforeQuit whether an attempt will be made send a POP3 RSET command when closing
89      * the folder, before sending the QUIT command
90      * @param messageClass the class name of a subclass of com.sun.mail.pop3.POP3Message
91      * @param localaddress the local address (host name) to bind to when creating the POP3 socket
92      * @param localport the local port number to bind to when creating the POP3 socket
93      * @param apopEnable whether to use APOP instead of USER/PASS to login to the POP3 server,
94      * if the POP3 server supports APOP
95      * @param socketFactoryClass the class that will be used to create POP3 sockets
96      * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
97      * socket factory class cannot be created
98      * @param socketFactoryPort whether java.net.Socket class will be created if the specified
99      * socket factory class cannot be created
100      */

101     public POP3StoreGBean(String JavaDoc objectName, Properties JavaDoc properties, String JavaDoc host, String JavaDoc user,
102                           Integer JavaDoc port,
103                           Integer JavaDoc connectionTimeout,
104                           Integer JavaDoc timeout,
105                           Boolean JavaDoc rsetBeforeQuit,
106                           String JavaDoc messageClass,
107                           String JavaDoc localaddress,
108                           Integer JavaDoc localport,
109                           Boolean JavaDoc apopEnable,
110                           String JavaDoc socketFactoryClass,
111                           Boolean JavaDoc socketFactoryFallback,
112                           Integer JavaDoc socketFactoryPort) {
113         super(objectName, "pop3", properties, host, user);
114
115         setPort(port);
116         setConnectionTimeout(connectionTimeout);
117         setTimeout(timeout);
118         setRsetBeforeQuit(rsetBeforeQuit);
119         setMessageClass(messageClass);
120         setLocaladdress(localaddress);
121         setLocalport(localport);
122         setApopEnable(apopEnable);
123         setSocketFactoryClass(socketFactoryClass);
124         setSocketFactoryFallback(socketFactoryFallback);
125         setSocketFactoryPort(socketFactoryPort);
126     }
127
128     /**
129      * Returns the POP3 server port to connect to, if the connect() method
130      * doesn't explicitly specify one.
131      * <p/>
132      * Defaults to 110.
133      */

134     public Integer JavaDoc getPort() {
135         return port;
136     }
137
138     /**
139      * Sets the POP3 server port to connect to, if the connect() method
140      * doesn't explicitly specify one.
141      * <p/>
142      * Defaults to 110.
143      * <p/>
144      * Values that are set here will override any of the corresponding value
145      * that has been set in the properties.
146      *
147      * @param port the POP3 server port to connect to, if the connect() method
148      * doesn't explicitly specify one
149      */

150     public void setPort(Integer JavaDoc port) {
151         this.port = port;
152     }
153
154     /**
155      * Returns the socket connection timeout value in milliseconds.
156      */

157     public Integer JavaDoc getConnectionTimeout() {
158         return connectionTimeout;
159     }
160
161     /**
162      * Sets the socket connection timeout value in milliseconds.
163      * <p/>
164      * Default is infinite timeout.
165      * <p/>
166      * Values that are set here will override any of the corresponding value
167      * that has been set in the properties.
168      *
169      * @param connectionTimeout the socket connection timeout value in milliseconds.
170      */

171     public void setConnectionTimeout(Integer JavaDoc connectionTimeout) {
172         this.connectionTimeout = connectionTimeout;
173     }
174
175     /**
176      * Returns the socket I/O timeout value in milliseconds.
177      */

178     public Integer JavaDoc getTimeout() {
179         return timeout;
180     }
181
182     /**
183      * Sets the socket I/O timeout value in milliseconds.
184      * <p/>
185      * Default is infinite timeout.
186      * <p/>
187      * Values that are set here will override any of the corresponding value
188      * that has been set in the properties.
189      *
190      * @param timeout the socket I/O timeout value in milliseconds
191      */

192     public void setTimeout(Integer JavaDoc timeout) {
193         this.timeout = timeout;
194     }
195
196     /**
197      * Returns whether an attempt will be made send a POP3 RSET command when
198      * closing the folder, before sending the QUIT command.
199      * <p/>
200      * Send a POP3 RSET command when closing the folder, before sending the
201      * QUIT command. Useful with POP3 servers that implicitly mark all
202      * messages that are read as "deleted"; this will prevent such messages
203      * from being deleted and expunged unless the client requests so. Default
204      * is false.
205      */

206     public Boolean JavaDoc getRsetBeforeQuit() {
207         return rsetBeforeQuit;
208     }
209
210     /**
211      * Sets whether an attempt will be made send a POP3 RSET command when
212      * closing the folder, before sending the QUIT command.
213      * <p/>
214      * Send a POP3 RSET command when closing the folder, before sending the
215      * QUIT command. Useful with POP3 servers that implicitly mark all messages
216      * that are read as "deleted"; this will prevent such messages from being
217      * deleted and expunged unless the client requests so. Default is false.
218      * <p/>
219      * Values that are set here will override any of the corresponding value
220      * that has been set in the properties.
221      *
222      * @param rsetBeforeQuit whether an attempt will be made send a POP3 RSET command when
223      * closing the folder, before sending the QUIT command
224      */

225     public void setRsetBeforeQuit(Boolean JavaDoc rsetBeforeQuit) {
226         this.rsetBeforeQuit = rsetBeforeQuit;
227     }
228
229     /**
230      * Returns the class name of a subclass of com.sun.mail.pop3.POP3Message.
231      * <p/>
232      * Class name of a subclass of com.sun.mail.pop3.POP3Message. The subclass
233      * can be used to handle (for example) non-standard Content-Type headers.
234      * The subclass must have a public constructor of the form
235      * MyPOP3Message(Folder f, int msgno) throws MessagingException.
236      */

237     public String JavaDoc getMessageClass() {
238         return messageClass;
239     }
240
241     /**
242      * Sets the class name of a subclass of com.sun.mail.pop3.POP3Message.
243      * <p/>
244      * Class name of a subclass of com.sun.mail.pop3.POP3Message. The subclass
245      * can be used to handle (for example) non-standard Content-Type headers.
246      * The subclass must have a public constructor of the form
247      * MyPOP3Message(Folder f, int msgno) throws MessagingException.
248      * <p/>
249      * Values that are set here will override any of the corresponding value
250      * that has been set in the properties.
251      *
252      * @param messageClass the class name of a subclass of com.sun.mail.pop3.POP3Message.
253      */

254     public void setMessageClass(String JavaDoc messageClass) {
255         this.messageClass = messageClass;
256     }
257
258     /**
259      * Returns the local address (host name) to bind to when creating the POP3 socket.
260      */

261     public String JavaDoc getLocaladdress() {
262         return localaddress;
263     }
264
265     /**
266      * Sets the local address (host name) to bind to when creating the POP3 socket.
267      * <p/>
268      * Local address (host name) to bind to when creating the POP3 socket.
269      * Defaults to the address picked by the Socket class. Should not normally
270      * need to be set, but useful with multi-homed hosts where it's important
271      * to pick a particular local address to bind to.
272      * <p/>
273      * Values that are set here will override any of the corresponding value
274      * that has been set in the properties.
275      *
276      * @param localaddress the local address (host name) to bind to when creating the POP3 socket
277      */

278     public void setLocaladdress(String JavaDoc localaddress) {
279         this.localaddress = localaddress;
280     }
281
282     /**
283      * Returns the local port number to bind to when creating the POP3 socket.
284      */

285     public Integer JavaDoc getLocalport() {
286         return localport;
287     }
288
289     /**
290      * Sets the local port number to bind to when creating the POP3 socket.
291      * <p/>
292      * Local port number to bind to when creating the POP3 socket. Defaults to
293      * the port number picked by the Socket class.
294      * <p/>
295      * Values that are set here will override any of the corresponding value
296      * that has been set in the properties.
297      *
298      * @param localport the local port number to bind to when creating the POP3 socket
299      */

300     public void setLocalport(Integer JavaDoc localport) {
301         this.localport = localport;
302     }
303
304     /**
305      * Returns whether to use APOP instead of USER/PASS to login to the POP3
306      * server, if the POP3 server supports APOP.
307      * <p/>
308      * If set to true, use APOP instead of USER/PASS to login to the POP3
309      * server, if the POP3 server supports APOP. APOP sends a digest of the
310      * password rather than the clear text password. Defaults to false.
311      */

312     public Boolean JavaDoc isApopEnable() {
313         return apopEnable;
314     }
315
316     /**
317      * Sets whether to use APOP instead of USER/PASS to login to the POP3
318      * server, if the POP3 server supports APOP.
319      * <p/>
320      * If set to true, use APOP instead of USER/PASS to login to the POP3
321      * server, if the POP3 server supports APOP. APOP sends a digest of the
322      * password rather than the clear text password. Defaults to false.
323      *
324      * @param apopEnable whether to use APOP instead of USER/PASS to login to the POP3
325      * server, if the POP3 server supports APOP
326      */

327     public void setApopEnable(Boolean JavaDoc apopEnable) {
328         this.apopEnable = apopEnable;
329     }
330
331     /**
332      * Returns the class that will be used to create POP3 sockets.
333      * <p/>
334      * If set, specifies the name of a class that implements the
335      * javax.net.SocketFactory interface. This class will be used to create POP3
336      * sockets.
337      */

338     public String JavaDoc getSocketFactoryClass() {
339         return socketFactoryClass;
340     }
341
342     /**
343      * Sets the class that will be used to create POP3 sockets.
344      * <p/>
345      * If set, specifies the name of a class that implements the
346      * javax.net.SocketFactory interface. This class will be used to create POP3
347      * sockets.
348      * <p/>
349      * Values that are set here will override any of the corresponding value
350      * that has been set in the properties.
351      *
352      * @param socketFactoryClass the class that will be used to create POP3 sockets
353      */

354     public void setSocketFactoryClass(String JavaDoc socketFactoryClass) {
355         this.socketFactoryClass = socketFactoryClass;
356     }
357
358     /**
359      * Returns whether java.net.Socket class will be created if the specified
360      * socket factory class cannot be created.
361      * <p/>
362      * If set to true, failure to create a socket using the specified socket
363      * factory class will cause the socket to be created using the
364      * java.net.Socket class. Defaults to true.
365      */

366     public Boolean JavaDoc isSocketFactoryFallback() {
367         return socketFactoryFallback;
368     }
369
370     /**
371      * Sets whether java.net.Socket class will be created if the specified
372      * socket factory class cannot be created.
373      * <p/>
374      * If set to true, failure to create a socket using the specified socket
375      * factory class will cause the socket to be created using the
376      * java.net.Socket class. Defaults to true.
377      * <p/>
378      * Values that are set here will override any of the corresponding value
379      * that has been set in the properties.
380      *
381      * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
382      * socket factory class cannot be created
383      */

384     public void setSocketFactoryFallback(Boolean JavaDoc socketFactoryFallback) {
385         this.socketFactoryFallback = socketFactoryFallback;
386     }
387
388     /**
389      * Returns the port to connect to when using the specified socket factory.
390      * <p/>
391      * Specifies the port to connect to when using the specified socket
392      * factory. If not set, the default port will be used.
393      */

394     public Integer JavaDoc getSocketFactoryPort() {
395         return socketFactoryPort;
396     }
397
398     /**
399      * Sets the port to connect to when using the specified socket factory.
400      * <p/>
401      * Specifies the port to connect to when using the specified socket
402      * factory. If not set, the default port will be used.
403      * <p/>
404      * Values that are set here will override any of the corresponding value
405      * that has been set in the properties.
406      *
407      * @param socketFactoryPort the port to connect to when using the specified socket factory
408      */

409     public void setSocketFactoryPort(Integer JavaDoc socketFactoryPort) {
410         this.socketFactoryPort = socketFactoryPort;
411     }
412
413     /**
414      * Add the overrides from the member variables to the properties file.
415      */

416     public void addOverrides(Properties JavaDoc props) {
417         super.addOverrides(props);
418
419         if (port != null) props.setProperty(POP3_PORT, port.toString());
420         if (connectionTimeout != null) props.setProperty(POP3_CONNECTION_TIMEOUT, connectionTimeout.toString());
421         if (timeout != null) props.setProperty(POP3_TIMEOUT, timeout.toString());
422         if (rsetBeforeQuit != null) props.setProperty(POP3_RESET, rsetBeforeQuit.toString());
423         if (messageClass != null) props.setProperty(POP3_MESSAGE_CLASS, messageClass);
424         if (localaddress != null) props.setProperty(POP3_LOCALADDRESS, localaddress);
425         if (localport != null) props.setProperty(POP3_LOCALPORT, localport.toString());
426         if (apopEnable != null) props.setProperty(POP3_APOP, apopEnable.toString());
427         if (socketFactoryClass != null) props.setProperty(POP3_FACTORY_CLASS, socketFactoryClass);
428         if (socketFactoryFallback != null) props.setProperty(POP3_FACTORY_FALLBACK, socketFactoryFallback.toString());
429         if (socketFactoryPort != null) props.setProperty(POP3_FACTORY_PORT, socketFactoryPort.toString());
430     }
431
432     public void doStart() throws Exception JavaDoc {
433         log.debug("Started " + getObjectName());
434     }
435
436     public void doStop() throws Exception JavaDoc {
437         log.debug("Stopped " + getObjectName());
438     }
439
440     public void doFail() {
441         log.warn("Failed " + getObjectName());
442     }
443
444     public static final GBeanInfo GBEAN_INFO;
445
446     static {
447         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(POP3StoreGBean.class, ProtocolGBean.GBEAN_INFO);
448
449         infoFactory.addAttribute(GBEAN_PORT, Integer JavaDoc.class, true);
450         infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer JavaDoc.class, true);
451         infoFactory.addAttribute(GBEAN_TIMEOUT, Integer JavaDoc.class, true);
452         infoFactory.addAttribute(GBEAN_RESET, Boolean JavaDoc.class, true);
453         infoFactory.addAttribute(GBEAN_MESSAGE_CLASS, String JavaDoc.class, true);
454         infoFactory.addAttribute(GBEAN_LOCALADDRESS, String JavaDoc.class, true);
455         infoFactory.addAttribute(GBEAN_LOCALPORT, Integer JavaDoc.class, true);
456         infoFactory.addAttribute(GBEAN_APOP, Boolean JavaDoc.class, true);
457         infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String JavaDoc.class, true);
458         infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean JavaDoc.class, true);
459         infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer JavaDoc.class, true);
460
461         infoFactory.addAttribute(GBEAN_OBJECTNAME, String JavaDoc.class, false);
462         infoFactory.addAttribute(GBEAN_PROTOCOL, String JavaDoc.class, true);
463         infoFactory.addAttribute(GBEAN_PROPERTIES, Properties JavaDoc.class, true);
464         infoFactory.addAttribute(GBEAN_HOST, String JavaDoc.class, true);
465         infoFactory.addAttribute(GBEAN_USER, String JavaDoc.class, true);
466         infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class JavaDoc[]{Properties JavaDoc.class});
467
468         infoFactory.setConstructor(new String JavaDoc[]{GBEAN_OBJECTNAME, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER,
469                                                 GBEAN_PORT,
470                                                 GBEAN_CONNECTION_TIMEOUT,
471                                                 GBEAN_TIMEOUT,
472                                                 GBEAN_RESET,
473                                                 GBEAN_MESSAGE_CLASS,
474                                                 GBEAN_LOCALADDRESS,
475                                                 GBEAN_LOCALPORT,
476                                                 GBEAN_APOP,
477                                                 GBEAN_FACTORY_CLASS,
478                                                 GBEAN_FACTORY_FALLBACK,
479                                                 GBEAN_FACTORY_PORT});
480
481         GBEAN_INFO = infoFactory.getBeanInfo();
482     }
483
484     public static GBeanInfo getGBeanInfo() {
485         return GBEAN_INFO;
486     }
487 }
488
Popular Tags