1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package javax.mail.event;
19
20 import javax.mail.Folder;
21
22 /**
23 * @version $Rev: 125583 $ $Date: 2005-01-18 19:44:27 -0800 (Tue, 18 Jan 2005) $
24 */
25 public class FolderEvent extends MailEvent {
26 public static final int CREATED = 1;
27 public static final int DELETED = 2;
28 public static final int RENAMED = 3;
29
30 protected transient Folder folder;
31 protected transient Folder newFolder;
32 protected int type;
33
34 /**
35 * Constructor used for RENAMED events.
36 *
37 * @param source the source of the event
38 * @param oldFolder the folder that was renamed
39 * @param newFolder the folder with the new name
40 * @param type the event type
41 */
42 public FolderEvent(Object source, Folder oldFolder, Folder newFolder, int type) {
43 super(source);
44 folder = oldFolder;
45 this.newFolder = newFolder;
46 this.type = type;
47 }
48
49 /**
50 * Constructor other events.
51 *
52 * @param source the source of the event
53 * @param folder the folder affected
54 * @param type the event type
55 */
56 public FolderEvent(Object source, Folder folder, int type) {
57 this(source, folder, null, type);
58 }
59
60 public void dispatch(Object listener) {
61 FolderListener l = (FolderListener) listener;
62 switch (type) {
63 case CREATED:
64 l.folderCreated(this);
65 break;
66 case DELETED:
67 l.folderDeleted(this);
68 break;
69 case RENAMED:
70 l.folderRenamed(this);
71 break;
72 default:
73 throw new IllegalArgumentException("Invalid type " + type);
74 }
75 }
76
77 /**
78 * Return the affected folder.
79 * @return the affected folder
80 */
81 public Folder getFolder() {
82 return folder;
83 }
84
85 /**
86 * Return the new folder; only applicable to RENAMED events.
87 * @return the new folder
88 */
89 public Folder getNewFolder() {
90 return newFolder;
91 }
92
93 /**
94 * Return the event type.
95 * @return the event type
96 */
97 public int getType() {
98 return type;
99 }
100 }