1 /**
2 *
3 * Copyright 2003-2004 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.Folder;
21 import javax.mail.Message;
22
23 /**
24 * Event indicating a change in the number of messages in a folder.
25 *
26 * @version $Rev: 125583 $ $Date: 2005-01-18 19:44:27 -0800 (Tue, 18 Jan 2005) $
27 */
28 public class MessageCountEvent extends MailEvent {
29 /**
30 * Messages were added to the folder.
31 */
32 public static final int ADDED = 1;
33
34 /**
35 * Messages were removed from the folder.
36 */
37 public static final int REMOVED = 2;
38
39 /**
40 * The affected messages.
41 */
42 protected transient Message msgs[];
43
44 /**
45 * The event type.
46 */
47 protected int type;
48
49 /**
50 * If true, then messages were expunged from the folder by this client
51 * and message numbers reflect the deletion; if false, then the change
52 * was the result of an expunge by a different client.
53 */
54 protected boolean removed;
55
56 /**
57 * Construct a new event.
58 *
59 * @param folder the folder containing the messages
60 * @param type the event type
61 * @param removed indicator of whether messages were expunged by this client
62 * @param messages the affected messages
63 */
64 public MessageCountEvent(Folder folder, int type, boolean removed, Message messages[]) {
65 super(folder);
66 this.msgs = messages;
67 this.type = type;
68 this.removed = removed;
69 }
70
71 /**
72 * Return the event type.
73 *
74 * @return the event type
75 */
76 public int getType() {
77 return type;
78 }
79
80 /**
81 * @return whether this event was the result of an expunge by this client
82 * @see MessageCountEvent#removed
83 */
84 public boolean isRemoved() {
85 return removed;
86 }
87
88 /**
89 * Return the affected messages.
90 *
91 * @return the affected messages
92 */
93 public Message[] getMessages() {
94 return msgs;
95 }
96
97 public void dispatch(Object listener) {
98 MessageCountListener l = (MessageCountListener) listener;
99 switch (type) {
100 case ADDED:
101 l.messagesAdded(this);
102 break;
103 case REMOVED:
104 l.messagesRemoved(this);
105 break;
106 default:
107 throw new IllegalArgumentException("Invalid type " + type);
108 }
109 }
110 }