001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * @(#)MessageCountEvent.java 1.11 07/05/04
039: */
040:
041: package javax.mail.event;
042:
043: import java.util.*;
044: import javax.mail.*;
045:
046: /**
047: * This class notifies changes in the number of messages in a folder. <p>
048: *
049: * Note that some folder types may only deliver MessageCountEvents at
050: * certain times or after certain operations. IMAP in particular will
051: * only notify the client of MessageCountEvents when a client issues a
052: * new command.
053: * Refer to RFC 2060 <A HREF="http://www.ietf.org/rfc/rfc2060.txt">
054: * http://www.ietf.org/rfc/rfc2060.txt</A> for details.
055: * A client may want "poll" the folder by occasionally calling the
056: * <code>getMessageCount</code> or <code>isConnected</code> methods
057: * to solicit any such notifications.
058: *
059: * @author John Mani
060: */
061:
062: public class MessageCountEvent extends MailEvent {
063:
064: /** The messages were added to their folder */
065: public static final int ADDED = 1;
066: /** The messages were removed from their folder */
067: public static final int REMOVED = 2;
068:
069: /**
070: * The event type.
071: *
072: * @serial
073: */
074: protected int type;
075:
076: /**
077: * If true, this event is the result of an explicit
078: * expunge by this client, and the messages in this
079: * folder have been renumbered to account for this.
080: * If false, this event is the result of an expunge
081: * by external sources.
082: *
083: * @serial
084: */
085: protected boolean removed;
086:
087: /**
088: * The messages.
089: */
090: transient protected Message[] msgs;
091:
092: private static final long serialVersionUID = -7447022340837897369L;
093:
094: /**
095: * Constructor.
096: * @param folder The containing folder
097: * @param type The event type
098: * @param removed If true, this event is the result of an explicit
099: * expunge by this client, and the messages in this
100: * folder have been renumbered to account for this.
101: * If false, this event is the result of an expunge
102: * by external sources.
103: *
104: * @param msgs The messages added/removed
105: */
106: public MessageCountEvent(Folder folder, int type, boolean removed,
107: Message[] msgs) {
108: super (folder);
109: this .type = type;
110: this .removed = removed;
111: this .msgs = msgs;
112: }
113:
114: /**
115: * Return the type of this event.
116: * @return type
117: */
118: public int getType() {
119: return type;
120: }
121:
122: /**
123: * Indicates whether this event is the result of an explicit
124: * expunge by this client, or due to an expunge from external
125: * sources. If <code>true</code>, this event is due to an
126: * explicit expunge and hence all remaining messages in this
127: * folder have been renumbered. If <code>false</code>, this event
128: * is due to an external expunge. <p>
129: *
130: * Note that this method is valid only if the type of this event
131: * is <code>REMOVED</code>
132: */
133: public boolean isRemoved() {
134: return removed;
135: }
136:
137: /**
138: * Return the array of messages added or removed.
139: * @return array of messages
140: */
141: public Message[] getMessages() {
142: return msgs;
143: }
144:
145: /**
146: * Invokes the appropriate MessageCountListener method.
147: */
148: public void dispatch(Object listener) {
149: if (type == ADDED)
150: ((MessageCountListener) listener).messagesAdded(this );
151: else
152: // REMOVED
153: ((MessageCountListener) listener).messagesRemoved(this);
154: }
155: }
|