View Javadoc

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