KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A GBean that provides for the configuration of a JavaMail NNTP transport
29  * protocol.
30  * <p/>
31  * NNTP transport properties that are common to all NNTP transports are
32  * provided via member variables of this class. Values that are set in the
33  * individual member variables will override any of the corresponding values
34  * that have been set in the properties set.
35  *
36  * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
37  * @see MailGBean
38  */

39 public class NNTPStoreGBean extends ProtocolGBean implements NNTPGBeanConstants {
40
41     private final Log log = LogFactory.getLog(NNTPTransportGBean.class);
42
43     private Integer JavaDoc port;
44     private Integer JavaDoc connectionTimeout;
45     private Integer JavaDoc timeout;
46     private Boolean JavaDoc auth;
47     private String JavaDoc saslRealm;
48     private Boolean JavaDoc quitWait;
49     private String JavaDoc socketFactoryClass;
50     private Boolean JavaDoc socketFactoryFallback;
51     private Integer JavaDoc socketFactoryPort;
52
53
54     /**
55      * Construct an instance of NNTPStoreGBean
56      * <p/>
57      * Values that are set in the individual member variables will override any of
58      * the corresponding values that have been set in the properties set.
59      *
60      * @param objectName the object name of the protocol
61      * @param properties the set of default properties for the protocol
62      * @param host the host the protocol connects to
63      * @param user the default name for the protocol
64      * @param port the NNTP server port
65      * @param connectionTimeout the socket connection timeout value in milliseconds
66      * @param timeout the socket I/O timeout value in milliseconds
67      * @param auth whether an attempt will be made to authenticate the user
68      * @param saslRealm the realm to use with DIGEST-MD5 authentication
69      * @param quitWait whether the transport will wait for the response to the QUIT command
70      * @param socketFactoryClass the class that will be used to create NNTP sockets
71      * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
72      * socket factory class cannot be created
73      * @param socketFactoryPort whether java.net.Socket class will be created if the specified
74      * socket factory class cannot be created
75      */

76     public NNTPStoreGBean(String JavaDoc objectName, Properties JavaDoc properties, String JavaDoc host, String JavaDoc user,
77                               Integer JavaDoc port,
78                               Integer JavaDoc connectionTimeout,
79                               Integer JavaDoc timeout,
80                               Boolean JavaDoc auth,
81                               String JavaDoc saslRealm,
82                               Boolean JavaDoc quitWait,
83                               String JavaDoc socketFactoryClass,
84                               Boolean JavaDoc socketFactoryFallback,
85                               Integer JavaDoc socketFactoryPort) {
86         super(objectName, "nntp", properties, host, user);
87
88         setPort(port);
89         setConnectionTimeout(connectionTimeout);
90         setTimeout(timeout);
91         setAuth(auth);
92         setSaslRealm(saslRealm);
93         setQuitWait(quitWait);
94         setSocketFactoryClass(socketFactoryClass);
95         setSocketFactoryFallback(socketFactoryFallback);
96         setSocketFactoryPort(socketFactoryPort);
97     }
98
99     /**
100      * Returns the NNTP server port to connect to, if the connect() method
101      * doesn't explicitly specify one.
102      */

103     public Integer JavaDoc getPort() {
104         return port;
105     }
106
107     /**
108      * Sets the NNTP server port to connect to, if the connect() method
109      * doesn't explicitly specify one.
110      * <p/>
111      * Defaults to 25.
112      * <p/>
113      * Values that are set here will override any of the corresponding value
114      * that has been set in the properties.
115      *
116      * @param port the NNTP server port to connect to
117      */

118     public void setPort(Integer JavaDoc port) {
119         this.port = port;
120     }
121
122     /**
123      * Returns the socket connection timeout value in milliseconds.
124      */

125     public Integer JavaDoc getConnectionTimeout() {
126         return connectionTimeout;
127     }
128
129     /**
130      * Sets the socket connection timeout value in milliseconds.
131      * <p/>
132      * Default is infinite timeout.
133      * <p/>
134      * Values that are set here will override any of the corresponding value
135      * that has been set in the properties.
136      *
137      * @param connectionTimeout the socket connection timeout value in milliseconds.
138      */

139     public void setConnectionTimeout(Integer JavaDoc connectionTimeout) {
140         this.connectionTimeout = connectionTimeout;
141     }
142
143     /**
144      * Returns the socket I/O timeout value in milliseconds.
145      */

146     public Integer JavaDoc getTimeout() {
147         return timeout;
148     }
149
150     /**
151      * Sets the socket I/O timeout value in milliseconds.
152      * <p/>
153      * Default is infinite timeout.
154      * <p/>
155      * Values that are set here will override any of the corresponding value
156      * that has been set in the properties.
157      *
158      * @param timeout the socket I/O timeout value in milliseconds
159      */

160     public void setTimeout(Integer JavaDoc timeout) {
161         this.timeout = timeout;
162     }
163
164
165     /**
166      * Returns whether an attempt will be made to authenticate the user.
167      * <p/>
168      * Defaults to false.
169      */

170     public Boolean JavaDoc getAuth() {
171         return auth;
172     }
173
174     /**
175      * Sets whether an attempt will be made to authenticate the user.
176      * <p/>
177      * Defaults to false.
178      * <p/>
179      * Values that are set here will override any of the corresponding value
180      * that has been set in the properties.
181      *
182      * @param auth whether an attempt will be made to authenticate the user.
183      */

184     public void setAuth(Boolean JavaDoc auth) {
185         this.auth = auth;
186     }
187
188     /**
189      * Returns the realm to use with DIGEST-MD5 authentication.
190      */

191     public String JavaDoc getSaslRealm() {
192         return saslRealm;
193     }
194
195     /**
196      * Sets the realm to use with DIGEST-MD5 authentication.
197      * <p/>
198      * Values that are set here will override any of the corresponding value
199      * that has been set in the properties.
200      *
201      * @param saslRealm the realm to use with DIGEST-MD5 authentication
202      */

203     public void setSaslRealm(String JavaDoc saslRealm) {
204         this.saslRealm = saslRealm;
205     }
206
207     /**
208      * Returns whether the transport will wait for the response to the QUIT command.
209      * <p/>
210      * If set to true, causes the transport to wait for the response to the QUIT
211      * command. If set to false (the default), the QUIT command is sent and the
212      * connection is immediately closed.
213      */

214     public Boolean JavaDoc getQuitWait() {
215         return quitWait;
216     }
217
218     /**
219      * Sets whether the transport will wait for the response to the QUIT command
220      * <p/>
221      * If set to true, causes the transport to wait for the response to the QUIT
222      * command. If set to false (the default), the QUIT command is sent and the
223      * connection is immediately closed.
224      * <p/>
225      * Values that are set here will override any of the corresponding value
226      * that has been set in the properties.
227      *
228      * @param quitWait whether the transport will wait for the response to the QUIT command
229      */

230     public void setQuitWait(Boolean JavaDoc quitWait) {
231         this.quitWait = quitWait;
232     }
233
234     /**
235      * Returns the class that will be used to create NNTP sockets.
236      * <p/>
237      * If set, specifies the name of a class that implements the
238      * javax.net.SocketFactory interface. This class will be used to create NNTP
239      * sockets.
240      */

241     public String JavaDoc getSocketFactoryClass() {
242         return socketFactoryClass;
243     }
244
245     /**
246      * Sets the class that will be used to create NNTP sockets.
247      * <p/>
248      * If set, specifies the name of a class that implements the
249      * javax.net.SocketFactory interface. This class will be used to create NNTP
250      * sockets.
251      * <p/>
252      * Values that are set here will override any of the corresponding value
253      * that has been set in the properties.
254      *
255      * @param socketFactoryClass the class that will be used to create NNTP sockets
256      */

257     public void setSocketFactoryClass(String JavaDoc socketFactoryClass) {
258         this.socketFactoryClass = socketFactoryClass;
259     }
260
261     /**
262      * Returns whether java.net.Socket class will be created if the specified
263      * socket factory class cannot be created.
264      * <p/>
265      * If set to true, failure to create a socket using the specified socket
266      * factory class will cause the socket to be created using the
267      * java.net.Socket class. Defaults to true.
268      */

269     public Boolean JavaDoc getSocketFactoryFallback() {
270         return socketFactoryFallback;
271     }
272
273     /**
274      * Sets whether java.net.Socket class will be created if the specified
275      * socket factory class cannot be created.
276      * <p/>
277      * If set to true, failure to create a socket using the specified socket
278      * factory class will cause the socket to be created using the
279      * java.net.Socket class. Defaults to true.
280      * <p/>
281      * Values that are set here will override any of the corresponding value
282      * that has been set in the properties.
283      *
284      * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
285      * socket factory class cannot be created
286      */

287     public void setSocketFactoryFallback(Boolean JavaDoc socketFactoryFallback) {
288         this.socketFactoryFallback = socketFactoryFallback;
289     }
290
291     /**
292      * Returns the port to connect to when using the specified socket factory.
293      * <p/>
294      * Specifies the port to connect to when using the specified socket
295      * factory. If not set, the default port will be used.
296      */

297     public Integer JavaDoc getSocketFactoryPort() {
298         return socketFactoryPort;
299     }
300
301     /**
302      * Sets the port to connect to when using the specified socket factory.
303      * <p/>
304      * Specifies the port to connect to when using the specified socket
305      * factory. If not set, the default port will be used.
306      * <p/>
307      * Values that are set here will override any of the corresponding value
308      * that has been set in the properties.
309      *
310      * @param socketFactoryPort the port to connect to when using the specified socket factory
311      */

312     public void setSocketFactoryPort(Integer JavaDoc socketFactoryPort) {
313         this.socketFactoryPort = socketFactoryPort;
314     }
315
316     /**
317      * Add the overrides from the member variables to the properties file.
318      */

319     public void addOverrides(Properties JavaDoc props) {
320         super.addOverrides(props);
321
322         if (port != null) props.setProperty(NNTPS_PORT, port.toString());
323         if (connectionTimeout != null) props.setProperty(NNTPS_CONNECTION_TIMEOUT, connectionTimeout.toString());
324         if (timeout != null) props.setProperty(NNTPS_TIMEOUT, timeout.toString());
325         if (auth != null) props.setProperty(NNTPS_AUTH, auth.toString());
326         if (saslRealm != null) props.setProperty(NNTPS_REALM, saslRealm);
327         if (quitWait != null) props.setProperty(NNTPS_QUITWAIT, quitWait.toString());
328         if (socketFactoryClass != null) props.setProperty(NNTPS_FACTORY_CLASS, socketFactoryClass);
329         if (socketFactoryFallback != null) props.setProperty(NNTPS_FACTORY_FALLBACK, socketFactoryFallback.toString());
330         if (socketFactoryPort != null) props.setProperty(NNTPS_FACTORY_PORT, socketFactoryPort.toString());
331     }
332
333     public void doStart() throws Exception JavaDoc {
334         log.debug("Started " + getObjectName());
335     }
336
337     public void doStop() throws Exception JavaDoc {
338         log.debug("Stopped " + getObjectName());
339     }
340
341     public void doFail() {
342         log.warn("Failed " + getObjectName());
343     }
344
345     public static final GBeanInfo GBEAN_INFO;
346
347     static {
348         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(NNTPStoreGBean.class);
349
350         infoFactory.addAttribute(GBEAN_PORT, Integer JavaDoc.class, true);
351         infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer JavaDoc.class, true);
352         infoFactory.addAttribute(GBEAN_TIMEOUT, Integer JavaDoc.class, true);
353         infoFactory.addAttribute(GBEAN_AUTH, Boolean JavaDoc.class, true);
354         infoFactory.addAttribute(GBEAN_REALM, String JavaDoc.class, true);
355         infoFactory.addAttribute(GBEAN_QUITWAIT, Boolean JavaDoc.class, true);
356         infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String JavaDoc.class, true);
357         infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean JavaDoc.class, true);
358         infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer JavaDoc.class, true);
359
360         infoFactory.addAttribute(GBEAN_OBJECTNAME, String JavaDoc.class, false);
361         infoFactory.addAttribute(GBEAN_PROTOCOL, String JavaDoc.class, true);
362         infoFactory.addAttribute(GBEAN_PROPERTIES, Properties JavaDoc.class, true);
363         infoFactory.addAttribute(GBEAN_HOST, String JavaDoc.class, true);
364         infoFactory.addAttribute(GBEAN_USER, String JavaDoc.class, true);
365         infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class JavaDoc[]{Properties JavaDoc.class});
366
367         infoFactory.setConstructor(new String JavaDoc[]{GBEAN_OBJECTNAME, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER,
368                                                 GBEAN_PORT,
369                                                 GBEAN_CONNECTION_TIMEOUT,
370                                                 GBEAN_TIMEOUT,
371                                                 GBEAN_AUTH,
372                                                 GBEAN_REALM,
373                                                 GBEAN_QUITWAIT,
374                                                 GBEAN_FACTORY_CLASS,
375                                                 GBEAN_FACTORY_FALLBACK,
376                                                 GBEAN_FACTORY_PORT});
377
378         GBEAN_INFO = infoFactory.getBeanInfo();
379     }
380
381     public static GBeanInfo getGBeanInfo() {
382         return GBEAN_INFO;
383     }
384 }
385
386
387
Popular Tags