Skip to content

Package: FolderEvent

FolderEvent

nameinstructionbranchcomplexitylinemethod
FolderEvent(Object, Folder, Folder, int)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
FolderEvent(Object, Folder, int)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
dispatch(Object)
M: 27 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getFolder()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNewFolder()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getType()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

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