-
Notifications
You must be signed in to change notification settings - Fork 100
/
FolderEvent.java
144 lines (129 loc) · 4.04 KB
/
FolderEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.mail.event;
import java.util.*;
import jakarta.mail.*;
/**
* This class models Folder <em>existence</em> events. FolderEvents are
* delivered to FolderListeners registered on the affected Folder as
* well as the containing Store. <p>
*
* Service providers vary widely in their ability to notify clients of
* these events. At a minimum, service providers must notify listeners
* registered on the same Store or Folder object on which the operation
* occurs. Service providers may also notify listeners when changes
* are made through operations on other objects in the same virtual
* machine, or by other clients in the same or other hosts. Such
* notifications are not required and are typically not supported
* by mail protocols (including IMAP).
*
* @author John Mani
* @author Bill Shannon
*/
public class FolderEvent extends MailEvent {
/** The folder was created. */
public static final int CREATED = 1;
/** The folder was deleted. */
public static final int DELETED = 2;
/** The folder was renamed. */
public static final int RENAMED = 3;
/**
* The event type.
*
* @serial
*/
protected int type;
/**
* The folder the event occurred on.
*/
transient protected Folder folder;
/**
* The folder that represents the new name, in case of a RENAMED event.
*
* @since JavaMail 1.1
*/
transient protected Folder newFolder;
private static final long serialVersionUID = 5278131310563694307L;
/**
* Constructor.
*
* @param source The source of the event
* @param folder The affected folder
* @param type The event type
*/
public FolderEvent(Object source, Folder folder, int type) {
this(source, folder, folder, type);
}
/**
* Constructor. Use for RENAMED events.
*
* @param source The source of the event
* @param oldFolder The folder that is renamed
* @param newFolder The folder that represents the new name
* @param type The event type
* @since JavaMail 1.1
*/
public FolderEvent(Object source, Folder oldFolder,
Folder newFolder, int type) {
super(source);
this.folder = oldFolder;
this.newFolder = newFolder;
this.type = type;
}
/**
* Return the type of this event.
*
* @return type
*/
public int getType() {
return type;
}
/**
* Return the affected folder.
*
* @return the affected folder
* @see #getNewFolder
*/
public Folder getFolder() {
return folder;
}
/**
* If this event indicates that a folder is renamed, (i.e, the event type
* is RENAMED), then this method returns the Folder object representing the
* new name. <p>
*
* The <code>getFolder()</code> method returns the folder that is renamed.
*
* @return Folder representing the new name.
* @see #getFolder
* @since JavaMail 1.1
*/
public Folder getNewFolder() {
return newFolder;
}
/**
* Invokes the appropriate FolderListener method
*/
@Override
public void dispatch(Object listener) {
if (type == CREATED)
((FolderListener)listener).folderCreated(this);
else if (type == DELETED)
((FolderListener)listener).folderDeleted(this);
else if (type == RENAMED)
((FolderListener)listener).folderRenamed(this);
}
}