Source Code Cross Referenced for MailSessionReference.java in  » Sevlet-Container » jetty-modules » org » mortbay » naming » factories » 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 » Sevlet Container » jetty modules » org.mortbay.naming.factories 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // $Id: MailSessionReference.java 1386 2006-12-08 17:53:22Z janb $
003:        // Copyright 1999-2004 Mort Bay Consulting Pty. Ltd.
004:        // ------------------------------------------------------------------------
005:        // Licensed under the Apache License, Version 2.0 (the "License");
006:        // you may not use this file except in compliance with the License.
007:        // You may obtain a copy of the License at 
008:        // http://www.apache.org/licenses/LICENSE-2.0
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:        // ========================================================================
015:
016:        package org.mortbay.naming.factories;
017:
018:        import javax.mail.Authenticator;
019:        import javax.mail.PasswordAuthentication;
020:        import javax.mail.Session;
021:
022:        import java.util.Enumeration;
023:        import java.util.Hashtable;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:        import java.util.Properties;
027:
028:        import javax.naming.Context;
029:        import javax.naming.Name;
030:        import javax.naming.NamingException;
031:        import javax.naming.RefAddr;
032:        import javax.naming.Reference;
033:        import javax.naming.Referenceable;
034:        import javax.naming.StringRefAddr;
035:        import javax.naming.spi.ObjectFactory;
036:
037:        import org.mortbay.jetty.security.Password;
038:
039:        /**
040:         * MailSessionReference
041:         * 
042:         * This is a subclass of javax.mail.Reference and an ObjectFactory for javax.mail.Session objects.
043:         * 
044:         * The subclassing of Reference allows all of the setup for a javax.mail.Session
045:         * to be captured without necessitating first instantiating a Session object. The
046:         * reference is bound into JNDI and it is only when the reference is looked up that
047:         * this object factory will create an instance of javax.mail.Session using the
048:         * information captured in the Reference.
049:         *
050:         */
051:        public class MailSessionReference extends Reference implements 
052:                ObjectFactory {
053:
054:            public static class PasswordAuthenticator extends Authenticator {
055:                PasswordAuthentication passwordAuthentication;
056:                private String user;
057:                private String password;
058:
059:                public PasswordAuthenticator() {
060:
061:                }
062:
063:                public PasswordAuthenticator(String user, String password) {
064:                    passwordAuthentication = new PasswordAuthentication(
065:                            user,
066:                            (password.startsWith(Password.__OBFUSCATE) ? Password
067:                                    .deobfuscate(password)
068:                                    : password));
069:                }
070:
071:                public PasswordAuthentication getPasswordAuthentication() {
072:                    return passwordAuthentication;
073:                }
074:
075:                public void setUser(String user) {
076:                    this .user = user;
077:                }
078:
079:                public String getUser() {
080:                    return this .user;
081:                }
082:
083:                public String getPassword() {
084:                    return this .password;
085:                }
086:
087:                public void setPassword(String password) {
088:                    this .password = password;
089:                }
090:
091:            };
092:
093:            /**
094:             * 
095:             */
096:            public MailSessionReference() {
097:                super ("javax.mail.Session", MailSessionReference.class
098:                        .getName(), null);
099:            }
100:
101:            /** 
102:             * Create a javax.mail.Session instance based on the information passed in the Reference
103:             * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
104:             * @param ref the Reference
105:             * @param arg1 not used
106:             * @param arg2 not used
107:             * @param arg3 not used
108:             * @return
109:             * @throws Exception
110:             */
111:            public Object getObjectInstance(Object ref, Name arg1,
112:                    Context arg2, Hashtable arg3) throws Exception {
113:                if (ref == null)
114:                    return null;
115:
116:                Reference reference = (Reference) ref;
117:
118:                Properties props = new Properties();
119:                String user = null;
120:                String password = null;
121:
122:                Enumeration refs = reference.getAll();
123:                while (refs.hasMoreElements()) {
124:                    RefAddr refAddr = (RefAddr) refs.nextElement();
125:                    String name = refAddr.getType();
126:                    String value = (String) refAddr.getContent();
127:                    if (name.equalsIgnoreCase("user"))
128:                        user = value;
129:                    else if (name.equalsIgnoreCase("pwd"))
130:                        password = value;
131:                    else
132:                        props.put(name, value);
133:                }
134:
135:                if (password == null)
136:                    return Session.getInstance(props);
137:                else
138:                    return Session.getInstance(props,
139:                            new PasswordAuthenticator(user, password));
140:            }
141:
142:            public void setUser(String user) {
143:                StringRefAddr addr = (StringRefAddr) get("user");
144:                if (addr != null) {
145:                    throw new RuntimeException(
146:                            "user already set on SessionReference, can't be changed");
147:                }
148:                add(new StringRefAddr("user", user));
149:            }
150:
151:            public void setPassword(String password) {
152:                StringRefAddr addr = (StringRefAddr) get("pwd");
153:                if (addr != null)
154:                    throw new RuntimeException(
155:                            "password already set on SessionReference, can't be changed");
156:                add(new StringRefAddr("pwd", password));
157:            }
158:
159:            public void setProperties(Properties properties) {
160:                Iterator entries = properties.entrySet().iterator();
161:                while (entries.hasNext()) {
162:                    Map.Entry e = (Map.Entry) entries.next();
163:                    StringRefAddr sref = (StringRefAddr) get((String) e
164:                            .getKey());
165:                    if (sref != null)
166:                        throw new RuntimeException(
167:                                "property "
168:                                        + e.getKey()
169:                                        + " already set on Session reference, can't be changed");
170:                    add(new StringRefAddr((String) e.getKey(), (String) e
171:                            .getValue()));
172:                }
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.