Source Code Cross Referenced for JavaMailSessionFactory.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » mail » factory » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.mail.factory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: JavaMailSessionFactory.java 7668 2005-11-16 09:22:33Z durieuxp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.mail.factory;
025:
026:        //import java
027:        import java.util.Hashtable;
028:        import java.util.Properties;
029:
030:        import javax.mail.Session;
031:        import javax.naming.Context;
032:        import javax.naming.Name;
033:        import javax.naming.RefAddr;
034:        import javax.naming.Reference;
035:        import javax.naming.spi.ObjectFactory;
036:
037:        import org.objectweb.jonas.common.JNDIUtils;
038:        import org.objectweb.jonas.common.Log;
039:        import org.objectweb.jonas.common.PropDump;
040:        import org.objectweb.jonas.mail.lib.JAuthenticator;
041:        import org.objectweb.util.monolog.api.BasicLevel;
042:        import org.objectweb.util.monolog.api.Logger;
043:
044:        /**
045:         * This class provides an implementation of a mail session factory for
046:         * sending mail.
047:         * @author Florent Benoit
048:         * @author Ludovic Bert
049:         */
050:        public class JavaMailSessionFactory implements  ObjectFactory {
051:
052:            /**
053:             * The Java type for which this factory knows how to create objects.
054:             */
055:            protected static final String FACTORY_TYPE = "javax.mail.Session";
056:
057:            /**
058:             * The logger used in JOnAS
059:             */
060:            private static Logger logger = null;
061:
062:            /**
063:             * Creates a javax.mail.Session object using the location or reference
064:             * information specified.
065:             * @param obj the possibly null object containing location or reference
066:             * information that can be used in creating an object.
067:             * @param name the name of this object relative to nameCtx, or null if no
068:             * name is specified.
069:             * @param nameCtx the context relative to which the name parameter is
070:             * specified, or null if name is relative to the default initial context.
071:             * @param environment the possibly null environment that is used in
072:             * creating the object.
073:             * @return a newly created javax.mail.Session object with the specific
074:             * configuration; null if an object cannot be created.
075:             * @throws Exception if this object factory encountered an exception
076:             * while attempting to create an object, and no other object factories
077:             * are to be tried.
078:             */
079:            public Object getObjectInstance(Object obj, Name name,
080:                    Context nameCtx, Hashtable environment) throws Exception {
081:
082:                //Get the logger
083:                if (logger == null) {
084:                    logger = Log.getLogger(Log.JONAS_MAIL_PREFIX);
085:                }
086:
087:                //Get the reference
088:                Reference ref = (Reference) obj;
089:
090:                //Get the class name
091:                String clname = ref.getClassName();
092:
093:                //Check the class name
094:                if (!ref.getClassName().equals(FACTORY_TYPE)) {
095:                    logger.log(BasicLevel.ERROR,
096:                            "Cannot create object : required type is '"
097:                                    + FACTORY_TYPE + "', but found type is '"
098:                                    + clname + "'.");
099:                    return (null);
100:                }
101:
102:                Properties props = new Properties();
103:                Properties authenticationProps = new Properties();
104:                RefAddr refAddr = null;
105:
106:                refAddr = ref.get("javaxmailSession.properties");
107:                if (refAddr != null) {
108:                    props = (Properties) JNDIUtils
109:                            .getObjectFromBytes((byte[]) refAddr.getContent());
110:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
111:                        PropDump
112:                                .print(
113:                                        "These are the properties attached to the Reference object used to construct a Session",
114:                                        props, logger, BasicLevel.DEBUG);
115:                    }
116:                }
117:
118:                refAddr = ref.get("authentication.properties");
119:                if (refAddr != null) {
120:                    authenticationProps = (Properties) JNDIUtils
121:                            .getObjectFromBytes((byte[]) refAddr.getContent());
122:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
123:                        PropDump
124:                                .print(
125:                                        "These are the authentication properties used to construct a Authenticator",
126:                                        authenticationProps, logger,
127:                                        BasicLevel.DEBUG);
128:                    }
129:                }
130:
131:                //username (Authentication)
132:                String mailAuthenticationUsername = authenticationProps
133:                        .getProperty("mail.authentication.username");
134:
135:                //Password (Authentication)
136:                String mailAuthenticationPassword = authenticationProps
137:                        .getProperty("mail.authentication.password");
138:
139:                JAuthenticator jAuthenticator = null;
140:                if ((mailAuthenticationUsername != null)
141:                        && (mailAuthenticationPassword != null)) {
142:                    jAuthenticator = new JAuthenticator(
143:                            mailAuthenticationUsername,
144:                            mailAuthenticationPassword);
145:                }
146:
147:                // Create and return a new Session object
148:                Session session = Session.getInstance(props, jAuthenticator);
149:
150:                return (session);
151:            }
152:
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.