001 /**
002 *
003 * Copyright 2003-2004 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package javax.mail.event;
019
020 import javax.mail.Address;
021 import javax.mail.Message;
022 import javax.mail.Transport;
023
024 /**
025 * @version $Rev: 125583 $ $Date: 2005-01-18 19:44:27 -0800 (Tue, 18 Jan 2005) $
026 */
027 public class TransportEvent extends MailEvent {
028 /**
029 * Indicates that the message has successfully been delivered to all
030 * recipients.
031 */
032 public static final int MESSAGE_DELIVERED = 1;
033
034 /**
035 * Indicates that no messages could be delivered.
036 */
037 public static final int MESSAGE_NOT_DELIVERED = 2;
038
039 /**
040 * Indicates that some of the messages were successfully delivered
041 * but that some failed.
042 */
043 public static final int MESSAGE_PARTIALLY_DELIVERED = 3;
044
045 /**
046 * The event type.
047 */
048 protected int type;
049
050 /**
051 * Addresses to which the message was successfully delivered.
052 */
053 protected transient Address[] validSent;
054
055 /**
056 * Addresses which are valid but to which the message was not sent.
057 */
058 protected transient Address[] validUnsent;
059
060 /**
061 * Addresses that are invalid.
062 */
063 protected transient Address[] invalid;
064
065 /**
066 * The message associated with this event.
067 */
068 protected transient Message msg;
069
070 /**
071 * Construct a new event,
072 *
073 * @param transport the transport attempting to deliver the message
074 * @param type the event type
075 * @param validSent addresses to which the message was successfully delivered
076 * @param validUnsent addresses which are valid but to which the message was not sent
077 * @param invalid invalid addresses
078 * @param message the associated message
079 */
080 public TransportEvent(Transport transport, int type, Address[] validSent, Address[] validUnsent, Address[] invalid, Message message) {
081 super(transport);
082 this.type = type;
083 this.validSent = validSent;
084 this.validUnsent = validUnsent;
085 this.invalid = invalid;
086 this.msg = message;
087 }
088
089 public Address[] getValidSentAddresses() {
090 return validSent;
091 }
092
093 public Address[] getValidUnsentAddresses() {
094 return validUnsent;
095 }
096
097 public Address[] getInvalidAddresses() {
098 return invalid;
099 }
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 }