KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @(#)FolderEvent.java 1.12 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 models Folder <em>existence</em> events. FolderEvents are
35  * delivered to FolderListeners registered on the affected Folder as
36  * well as the containing Store. <p>
37  *
38  * Service providers vary widely in their ability to notify clients of
39  * these events. At a minimum, service providers must notify listeners
40  * registered on the same Store or Folder object on which the operation
41  * occurs. Service providers may also notify listeners when changes
42  * are made through operations on other objects in the same virtual
43  * machine, or by other clients in the same or other hosts. Such
44  * notifications are not required and are typically not supported
45  * by mail protocols (including IMAP).
46  *
47  * @author John Mani
48  * @author Bill Shannon
49  */

50
51 public class FolderEvent extends MailEvent JavaDoc {
52
53     /** The folder was created. */
54     public static final int CREATED = 1;
55     /** The folder was deleted. */
56     public static final int DELETED = 2;
57     /** The folder was renamed. */
58     public static final int RENAMED = 3;
59
60     /**
61      * The event type.
62      *
63      * @serial
64      */

65     protected int type;
66
67     /**
68      * The folder the event occurred on.
69      */

70     transient protected Folder folder;
71
72     /**
73      * The folder that represents the new name, in case of a RENAMED event.
74      *
75      * @since JavaMail 1.1
76      */

77     transient protected Folder newFolder;
78
79     private static final long serialVersionUID = 5278131310563694307L;
80
81     /**
82      * Constructor. <p>
83      *
84      * @param source The source of the event
85      * @param folder The affected folder
86      * @param type The event type
87      */

88     public FolderEvent(Object JavaDoc source, Folder folder, int type) {
89     this(source, folder, folder, type);
90     }
91
92     /**
93      * Constructor. Use for RENAMED events.
94      *
95      * @param source The source of the event
96      * @param oldFolder The folder that is renamed
97      * @param newFolder The folder that represents the new name
98      * @param type The event type
99      * @since JavaMail 1.1
100      */

101     public FolderEvent(Object JavaDoc source, Folder oldFolder,
102                Folder newFolder, int type) {
103     super(source);
104     this.folder = oldFolder;
105     this.newFolder = newFolder;
106     this.type = type;
107     }
108
109     /**
110      * Return the type of this event.
111      *
112      * @return type
113      */

114     public int getType() {
115     return type;
116     }
117
118     /**
119      * Return the affected folder.
120      *
121      * @return the affected folder
122      * @see #getNewFolder
123      */

124     public Folder getFolder() {
125     return folder;
126     }
127
128     /**
129      * If this event indicates that a folder is renamed, (i.e, the event type
130      * is RENAMED), then this method returns the Folder object representing the
131      * new name. <p>
132      *
133      * The <code>getFolder()</code> method returns the folder that is renamed.
134      *
135      * @return Folder representing the new name.
136      * @see #getFolder
137      * @since JavaMail 1.1
138      */

139     public Folder getNewFolder() {
140     return newFolder;
141     }
142
143     /**
144      * Invokes the appropriate FolderListener method
145      */

146     public void dispatch(Object JavaDoc listener) {
147     if (type == CREATED)
148         ((FolderListener JavaDoc)listener).folderCreated(this);
149     else if (type == DELETED)
150         ((FolderListener JavaDoc)listener).folderDeleted(this);
151     else if (type == RENAMED)
152         ((FolderListener JavaDoc)listener).folderRenamed(this);
153     }
154 }
155
Popular Tags