1 26 27 package org.objectweb.jonas.mail.factory; 28 29 import java.io.Serializable ; 31 import java.util.Properties ; 32 33 import javax.naming.NamingException ; 34 import javax.naming.Reference ; 35 import javax.naming.Referenceable ; 36 37 import org.objectweb.jonas.common.Log; 38 import org.objectweb.jonas.common.PropDump; 39 import org.objectweb.jonas.mail.MailService; 40 import org.objectweb.jonas.mail.MailServiceImpl; 41 import org.objectweb.jonas.service.ServiceManager; 42 import org.objectweb.util.monolog.api.BasicLevel; 43 import org.objectweb.util.monolog.api.Logger; 44 45 63 public abstract class JavaMail implements Serializable , Referenceable { 64 65 68 private static Logger logger = null; 69 70 73 private String factoryName = null; 74 75 78 private String name = null; 79 80 84 private Properties mailSessionProperties = null; 85 86 89 private Properties authenticationProperties = null; 90 91 94 private static final String PROPERTY_AUTHENTICATION_USERNAME = "mail.authentication.username"; 95 96 99 private static final String PROPERTY_AUTHENTICATION_PASSWORD = "mail.authentication.password"; 100 101 107 public JavaMail(String factoryName, String name, Properties mailProperties) { 108 if (logger == null) { 110 logger = Log.getLogger(Log.JONAS_MAIL_PREFIX); 111 } 112 this.factoryName = factoryName; 113 this.name = name; 114 115 this.mailSessionProperties = (Properties ) mailProperties.clone(); 116 117 mailSessionProperties.remove(MailServiceImpl.PROPERTY_NAME); 119 mailSessionProperties.remove(MailServiceImpl.PROPERTY_TYPE); 120 121 this.authenticationProperties = new Properties (); 123 String propValue = null; 124 propValue = (String ) mailSessionProperties.remove(PROPERTY_AUTHENTICATION_USERNAME); 125 if (propValue != null) { 126 authenticationProperties.setProperty(PROPERTY_AUTHENTICATION_USERNAME, propValue); 127 } 128 propValue = (String ) mailSessionProperties.remove(PROPERTY_AUTHENTICATION_PASSWORD); 129 if (propValue != null) { 130 authenticationProperties.setProperty(PROPERTY_AUTHENTICATION_PASSWORD, propValue); 131 } 132 } 133 134 135 139 public String getName() { 140 return name; 141 } 142 143 147 void setName(String name) { 148 String oldName = this.name; 149 this.name = new String (name); 150 try { 151 ((MailService) ServiceManager.getInstance().getMailService()).renameJavaMailFactory(oldName, this); 152 } catch (Exception e) { 153 } 155 } 156 157 161 public String getFactoryName() { 162 return factoryName; 163 } 164 165 169 public abstract String getType(); 170 171 172 176 Properties getSessionProperties() { 177 return mailSessionProperties; 178 } 179 180 184 void setSessionProperties(Properties props) { 185 this.mailSessionProperties = props; 186 try { 188 ((MailService) ServiceManager.getInstance().getMailService()).recreateJavaMailFactory(this); 189 } catch (Exception e) { 190 } 192 if (logger.isLoggable(BasicLevel.DEBUG)) { 194 PropDump.print("These are the udated session properties", this.mailSessionProperties, logger, BasicLevel.DEBUG); 195 } 196 } 197 198 202 Properties getAuthenticationProperties() { 203 return authenticationProperties; 204 } 205 206 210 void setAuthenticationProperties(Properties props) { 211 this.authenticationProperties = props; 212 try { 214 ((MailService) ServiceManager.getInstance().getMailService()).recreateJavaMailFactory(this); 215 } catch (Exception e) { 216 } 218 if (logger.isLoggable(BasicLevel.DEBUG)) { 220 PropDump.print("These are the udated auth properties", 221 this.authenticationProperties, logger, BasicLevel.DEBUG); 222 } 223 } 224 225 233 public abstract Reference getReference() throws NamingException ; 234 235 236 239 public static Logger getLogger() { 240 return logger; 241 } 242 245 public static void setLogger(Logger logger) { 246 JavaMail.logger = logger; 247 } 248 251 public Properties getMailSessionProperties() { 252 return mailSessionProperties; 253 } 254 257 public void setMailSessionProperties(Properties mailSessionProperties) { 258 this.mailSessionProperties = mailSessionProperties; 259 } 260 } 261 262 | Popular Tags |