View Javadoc

1   /*
2    * $Id: SmtpMailSession.java 119 2004-10-24 08:52:43Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.factory;
24  
25  import java.util.Properties;
26  import javax.mail.Session;
27  
28  /**
29   * SMTP mail <code>Session</code> factory implementation of <code>Factory</code>
30   * interface.<br>
31   * <br>
32   * Creates a <code>Session</code> object from given parameters.<br>
33   * <br>
34   * Parameters given to create <code>Session</code> are:
35   * <ul>
36   * <li>smtpHost - SMTP server.</li>
37   * </ul>
38   *
39   * @author  Jose M. Palomar
40   * @version $Revision: 119 $
41   * @see javax.mail.Session
42   */
43  public final class SmtpMailSession extends FactoryService {
44  
45      // Constants
46  
47      // Fields
48      /**
49       * Init properties for <code>Session</code>.
50       */
51      private Properties env = new Properties();
52  
53      // Constructors
54      /**
55       * Creates a new <code>SmtpMailSession</code> object.
56       */
57      public SmtpMailSession() {
58          this.env.put("mail.trasport.protocol", "smtp");
59      }
60  
61      // Methods
62      /**
63       * Sets smtpHost parameter.
64       *
65       * @param smtpHost String SMTP server.
66       */
67      public void setSmtpHost(String smtpHost) {
68          this.env.put("mail.smtp.host", smtpHost);
69      }
70  
71      /**
72       * Returns name of service.
73       *
74       * @return String name of service.
75       * @see org.talika.tarsis.service.Service#getName()
76       */
77      public String getName() {
78          return "SmtpMailSessionFactory";
79      }
80  
81      /**
82       * Returns a new <code>Session</code> instance created by this factory.
83       *
84       * @return Object a new <code>Session</code> instance created by this factory.
85       * @see org.talika.tarsis.factory.Factory#getInstance()
86       */
87      public Object getInstance() {
88          return getMailSession();
89      }
90  
91      /**
92       * Returns a new <code>Session</code> instance created by this factory.
93       *
94       * @return Session a new <code>Session</code> instance created by this factory.
95       */
96      public Session getMailSession() {
97          return Session.getDefaultInstance(env);
98      }
99  
100 }