View Javadoc

1   /**
2    *
3    * Copyright 2003-2006 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package javax.mail.event;
19  
20  import javax.mail.Address;
21  import javax.mail.Message;
22  import javax.mail.Transport;
23  
24  /**
25   * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $
26   */
27  public class TransportEvent extends MailEvent {
28      /**
29       * Indicates that the message has successfully been delivered to all
30       * recipients.
31       */
32      public static final int MESSAGE_DELIVERED = 1;
33  
34      /**
35       * Indicates that no messages could be delivered.
36       */
37      public static final int MESSAGE_NOT_DELIVERED = 2;
38  
39      /**
40       * Indicates that some of the messages were successfully delivered
41       * but that some failed.
42       */
43      public static final int MESSAGE_PARTIALLY_DELIVERED = 3;
44  
45      /**
46       * The event type.
47       */
48      protected int type;
49  
50      /**
51       * Addresses to which the message was successfully delivered.
52       */
53      protected transient Address[] validSent;
54  
55      /**
56       * Addresses which are valid but to which the message was not sent.
57       */
58      protected transient Address[] validUnsent;
59  
60      /**
61       * Addresses that are invalid.
62       */
63      protected transient Address[] invalid;
64  
65      /**
66       * The message associated with this event.
67       */
68      protected transient Message msg;
69  
70      /**
71       * Construct a new event,
72       *
73       * @param transport   the transport attempting to deliver the message
74       * @param type        the event type
75       * @param validSent   addresses to which the message was successfully delivered
76       * @param validUnsent addresses which are valid but to which the message was not sent
77       * @param invalid     invalid addresses
78       * @param message     the associated message
79       */
80      public TransportEvent(Transport transport, int type, Address[] validSent, Address[] validUnsent, Address[] invalid, Message message) {
81          super(transport);
82          this.type = type;
83          this.validSent = validSent;
84          this.validUnsent = validUnsent;
85          this.invalid = invalid;
86          this.msg = message;
87      }
88  
89      public Address[] getValidSentAddresses() {
90          return validSent;
91      }
92  
93      public Address[] getValidUnsentAddresses() {
94          return validUnsent;
95      }
96  
97      public Address[] getInvalidAddresses() {
98          return invalid;
99      }
100 
101     public Message getMessage() {
102         return msg;
103     }
104 
105     public int getType() {
106         return type;
107     }
108 
109     public void dispatch(Object listener) {
110         TransportListener l = (TransportListener) listener;
111         switch (type) {
112         case MESSAGE_DELIVERED:
113             l.messageDelivered(this);
114             break;
115         case MESSAGE_NOT_DELIVERED:
116             l.messageNotDelivered(this);
117             break;
118         case MESSAGE_PARTIALLY_DELIVERED:
119             l.messagePartiallyDelivered(this);
120             break;
121         default:
122             throw new IllegalArgumentException("Invalid type " + type);
123         }
124     }
125 }