001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package javax.mail.event; 021 022 import javax.mail.Address; 023 import javax.mail.Message; 024 import javax.mail.Transport; 025 026 /** 027 * @version $Rev: 920714 $ $Date: 2010-03-09 01:55:49 -0500 (Tue, 09 Mar 2010) $ 028 */ 029 public class TransportEvent extends MailEvent { 030 031 private static final long serialVersionUID = -4729852364684273073L; 032 033 /** 034 * Indicates that the message has successfully been delivered to all 035 * recipients. 036 */ 037 public static final int MESSAGE_DELIVERED = 1; 038 039 /** 040 * Indicates that no messages could be delivered. 041 */ 042 public static final int MESSAGE_NOT_DELIVERED = 2; 043 044 /** 045 * Indicates that some of the messages were successfully delivered 046 * but that some failed. 047 */ 048 public static final int MESSAGE_PARTIALLY_DELIVERED = 3; 049 050 /** 051 * The event type. 052 */ 053 protected int type; 054 055 /** 056 * Addresses to which the message was successfully delivered. 057 */ 058 protected transient Address[] validSent; 059 060 /** 061 * Addresses which are valid but to which the message was not sent. 062 */ 063 protected transient Address[] validUnsent; 064 065 /** 066 * Addresses that are invalid. 067 */ 068 protected transient Address[] invalid; 069 070 /** 071 * The message associated with this event. 072 */ 073 protected transient Message msg; 074 075 /** 076 * Construct a new event, 077 * 078 * @param transport the transport attempting to deliver the message 079 * @param type the event type 080 * @param validSent addresses to which the message was successfully delivered 081 * @param validUnsent addresses which are valid but to which the message was not sent 082 * @param invalid invalid addresses 083 * @param message the associated message 084 */ 085 public TransportEvent(Transport transport, int type, Address[] validSent, Address[] validUnsent, Address[] invalid, Message message) { 086 super(transport); 087 this.type = type; 088 this.validSent = validSent; 089 this.validUnsent = validUnsent; 090 this.invalid = invalid; 091 this.msg = message; 092 } 093 094 public Address[] getValidSentAddresses() { 095 return validSent; 096 } 097 098 public Address[] getValidUnsentAddresses() { 099 return validUnsent; 100 } 101 102 public Address[] getInvalidAddresses() { 103 return invalid; 104 } 105 106 public Message getMessage() { 107 return msg; 108 } 109 110 public int getType() { 111 return type; 112 } 113 114 public void dispatch(Object listener) { 115 TransportListener l = (TransportListener) listener; 116 switch (type) { 117 case MESSAGE_DELIVERED: 118 l.messageDelivered(this); 119 break; 120 case MESSAGE_NOT_DELIVERED: 121 l.messageNotDelivered(this); 122 break; 123 case MESSAGE_PARTIALLY_DELIVERED: 124 l.messagePartiallyDelivered(this); 125 break; 126 default: 127 throw new IllegalArgumentException("Invalid type " + type); 128 } 129 } 130 }