1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 /*
38 * @(#)TransportEvent.java 1.14 07/05/04
39 */
40
41 package javax.mail.event;
42
43 import java.util;
44 import javax.mail;
45
46 /**
47 * This class models Transport events.
48 *
49 * @author John Mani
50 * @author Max Spivak
51 *
52 * @see javax.mail.Transport
53 * @see javax.mail.event.TransportListener
54 */
55
56 public class TransportEvent extends MailEvent {
57
58 /**
59 * Message has been successfully delivered to all recipients by the
60 * transport firing this event. validSent[] contains all the addresses
61 * this transport sent to successfully. validUnsent[] and invalid[]
62 * should be null,
63 */
64 public static final int MESSAGE_DELIVERED = 1;
65
66 /**
67 * Message was not sent for some reason. validSent[] should be null.
68 * validUnsent[] may have addresses that are valid (but the message
69 * wasn't sent to them). invalid[] should likely contain invalid addresses.
70 */
71 public static final int MESSAGE_NOT_DELIVERED = 2;
72
73 /**
74 * Message was successfully sent to some recipients but not to all.
75 * validSent[] holds addresses of recipients to whom the message was sent.
76 * validUnsent[] holds valid addresses to which the message was not sent.
77 * invalid[] holds invalid addresses, if any.
78 */
79 public static final int MESSAGE_PARTIALLY_DELIVERED = 3;
80
81
82 /**
83 * The event type.
84 *
85 * @serial
86 */
87 protected int type;
88
89 transient protected Address[] validSent;
90 transient protected Address[] validUnsent;
91 transient protected Address[] invalid;
92 transient protected Message msg;
93
94 private static final long serialVersionUID = -4729852364684273073L;
95
96 /**
97 * Constructor.
98 * @param transport The Transport object
99 */
100 public TransportEvent(Transport transport, int type, Address[] validSent,
101 Address[] validUnsent, Address[] invalid,
102 Message msg) {
103 super(transport);
104 this.type = type;
105 this.validSent = validSent;
106 this.validUnsent = validUnsent;
107 this.invalid = invalid;
108 this.msg = msg;
109 }
110
111 /**
112 * Return the type of this event.
113 * @return type
114 */
115 public int getType() {
116 return type;
117 }
118
119 /**
120 * Return the addresses to which this message was sent succesfully.
121 * @return Addresses to which the message was sent successfully or null
122 */
123 public Address[] getValidSentAddresses() {
124 return validSent;
125 }
126
127 /**
128 * Return the addresses that are valid but to which this message
129 * was not sent.
130 * @return Addresses that are valid but to which the message was
131 * not sent successfully or null
132 */
133 public Address[] getValidUnsentAddresses() {
134 return validUnsent;
135 }
136
137 /**
138 * Return the addresses to which this message could not be sent.
139 * @return Addresses to which the message sending failed or null
140 */
141 public Address[] getInvalidAddresses() {
142 return invalid;
143 }
144
145 /**
146 * Get the Message object associated with this Transport Event.
147 *
148 * @return the Message object
149 * @since JavaMail 1.2
150 */
151 public Message getMessage() {
152 return msg;
153 }
154
155 /**
156 * Invokes the appropriate TransportListener method.
157 */
158 public void dispatch(Object listener) {
159 if (type == MESSAGE_DELIVERED)
160 ((TransportListener)listener).messageDelivered(this);
161 else if (type == MESSAGE_NOT_DELIVERED)
162 ((TransportListener)listener).messageNotDelivered(this);
163 else // MESSAGE_PARTIALLY_DELIVERED
164 ((TransportListener)listener).messagePartiallyDelivered(this);
165 }
166 }