1 17 package org.apache.geronimo.mail; 18 19 import java.util.Enumeration ; 20 import java.util.Properties ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.apache.geronimo.gbean.GBeanInfo; 26 import org.apache.geronimo.gbean.GBeanInfoBuilder; 27 import org.apache.geronimo.gbean.GBeanLifecycle; 28 29 37 public class ProtocolGBean implements GBeanLifecycle { 38 39 static public final String GBEAN_OBJECTNAME = "objectName"; 41 static public final String GBEAN_PROTOCOL = "protocol"; 42 static public final String GBEAN_PROPERTIES = "properties"; 43 static public final String GBEAN_HOST = "host"; 44 static public final String GBEAN_USER = "user"; 45 static public final String GBEAN_ADD_OVERRIDES = "addOverrides"; 46 47 static public final String GBEAN_PORT = "port"; 49 static public final String GBEAN_CONNECTION_TIMEOUT = "connectionTimeout"; 50 static public final String GBEAN_TIMEOUT = "timeout"; 51 static public final String GBEAN_FROM = "from"; 52 static public final String GBEAN_AUTH = "auth"; 53 static public final String GBEAN_REALM = "saslRealm"; 54 static public final String GBEAN_QUITWAIT = "quitWait"; 55 static public final String GBEAN_FACTORY_CLASS = "socketFactoryClass"; 56 static public final String GBEAN_FACTORY_FALLBACK = "socketFactoryFallback"; 57 static public final String GBEAN_FACTORY_PORT = "socketFactoryPort"; 58 static public final String GBEAN_LOCALHOST = "localhost"; 59 static public final String GBEAN_LOCALADDRESS = "localaddress"; 60 static public final String GBEAN_LOCALPORT = "localport"; 61 62 private final Log log = LogFactory.getLog(ProtocolGBean.class); 63 64 private final String objectName; 65 private Properties properties; 66 private final String protocol; 67 private String host; 68 private String user; 69 70 73 public ProtocolGBean() { 74 this.objectName = null; 75 this.protocol = null; 76 this.properties = null; 77 } 78 79 91 public ProtocolGBean(String objectName, String protocol, Properties properties, String host, String user) { 92 assert protocol != null; 93 94 this.objectName = objectName; 95 this.protocol = protocol; 96 this.properties = (properties == null ? new Properties () : properties); 97 this.host = host; 98 this.user = user; 99 } 100 101 104 public String getObjectName() { 105 return objectName; 106 } 107 108 114 public Properties getProperties() { 115 return properties; 116 } 117 118 126 public void setProperties(Properties properties) { 127 this.properties = properties; 128 } 129 130 133 public String getProtocol() { 134 return protocol; 135 } 136 137 140 public String getHost() { 141 return host; 142 } 143 144 149 public void setHost(String host) { 150 this.host = host; 151 } 152 153 156 public String getUser() { 157 return user; 158 } 159 160 165 public void setUser(String user) { 166 this.user = user; 167 } 168 169 172 public void addOverrides(Properties props) { 173 Enumeration keys = properties.propertyNames(); 174 175 while (keys.hasMoreElements()) { 178 String key = (String )keys.nextElement(); 179 props.put(key, properties.getProperty(key)); 180 } 181 182 if (host != null) props.put("mail." + protocol + ".host", host); 183 if (user != null) props.put("mail." + protocol + ".user", user); 184 } 185 186 public void doStart() throws Exception { 187 log.debug("Started " + objectName); 188 } 189 190 public void doStop() throws Exception { 191 log.debug("Stopped " + objectName); 192 } 193 194 public void doFail() { 195 log.warn("Failed " + objectName); 196 } 197 198 public static final GBeanInfo GBEAN_INFO; 199 200 static { 201 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ProtocolGBean.class); 203 infoFactory.addAttribute(GBEAN_OBJECTNAME, String .class, false); 204 infoFactory.addAttribute(GBEAN_PROTOCOL, String .class, true); 205 infoFactory.addAttribute(GBEAN_PROPERTIES, Properties .class, true); 206 infoFactory.addAttribute(GBEAN_HOST, String .class, true); 207 infoFactory.addAttribute(GBEAN_USER, String .class, true); 208 infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class []{Properties .class}); 209 210 infoFactory.setConstructor(new String []{GBEAN_OBJECTNAME, GBEAN_PROTOCOL, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER}); 211 212 GBEAN_INFO = infoFactory.getBeanInfo(); 213 } 214 215 public static GBeanInfo getGBeanInfo() { 216 return GBEAN_INFO; 217 } 218 } 219 | Popular Tags |