Source Code Cross Referenced for MailSendException.java in  » J2EE » spring-framework-2.0.6 » org » springframework » mail » 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 » spring framework 2.0.6 » org.springframework.mail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.mail;
018:
019:        import java.io.PrintStream;
020:        import java.io.PrintWriter;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.Map;
024:
025:        /**
026:         * Exception thrown when a mail sending error is encountered.
027:         * Can register failed messages with their exceptions.
028:         *
029:         * @author Dmitriy Kopylenko
030:         * @author Juergen Hoeller
031:         */
032:        public class MailSendException extends MailException {
033:
034:            private Map failedMessages = new HashMap();
035:
036:            /**
037:             * Constructor for MailSendException.
038:             * @param msg the detail message
039:             */
040:            public MailSendException(String msg) {
041:                super (msg);
042:            }
043:
044:            /**
045:             * Constructor for MailSendException.
046:             * @param msg the detail message
047:             * @param cause the root cause from the mail API in use
048:             */
049:            public MailSendException(String msg, Throwable cause) {
050:                super (msg, cause);
051:            }
052:
053:            /**
054:             * Constructor for registration of failed messages, with the
055:             * messages that failed as keys, and the thrown exceptions as values.
056:             * <p>The messages should be the same that were originally passed
057:             * to the invoked send method.
058:             */
059:            public MailSendException(Map failedMessages) {
060:                super (null);
061:                this .failedMessages.putAll(failedMessages);
062:            }
063:
064:            /**
065:             * Return a Map with the failed messages as keys, and the thrown exceptions
066:             * as values. Note that a general mail server connection failure will not
067:             * result in failed messages being returned here: A message will only be
068:             * contained here if actually sending it was attempted but failed.
069:             * <p>The messages will be the same that were originally passed to the
070:             * invoked send method, that is, SimpleMailMessages in case of using
071:             * the generic MailSender interface.
072:             * <p>In case of sending MimeMessage instances via JavaMailSender,
073:             * the messages will be of type MimeMessage.
074:             * @return the Map of failed messages as keys and thrown exceptions as
075:             * values, or an empty Map if no failed messages
076:             * @see SimpleMailMessage
077:             * @see javax.mail.internet.MimeMessage
078:             */
079:            public final Map getFailedMessages() {
080:                return failedMessages;
081:            }
082:
083:            public String getMessage() {
084:                StringBuffer sb = new StringBuffer();
085:                String super Msg = super .getMessage();
086:                sb.append(super Msg != null ? super Msg : "Failed messages: ");
087:                for (Iterator subExs = getFailedMessages().values().iterator(); subExs
088:                        .hasNext();) {
089:                    Throwable subEx = (Throwable) subExs.next();
090:                    sb.append(subEx.toString());
091:                    if (subExs.hasNext()) {
092:                        sb.append("; ");
093:                    }
094:                }
095:                return sb.toString();
096:            }
097:
098:            public String toString() {
099:                StringBuffer sb = new StringBuffer();
100:                sb.append(getClass().getName()).append("; nested exceptions (");
101:                sb.append(getFailedMessages().size()).append(") are:");
102:                int i = 0;
103:                for (Iterator subExs = getFailedMessages().values().iterator(); subExs
104:                        .hasNext();) {
105:                    Throwable subEx = (Throwable) subExs.next();
106:                    i++;
107:                    sb.append('\n').append("Failed message ").append(i).append(
108:                            ": ");
109:                    sb.append(subEx);
110:                }
111:                return sb.toString();
112:            }
113:
114:            public void printStackTrace(PrintStream ps) {
115:                if (getFailedMessages().isEmpty()) {
116:                    super .printStackTrace(ps);
117:                } else {
118:                    ps.println(getClass().getName()
119:                            + "; nested exception details ("
120:                            + getFailedMessages().size() + ") are:");
121:                    int i = 0;
122:                    for (Iterator subExs = getFailedMessages().values()
123:                            .iterator(); subExs.hasNext();) {
124:                        Throwable subEx = (Throwable) subExs.next();
125:                        i++;
126:                        ps.println("Failed message " + i + ":");
127:                        subEx.printStackTrace(ps);
128:                    }
129:                }
130:            }
131:
132:            public void printStackTrace(PrintWriter pw) {
133:                if (getFailedMessages().isEmpty()) {
134:                    super .printStackTrace(pw);
135:                } else {
136:                    pw.println(getClass().getName()
137:                            + "; nested exception details ("
138:                            + getFailedMessages().size() + ") are:");
139:                    int i = 0;
140:                    for (Iterator subExs = getFailedMessages().values()
141:                            .iterator(); subExs.hasNext();) {
142:                        Throwable subEx = (Throwable) subExs.next();
143:                        i++;
144:                        pw.println("Failed message " + i + ":");
145:                        subEx.printStackTrace(pw);
146:                    }
147:                }
148:            }
149:
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.