01: /**
02: * EasyBeans
03: * Copyright (C) 2007 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: * --------------------------------------------------------------------------
22: * $Id: JavaMailSessionFactory.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.component.mail.factory;
25:
26: import java.util.Hashtable;
27:
28: import javax.mail.Session;
29: import javax.naming.Context;
30: import javax.naming.Name;
31: import javax.naming.Reference;
32: import javax.naming.spi.ObjectFactory;
33:
34: /**
35: * JNDI factory for session factory.
36: * @author Florent BENOIT
37: */
38: public class JavaMailSessionFactory extends AbsJavaMailFactory
39: implements ObjectFactory {
40:
41: /**
42: * Type of object created by this factory.
43: */
44: public static final String FACTORY_TYPE = "javax.mail.Session";
45:
46: /**
47: * Creates an object using the location or reference information specified.
48: * @param obj The possibly null object containing location or reference
49: * information that can be used in creating an object.
50: * @param name The name of this object relative to <code>nameCtx</code>,
51: * or null if no name is specified.
52: * @param nameCtx The context relative to which the <code>name</code>
53: * parameter is specified, or null if <code>name</code> is relative
54: * to the default initial context.
55: * @param environment The possibly null environment that is used in creating
56: * the object.
57: * @return The object created; null if an object cannot be created.
58: * @exception Exception if this object factory encountered an exception
59: */
60: public Object getObjectInstance(final Object obj, final Name name,
61: final Context nameCtx, final Hashtable<?, ?> environment)
62: throws Exception {
63:
64: // Check if the reference classname is valid
65: Reference reference = (Reference) obj;
66: if (!FACTORY_TYPE.equals(reference.getClassName())) {
67: return null;
68: }
69:
70: // Create and return a new Session object
71: Session session = Session.getInstance(
72: getSessionProperties(reference),
73: getAuthenticator(reference));
74:
75: return session;
76: }
77:
78: }
|