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