KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > event > TransportEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)TransportEvent.java 1.13 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.event;
29
30 import java.util.*;
31 import javax.mail.*;
32
33 /**
34  * This class models Transport events.
35  *
36  * @author John Mani
37  * @author Max Spivak
38  *
39  * @see javax.mail.Transport
40  * @see javax.mail.event.TransportListener
41  */

42
43 public class TransportEvent extends MailEvent JavaDoc {
44
45     /**
46      * Message has been successfully delivered to all recipients by the
47      * transport firing this event. validSent[] contains all the addresses
48      * this transport sent to successfully. validUnsent[] and invalid[]
49      * should be null,
50      */

51     public static final int MESSAGE_DELIVERED = 1;
52
53     /**
54      * Message was not sent for some reason. validSent[] should be null.
55      * validUnsent[] may have addresses that are valid (but the message
56      * wasn't sent to them). invalid[] should likely contain invalid addresses.
57      */

58     public static final int MESSAGE_NOT_DELIVERED = 2;
59
60     /**
61      * Message was successfully sent to some recipients but not to all.
62      * validSent[] holds addresses of recipients to whom the message was sent.
63      * validUnsent[] holds valid addresses to which the message was not sent.
64      * invalid[] holds invalid addresses, if any.
65      */

66     public static final int MESSAGE_PARTIALLY_DELIVERED = 3;
67
68
69     /**
70      * The event type.
71      *
72      * @serial
73      */

74     protected int type;
75
76     transient protected Address[] validSent;
77     transient protected Address[] validUnsent;
78     transient protected Address[] invalid;
79     transient protected Message msg;
80
81     private static final long serialVersionUID = -4729852364684273073L;
82
83     /**
84      * Constructor.
85      * @param transport The Transport object
86      */

87     public TransportEvent(Transport transport, int type, Address[] validSent,
88               Address[] validUnsent, Address[] invalid,
89               Message msg) {
90     super(transport);
91     this.type = type;
92     this.validSent = validSent;
93     this.validUnsent = validUnsent;
94     this.invalid = invalid;
95     this.msg = msg;
96     }
97
98     /**
99      * Return the type of this event.
100      * @return type
101      */

102     public int getType() {
103     return type;
104     }
105
106     /**
107      * Return the addresses to which this message was sent succesfully.
108      * @return Addresses to which the message was sent successfully or null
109      */

110     public Address[] getValidSentAddresses() {
111     return validSent;
112     }
113
114     /**
115      * Return the addresses that are valid but to which this message
116      * was not sent.
117      * @return Addresses that are valid but to which the message was
118      * not sent successfully or null
119      */

120     public Address[] getValidUnsentAddresses() {
121     return validUnsent;
122     }
123
124     /**
125      * Return the addresses to which this message could not be sent.
126      * @return Addresses to which the message sending failed or null
127      */

128     public Address[] getInvalidAddresses() {
129     return invalid;
130     }
131
132     /**
133      * Get the Message object associated with this Transport Event.
134      *
135      * @return the Message object
136      * @since JavaMail 1.2
137      */

138     public Message getMessage() {
139         return msg;
140     }
141
142     /**
143      * Invokes the appropriate TransportListener method.
144      */

145     public void dispatch(Object JavaDoc listener) {
146     if (type == MESSAGE_DELIVERED)
147         ((TransportListener JavaDoc)listener).messageDelivered(this);
148     else if (type == MESSAGE_NOT_DELIVERED)
149         ((TransportListener JavaDoc)listener).messageNotDelivered(this);
150     else // MESSAGE_PARTIALLY_DELIVERED
151
((TransportListener JavaDoc)listener).messagePartiallyDelivered(this);
152     }
153 }
154
Popular Tags