KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > mail > factory > JavaMailSession


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Florent BENOIT & Ludovic BERT
22  * --------------------------------------------------------------------------
23  * $Id: JavaMailSession.java,v 1.6 2005/04/28 08:43:25 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.mail.factory;
28
29 //import java
30
import java.util.Properties JavaDoc;
31
32 //import javax
33
import javax.naming.BinaryRefAddr JavaDoc;
34 import javax.naming.NamingException JavaDoc;
35 import javax.naming.Reference JavaDoc;
36
37 //import objectweb.util
38
import org.objectweb.util.monolog.api.BasicLevel;
39
40 //import jonas
41
import org.objectweb.jonas.common.PropDump;
42 import org.objectweb.jonas.common.JNDIUtils;
43
44 /**
45  * This class provides a way for referencing mail session.
46  * @author Florent Benoit
47  * @author Ludovic Bert
48  */

49 public class JavaMailSession extends JavaMail {
50
51     /**
52      * Type of the factory
53      */

54     private static final String JavaDoc FACTORY_TYPE = "javax.mail.Session";
55
56
57    /**
58      * Constructor of a JMailSession Object.
59      * @param factoryName the name of the factory.
60      * @param name the jndi name
61      * @param mailProperties properties for configuring this object.
62      */

63     public JavaMailSession(String JavaDoc factoryName, String JavaDoc name, Properties JavaDoc mailProperties) {
64         super(factoryName, name, mailProperties);
65     }
66
67     /**
68      * Return the type of the factory
69      * @return the type of the mail factory
70      */

71     public String JavaDoc getType() {
72         return FACTORY_TYPE;
73     }
74
75     /**
76      * Retrieves the Reference of the javax.mail.Session object.
77      * The Reference contains the factory used to create this object
78      * (that is the JavaMailSessionFactory) and the optional parameters used to
79      * configure the factory.
80      * @return the non-null Reference of the javax.mail.Session object.
81      * @throws NamingException if a naming exception was encountered while
82      * retrieving the reference.
83      */

84     public Reference JavaDoc getReference() throws NamingException JavaDoc {
85
86        //Build the reference to the factory JMailSessionFactory
87
Reference JavaDoc reference = new Reference JavaDoc(FACTORY_TYPE,
88                                             "org.objectweb.jonas.mail.factory.JavaMailSessionFactory",
89                                             null);
90         if (getLogger().isLoggable(BasicLevel.DEBUG)) {
91             PropDump.print("Here are these properties:", getMailSessionProperties(), getLogger(), BasicLevel.DEBUG);
92         }
93
94         //Give the session properties
95
byte[] bytes = JNDIUtils.getBytesFromObject(getMailSessionProperties());
96         if (bytes != null) {
97             reference.add(new BinaryRefAddr JavaDoc("javaxmailSession.properties", bytes));
98         }
99
100         //Give the authentication properties
101
bytes = JNDIUtils.getBytesFromObject(getAuthenticationProperties());
102         if (bytes != null) {
103             reference.add(new BinaryRefAddr JavaDoc("authentication.properties", bytes));
104         }
105
106         return reference;
107
108     }
109
110
111 }
112
Popular Tags