001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.mail;
017:
018: import java.util.Properties;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022:
023: import org.apache.geronimo.gbean.GBeanInfo;
024: import org.apache.geronimo.gbean.GBeanInfoBuilder;
025:
026: /**
027: * A GBean that provides for the configuration of a JavaMail NNTP transport
028: * protocol.
029: * <p/>
030: * NNTP transport properties that are common to all NNTP transports are
031: * provided via member variables of this class. Values that are set in the
032: * individual member variables will override any of the corresponding values
033: * that have been set in the properties set.
034: *
035: * @version $Rev: 486195 $ $Date: 2006-12-12 07:42:02 -0800 (Tue, 12 Dec 2006) $
036: * @see MailGBean
037: */
038: public class NNTPStoreGBean extends ProtocolGBean implements
039: NNTPGBeanConstants {
040:
041: private final Log log = LogFactory.getLog(NNTPTransportGBean.class);
042:
043: private Integer port;
044: private Integer connectionTimeout;
045: private Integer timeout;
046: private Boolean auth;
047: private String saslRealm;
048: private Boolean quitWait;
049: private String socketFactoryClass;
050: private Boolean socketFactoryFallback;
051: private Integer socketFactoryPort;
052:
053: /**
054: * Construct an instance of NNTPStoreGBean
055: * <p/>
056: * Values that are set in the individual member variables will override any of
057: * the corresponding values that have been set in the properties set.
058: *
059: * @param objectName the object name of the protocol
060: * @param properties the set of default properties for the protocol
061: * @param host the host the protocol connects to
062: * @param user the default name for the protocol
063: * @param port the NNTP server port
064: * @param connectionTimeout the socket connection timeout value in milliseconds
065: * @param timeout the socket I/O timeout value in milliseconds
066: * @param auth whether an attempt will be made to authenticate the user
067: * @param saslRealm the realm to use with DIGEST-MD5 authentication
068: * @param quitWait whether the transport will wait for the response to the QUIT command
069: * @param socketFactoryClass the class that will be used to create NNTP sockets
070: * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
071: * socket factory class cannot be created
072: * @param socketFactoryPort whether java.net.Socket class will be created if the specified
073: * socket factory class cannot be created
074: */
075: public NNTPStoreGBean(String objectName, Properties properties,
076: String host, String user, Integer port,
077: Integer connectionTimeout, Integer timeout, Boolean auth,
078: String saslRealm, Boolean quitWait,
079: String socketFactoryClass, Boolean socketFactoryFallback,
080: Integer socketFactoryPort) {
081: super (objectName, "nntp", properties, host, user);
082:
083: setPort(port);
084: setConnectionTimeout(connectionTimeout);
085: setTimeout(timeout);
086: setAuth(auth);
087: setSaslRealm(saslRealm);
088: setQuitWait(quitWait);
089: setSocketFactoryClass(socketFactoryClass);
090: setSocketFactoryFallback(socketFactoryFallback);
091: setSocketFactoryPort(socketFactoryPort);
092: }
093:
094: /**
095: * Returns the NNTP server port to connect to, if the connect() method
096: * doesn't explicitly specify one.
097: */
098: public Integer getPort() {
099: return port;
100: }
101:
102: /**
103: * Sets the NNTP server port to connect to, if the connect() method
104: * doesn't explicitly specify one.
105: * <p/>
106: * Defaults to 25.
107: * <p/>
108: * Values that are set here will override any of the corresponding value
109: * that has been set in the properties.
110: *
111: * @param port the NNTP server port to connect to
112: */
113: public void setPort(Integer port) {
114: this .port = port;
115: }
116:
117: /**
118: * Returns the socket connection timeout value in milliseconds.
119: */
120: public Integer getConnectionTimeout() {
121: return connectionTimeout;
122: }
123:
124: /**
125: * Sets the socket connection timeout value in milliseconds.
126: * <p/>
127: * Default is infinite timeout.
128: * <p/>
129: * Values that are set here will override any of the corresponding value
130: * that has been set in the properties.
131: *
132: * @param connectionTimeout the socket connection timeout value in milliseconds.
133: */
134: public void setConnectionTimeout(Integer connectionTimeout) {
135: this .connectionTimeout = connectionTimeout;
136: }
137:
138: /**
139: * Returns the socket I/O timeout value in milliseconds.
140: */
141: public Integer getTimeout() {
142: return timeout;
143: }
144:
145: /**
146: * Sets the socket I/O timeout value in milliseconds.
147: * <p/>
148: * Default is infinite timeout.
149: * <p/>
150: * Values that are set here will override any of the corresponding value
151: * that has been set in the properties.
152: *
153: * @param timeout the socket I/O timeout value in milliseconds
154: */
155: public void setTimeout(Integer timeout) {
156: this .timeout = timeout;
157: }
158:
159: /**
160: * Returns whether an attempt will be made to authenticate the user.
161: * <p/>
162: * Defaults to false.
163: */
164: public Boolean getAuth() {
165: return auth;
166: }
167:
168: /**
169: * Sets whether an attempt will be made to authenticate the user.
170: * <p/>
171: * Defaults to false.
172: * <p/>
173: * Values that are set here will override any of the corresponding value
174: * that has been set in the properties.
175: *
176: * @param auth whether an attempt will be made to authenticate the user.
177: */
178: public void setAuth(Boolean auth) {
179: this .auth = auth;
180: }
181:
182: /**
183: * Returns the realm to use with DIGEST-MD5 authentication.
184: */
185: public String getSaslRealm() {
186: return saslRealm;
187: }
188:
189: /**
190: * Sets the realm to use with DIGEST-MD5 authentication.
191: * <p/>
192: * Values that are set here will override any of the corresponding value
193: * that has been set in the properties.
194: *
195: * @param saslRealm the realm to use with DIGEST-MD5 authentication
196: */
197: public void setSaslRealm(String saslRealm) {
198: this .saslRealm = saslRealm;
199: }
200:
201: /**
202: * Returns whether the transport will wait for the response to the QUIT command.
203: * <p/>
204: * If set to true, causes the transport to wait for the response to the QUIT
205: * command. If set to false (the default), the QUIT command is sent and the
206: * connection is immediately closed.
207: */
208: public Boolean getQuitWait() {
209: return quitWait;
210: }
211:
212: /**
213: * Sets whether the transport will wait for the response to the QUIT command
214: * <p/>
215: * If set to true, causes the transport to wait for the response to the QUIT
216: * command. If set to false (the default), the QUIT command is sent and the
217: * connection is immediately closed.
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 quitWait whether the transport will wait for the response to the QUIT command
223: */
224: public void setQuitWait(Boolean quitWait) {
225: this .quitWait = quitWait;
226: }
227:
228: /**
229: * Returns the class that will be used to create NNTP sockets.
230: * <p/>
231: * If set, specifies the name of a class that implements the
232: * javax.net.SocketFactory interface. This class will be used to create NNTP
233: * sockets.
234: */
235: public String getSocketFactoryClass() {
236: return socketFactoryClass;
237: }
238:
239: /**
240: * Sets the class that will be used to create NNTP sockets.
241: * <p/>
242: * If set, specifies the name of a class that implements the
243: * javax.net.SocketFactory interface. This class will be used to create NNTP
244: * sockets.
245: * <p/>
246: * Values that are set here will override any of the corresponding value
247: * that has been set in the properties.
248: *
249: * @param socketFactoryClass the class that will be used to create NNTP sockets
250: */
251: public void setSocketFactoryClass(String socketFactoryClass) {
252: this .socketFactoryClass = socketFactoryClass;
253: }
254:
255: /**
256: * Returns whether java.net.Socket class will be created if the specified
257: * socket factory class cannot be created.
258: * <p/>
259: * If set to true, failure to create a socket using the specified socket
260: * factory class will cause the socket to be created using the
261: * java.net.Socket class. Defaults to true.
262: */
263: public Boolean getSocketFactoryFallback() {
264: return socketFactoryFallback;
265: }
266:
267: /**
268: * Sets whether java.net.Socket class will be created if the specified
269: * socket factory class cannot be created.
270: * <p/>
271: * If set to true, failure to create a socket using the specified socket
272: * factory class will cause the socket to be created using the
273: * java.net.Socket class. Defaults to true.
274: * <p/>
275: * Values that are set here will override any of the corresponding value
276: * that has been set in the properties.
277: *
278: * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
279: * socket factory class cannot be created
280: */
281: public void setSocketFactoryFallback(Boolean socketFactoryFallback) {
282: this .socketFactoryFallback = socketFactoryFallback;
283: }
284:
285: /**
286: * Returns the port to connect to when using the specified socket factory.
287: * <p/>
288: * Specifies the port to connect to when using the specified socket
289: * factory. If not set, the default port will be used.
290: */
291: public Integer getSocketFactoryPort() {
292: return socketFactoryPort;
293: }
294:
295: /**
296: * Sets the port to connect to when using the specified socket factory.
297: * <p/>
298: * Specifies the port to connect to when using the specified socket
299: * factory. If not set, the default port will be used.
300: * <p/>
301: * Values that are set here will override any of the corresponding value
302: * that has been set in the properties.
303: *
304: * @param socketFactoryPort the port to connect to when using the specified socket factory
305: */
306: public void setSocketFactoryPort(Integer socketFactoryPort) {
307: this .socketFactoryPort = socketFactoryPort;
308: }
309:
310: /**
311: * Add the overrides from the member variables to the properties file.
312: */
313: public void addOverrides(Properties props) {
314: super .addOverrides(props);
315:
316: if (port != null)
317: props.setProperty(NNTPS_PORT, port.toString());
318: if (connectionTimeout != null)
319: props.setProperty(NNTPS_CONNECTION_TIMEOUT,
320: connectionTimeout.toString());
321: if (timeout != null)
322: props.setProperty(NNTPS_TIMEOUT, timeout.toString());
323: if (auth != null)
324: props.setProperty(NNTPS_AUTH, auth.toString());
325: if (saslRealm != null)
326: props.setProperty(NNTPS_REALM, saslRealm);
327: if (quitWait != null)
328: props.setProperty(NNTPS_QUITWAIT, quitWait.toString());
329: if (socketFactoryClass != null)
330: props.setProperty(NNTPS_FACTORY_CLASS, socketFactoryClass);
331: if (socketFactoryFallback != null)
332: props.setProperty(NNTPS_FACTORY_FALLBACK,
333: socketFactoryFallback.toString());
334: if (socketFactoryPort != null)
335: props.setProperty(NNTPS_FACTORY_PORT, socketFactoryPort
336: .toString());
337: }
338:
339: public void doStart() throws Exception {
340: log.debug("Started " + getObjectName());
341: }
342:
343: public void doStop() throws Exception {
344: log.debug("Stopped " + getObjectName());
345: }
346:
347: public void doFail() {
348: log.warn("Failed " + getObjectName());
349: }
350:
351: public static final GBeanInfo GBEAN_INFO;
352:
353: static {
354: GBeanInfoBuilder infoFactory = GBeanInfoBuilder
355: .createStatic(NNTPStoreGBean.class);
356:
357: infoFactory.addAttribute(GBEAN_PORT, Integer.class, true);
358: infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT,
359: Integer.class, true);
360: infoFactory.addAttribute(GBEAN_TIMEOUT, Integer.class, true);
361: infoFactory.addAttribute(GBEAN_AUTH, Boolean.class, true);
362: infoFactory.addAttribute(GBEAN_REALM, String.class, true);
363: infoFactory.addAttribute(GBEAN_QUITWAIT, Boolean.class, true);
364: infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String.class,
365: true);
366: infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean.class,
367: true);
368: infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer.class,
369: true);
370:
371: infoFactory.addAttribute(GBEAN_OBJECTNAME, String.class, false);
372: infoFactory.addAttribute(GBEAN_PROTOCOL, String.class, true);
373: infoFactory.addAttribute(GBEAN_PROPERTIES, Properties.class,
374: true);
375: infoFactory.addAttribute(GBEAN_HOST, String.class, true);
376: infoFactory.addAttribute(GBEAN_USER, String.class, true);
377: infoFactory.addOperation(GBEAN_ADD_OVERRIDES,
378: new Class[] { Properties.class });
379:
380: infoFactory.setConstructor(new String[] { GBEAN_OBJECTNAME,
381: GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER, GBEAN_PORT,
382: GBEAN_CONNECTION_TIMEOUT, GBEAN_TIMEOUT, GBEAN_AUTH,
383: GBEAN_REALM, GBEAN_QUITWAIT, GBEAN_FACTORY_CLASS,
384: GBEAN_FACTORY_FALLBACK, GBEAN_FACTORY_PORT });
385:
386: GBEAN_INFO = infoFactory.getBeanInfo();
387: }
388:
389: public static GBeanInfo getGBeanInfo() {
390: return GBEAN_INFO;
391: }
392: }
|