Save This Page
Home » glassfish-v2ur2-b04-src » javax » mail » event » [javadoc | source]
    1   /*
    2    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    3    *
    4    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    5    *
    6    * The contents of this file are subject to the terms of either the GNU
    7    * General Public License Version 2 only ("GPL") or the Common Development
    8    * and Distribution License("CDDL") (collectively, the "License").  You
    9    * may not use this file except in compliance with the License. You can obtain
   10    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   11    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   12    * language governing permissions and limitations under the License.
   13    *
   14    * When distributing the software, include this License Header Notice in each
   15    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   16    * Sun designates this particular file as subject to the "Classpath" exception
   17    * as provided by Sun in the GPL Version 2 section of the License file that
   18    * accompanied this code.  If applicable, add the following below the License
   19    * Header, with the fields enclosed by brackets [] replaced by your own
   20    * identifying information: "Portions Copyrighted [year]
   21    * [name of copyright owner]"
   22    *
   23    * Contributor(s):
   24    *
   25    * If you wish your version of this file to be governed by only the CDDL or
   26    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   27    * elects to include this software in this distribution under the [CDDL or GPL
   28    * Version 2] license."  If you don't indicate a single choice of license, a
   29    * recipient has the option to distribute your version of this file under
   30    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   31    * its licensees as provided above.  However, if you add GPL Version 2 code
   32    * and therefore, elected the GPL Version 2 license, then the option applies
   33    * only if the new code is made subject to such option by the copyright
   34    * holder.
   35    */
   36   
   37   /*
   38    * @(#)MessageCountEvent.java	1.11 07/05/04
   39    */
   40   
   41   package javax.mail.event;
   42   
   43   import java.util;
   44   import javax.mail;
   45   
   46   /**
   47    * This class notifies changes in the number of messages in a folder. <p>
   48    *
   49    * Note that some folder types may only deliver MessageCountEvents at
   50    * certain times or after certain operations.  IMAP in particular will
   51    * only notify the client of MessageCountEvents when a client issues a
   52    * new command.
   53    * Refer to RFC 2060 <A HREF="http://www.ietf.org/rfc/rfc2060.txt">
   54    * http://www.ietf.org/rfc/rfc2060.txt</A> for details.
   55    * A client may want "poll" the folder by occasionally calling the
   56    * <code>getMessageCount</code> or <code>isConnected</code> methods
   57    * to solicit any such notifications.
   58    *
   59    * @author John Mani
   60    */
   61   
   62   public class MessageCountEvent extends MailEvent {
   63   
   64       /** The messages were added to their folder */
   65       public static final int ADDED 		= 1;
   66       /** The messages were removed from their folder */
   67       public static final int REMOVED 		= 2;
   68   
   69       /**
   70        * The event type.
   71        *
   72        * @serial
   73        */
   74       protected int type;
   75   
   76       /**
   77        * If true, this event is the result of an explicit
   78        * expunge by this client, and the messages in this 
   79        * folder have been renumbered to account for this.
   80        * If false, this event is the result of an expunge
   81        * by external sources.
   82        *
   83        * @serial
   84        */
   85       protected boolean removed;
   86   
   87       /**
   88        * The messages.
   89        */
   90       transient protected Message[] msgs;
   91   
   92       private static final long serialVersionUID = -7447022340837897369L;
   93   
   94       /**
   95        * Constructor.
   96        * @param folder  	The containing folder
   97        * @param type	The event type
   98        * @param removed	If true, this event is the result of an explicit
   99        *			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, 
  107   			     boolean removed, 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 // REMOVED
  152   	    ((MessageCountListener)listener).messagesRemoved(this);
  153       }
  154   }

Save This Page
Home » glassfish-v2ur2-b04-src » javax » mail » event » [javadoc | source]