KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > event > MessageCountEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)MessageCountEvent.java 1.10 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.event;
29
30 import java.util.*;
31 import javax.mail.*;
32
33 /**
34  * This class notifies changes in the number of messages in a folder. <p>
35  *
36  * Note that some folder types may only deliver MessageCountEvents at
37  * certain times or after certain operations. IMAP in particular will
38  * only notify the client of MessageCountEvents when a client issues a
39  * new command.
40  * Refer to RFC 2060 <A HREF="http://www.ietf.org/rfc/rfc2060.txt">
41  * http://www.ietf.org/rfc/rfc2060.txt</A> for details.
42  * A client may want "poll" the folder by occasionally calling the
43  * <code>getMessageCount</code> or <code>isConnected</code> methods
44  * to solicit any such notifications.
45  *
46  * @author John Mani
47  */

48
49 public class MessageCountEvent extends MailEvent JavaDoc {
50
51     /** The messages were added to their folder */
52     public static final int ADDED = 1;
53     /** The messages were removed from their folder */
54     public static final int REMOVED = 2;
55
56     /**
57      * The event type.
58      *
59      * @serial
60      */

61     protected int type;
62
63     /**
64      * If true, this event is the result of an explicit
65      * expunge by this client, and the messages in this
66      * folder have been renumbered to account for this.
67      * If false, this event is the result of an expunge
68      * by external sources.
69      *
70      * @serial
71      */

72     protected boolean removed;
73
74     /**
75      * The messages.
76      */

77     transient protected Message[] msgs;
78
79     private static final long serialVersionUID = -7447022340837897369L;
80
81     /**
82      * Constructor.
83      * @param folder The containing folder
84      * @param type The event type
85      * @param removed If true, this event is the result of an explicit
86      * expunge by this client, and the messages in this
87      * folder have been renumbered to account for this.
88      * If false, this event is the result of an expunge
89      * by external sources.
90      *
91      * @param msgs The messages added/removed
92      */

93     public MessageCountEvent(Folder folder, int type,
94                  boolean removed, Message[] msgs) {
95     super(folder);
96     this.type = type;
97     this.removed = removed;
98     this.msgs = msgs;
99     }
100
101     /**
102      * Return the type of this event.
103      * @return type
104      */

105     public int getType() {
106     return type;
107     }
108
109     /**
110      * Indicates whether this event is the result of an explicit
111      * expunge by this client, or due to an expunge from external
112      * sources. If <code>true</code>, this event is due to an
113      * explicit expunge and hence all remaining messages in this
114      * folder have been renumbered. If <code>false</code>, this event
115      * is due to an external expunge. <p>
116      *
117      * Note that this method is valid only if the type of this event
118      * is <code>REMOVED</code>
119      */

120     public boolean isRemoved() {
121     return removed;
122     }
123
124     /**
125      * Return the array of messages added or removed.
126      * @return array of messages
127      */

128     public Message[] getMessages() {
129     return msgs;
130     }
131
132     /**
133      * Invokes the appropriate MessageCountListener method.
134      */

135     public void dispatch(Object JavaDoc listener) {
136     if (type == ADDED)
137         ((MessageCountListener JavaDoc)listener).messagesAdded(this);
138     else // REMOVED
139
((MessageCountListener JavaDoc)listener).messagesRemoved(this);
140     }
141 }
142
Popular Tags