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 * @(#)FolderEvent.java 1.13 07/05/04
39 */
40
41 package javax.mail.event;
42
43 import java.util;
44 import javax.mail;
45
46 /**
47 * This class models Folder <em>existence</em> events. FolderEvents are
48 * delivered to FolderListeners registered on the affected Folder as
49 * well as the containing Store. <p>
50 *
51 * Service providers vary widely in their ability to notify clients of
52 * these events. At a minimum, service providers must notify listeners
53 * registered on the same Store or Folder object on which the operation
54 * occurs. Service providers may also notify listeners when changes
55 * are made through operations on other objects in the same virtual
56 * machine, or by other clients in the same or other hosts. Such
57 * notifications are not required and are typically not supported
58 * by mail protocols (including IMAP).
59 *
60 * @author John Mani
61 * @author Bill Shannon
62 */
63
64 public class FolderEvent extends MailEvent {
65
66 /** The folder was created. */
67 public static final int CREATED = 1;
68 /** The folder was deleted. */
69 public static final int DELETED = 2;
70 /** The folder was renamed. */
71 public static final int RENAMED = 3;
72
73 /**
74 * The event type.
75 *
76 * @serial
77 */
78 protected int type;
79
80 /**
81 * The folder the event occurred on.
82 */
83 transient protected Folder folder;
84
85 /**
86 * The folder that represents the new name, in case of a RENAMED event.
87 *
88 * @since JavaMail 1.1
89 */
90 transient protected Folder newFolder;
91
92 private static final long serialVersionUID = 5278131310563694307L;
93
94 /**
95 * Constructor. <p>
96 *
97 * @param source The source of the event
98 * @param folder The affected folder
99 * @param type The event type
100 */
101 public FolderEvent(Object source, Folder folder, int type) {
102 this(source, folder, folder, type);
103 }
104
105 /**
106 * Constructor. Use for RENAMED events.
107 *
108 * @param source The source of the event
109 * @param oldFolder The folder that is renamed
110 * @param newFolder The folder that represents the new name
111 * @param type The event type
112 * @since JavaMail 1.1
113 */
114 public FolderEvent(Object source, Folder oldFolder,
115 Folder newFolder, int type) {
116 super(source);
117 this.folder = oldFolder;
118 this.newFolder = newFolder;
119 this.type = type;
120 }
121
122 /**
123 * Return the type of this event.
124 *
125 * @return type
126 */
127 public int getType() {
128 return type;
129 }
130
131 /**
132 * Return the affected folder.
133 *
134 * @return the affected folder
135 * @see #getNewFolder
136 */
137 public Folder getFolder() {
138 return folder;
139 }
140
141 /**
142 * If this event indicates that a folder is renamed, (i.e, the event type
143 * is RENAMED), then this method returns the Folder object representing the
144 * new name. <p>
145 *
146 * The <code>getFolder()</code> method returns the folder that is renamed.
147 *
148 * @return Folder representing the new name.
149 * @see #getFolder
150 * @since JavaMail 1.1
151 */
152 public Folder getNewFolder() {
153 return newFolder;
154 }
155
156 /**
157 * Invokes the appropriate FolderListener method
158 */
159 public void dispatch(Object listener) {
160 if (type == CREATED)
161 ((FolderListener)listener).folderCreated(this);
162 else if (type == DELETED)
163 ((FolderListener)listener).folderDeleted(this);
164 else if (type == RENAMED)
165 ((FolderListener)listener).folderRenamed(this);
166 }
167 }