1 28 29 package com.caucho.jca.cfg; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import java.lang.reflect.Method ; 36 import java.util.Properties ; 37 import java.util.logging.Logger ; 38 39 42 public class JavaMailConfig { 43 private static final L10N L = new L10N(JavaMailConfig.class); 44 private static final Logger log = Log.open(JavaMailConfig.class); 45 46 private Properties _props = new Properties (); 47 48 public JavaMailConfig() 49 { 50 } 51 52 55 public void setAttribute(String name, String value) 56 { 57 _props.put(name, value); 58 } 59 60 public Object replaceObject() 61 throws ConfigException 62 { 63 try { 64 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 65 66 Class sessionClass = Class.forName("javax.mail.Session", false, loader); 67 Class authClass = Class.forName("javax.mail.Authenticator", false, loader); 68 69 Method method = sessionClass.getMethod("getInstance", 70 new Class [] { Properties .class, 71 authClass }); 72 Object obj = method.invoke(null, new Object [] { _props, null }); 73 74 return obj; 75 } catch (ClassNotFoundException e) { 76 throw new ConfigException(L.l("javax.mail.Session is not available. JavaMail must be downloaded separately from Sun."), 77 e); 78 } catch (Exception e) { 79 throw new ConfigException(e); 80 } 81 } 82 } 83 | Popular Tags |