00001
00027 package org.objectweb.jonas.mail.factory;
00028
00029
00030 import java.io.Serializable;
00031 import java.util.Properties;
00032
00033 import javax.naming.NamingException;
00034 import javax.naming.Reference;
00035 import javax.naming.Referenceable;
00036
00037 import org.objectweb.jonas.common.Log;
00038 import org.objectweb.jonas.common.PropDump;
00039 import org.objectweb.jonas.mail.MailService;
00040 import org.objectweb.jonas.mail.MailServiceImpl;
00041 import org.objectweb.jonas.service.ServiceManager;
00042 import org.objectweb.util.monolog.api.BasicLevel;
00043 import org.objectweb.util.monolog.api.Logger;
00044
00063 public abstract class JavaMail implements Serializable, Referenceable {
00064
00068 private static Logger logger = null;
00069
00073 private String factoryName = null;
00074
00078 private String name = null;
00079
00084 private Properties mailSessionProperties = null;
00085
00089 private Properties authenticationProperties = null;
00090
00094 private static final String PROPERTY_AUTHENTICATION_USERNAME = "mail.authentication.username";
00095
00099 private static final String PROPERTY_AUTHENTICATION_PASSWORD = "mail.authentication.password";
00100
00107 public JavaMail(String factoryName, String name, Properties mailProperties) {
00108
00109 if (logger == null) {
00110 logger = Log.getLogger(Log.JONAS_MAIL_PREFIX);
00111 }
00112 this.factoryName = factoryName;
00113 this.name = name;
00114
00115 this.mailSessionProperties = (Properties) mailProperties.clone();
00116
00117
00118 mailSessionProperties.remove(MailServiceImpl.PROPERTY_NAME);
00119 mailSessionProperties.remove(MailServiceImpl.PROPERTY_TYPE);
00120
00121
00122 this.authenticationProperties = new Properties();
00123 String propValue = null;
00124 propValue = (String) mailSessionProperties.remove(PROPERTY_AUTHENTICATION_USERNAME);
00125 if (propValue != null) {
00126 authenticationProperties.setProperty(PROPERTY_AUTHENTICATION_USERNAME, propValue);
00127 }
00128 propValue = (String) mailSessionProperties.remove(PROPERTY_AUTHENTICATION_PASSWORD);
00129 if (propValue != null) {
00130 authenticationProperties.setProperty(PROPERTY_AUTHENTICATION_PASSWORD, propValue);
00131 }
00132 }
00133
00134
00139 public String getName() {
00140 return name;
00141 }
00142
00147 void setName(String name) {
00148 String oldName = this.name;
00149 this.name = new String(name);
00150 try {
00151 ((MailService) ServiceManager.getInstance().getMailService()).renameJavaMailFactory(oldName, this);
00152 } catch (Exception e) {
00153
00154 }
00155 }
00156
00161 public String getFactoryName() {
00162 return factoryName;
00163 }
00164
00169 public abstract String getType();
00170
00171
00176 Properties getSessionProperties() {
00177 return mailSessionProperties;
00178 }
00179
00184 void setSessionProperties(Properties props) {
00185 this.mailSessionProperties = props;
00186
00187 try {
00188 ((MailService) ServiceManager.getInstance().getMailService()).recreateJavaMailFactory(this);
00189 } catch (Exception e) {
00190
00191 }
00192
00193 PropDump.print("These are the udated session properties",
00194 this.mailSessionProperties, logger, BasicLevel.DEBUG);
00195 }
00196
00201 Properties getAuthenticationProperties() {
00202 return authenticationProperties;
00203 }
00204
00209 void setAuthenticationProperties(Properties props) {
00210 this.authenticationProperties = props;
00211
00212 try {
00213 ((MailService) ServiceManager.getInstance().getMailService()).recreateJavaMailFactory(this);
00214 } catch (Exception e) {
00215
00216 }
00217
00218 PropDump.print("These are the udated auth properties",
00219 this.authenticationProperties, logger, BasicLevel.DEBUG);
00220 }
00221
00230 public abstract Reference getReference() throws NamingException;
00231
00232
00236 public static Logger getLogger() {
00237 return logger;
00238 }
00242 public static void setLogger(Logger logger) {
00243 JavaMail.logger = logger;
00244 }
00248 public Properties getMailSessionProperties() {
00249 return mailSessionProperties;
00250 }
00254 public void setMailSessionProperties(Properties mailSessionProperties) {
00255 this.mailSessionProperties = mailSessionProperties;
00256 }
00257 }
00258