|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
FolderEvent.java | - | 81% | 66.7% | 77.8% |
|
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 | 3 | public FolderEvent(Object source, Folder oldFolder, Folder newFolder, int type) { |
43 | 3 | super(source); |
44 | 3 | folder = oldFolder; |
45 | 3 | this.newFolder = newFolder; |
46 | 3 | 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 | 3 | public FolderEvent(Object source, Folder folder, int type) { |
57 | 3 | this(source, folder, null, type); |
58 | } | |
59 | ||
60 | 3 | public void dispatch(Object listener) { |
61 | 3 | FolderListener l = (FolderListener) listener; |
62 | 3 | switch (type) { |
63 | 1 | case CREATED: |
64 | 1 | l.folderCreated(this); |
65 | 1 | break; |
66 | 1 | case DELETED: |
67 | 1 | l.folderDeleted(this); |
68 | 1 | break; |
69 | 1 | case RENAMED: |
70 | 1 | l.folderRenamed(this); |
71 | 1 | break; |
72 | 0 | default: |
73 | 0 | throw new IllegalArgumentException("Invalid type " + type); |
74 | } | |
75 | } | |
76 | ||
77 | /** | |
78 | * Return the affected folder. | |
79 | * @return the affected folder | |
80 | */ | |
81 | 0 | public Folder getFolder() { |
82 | 0 | return folder; |
83 | } | |
84 | ||
85 | /** | |
86 | * Return the new folder; only applicable to RENAMED events. | |
87 | * @return the new folder | |
88 | */ | |
89 | 0 | public Folder getNewFolder() { |
90 | 0 | return newFolder; |
91 | } | |
92 | ||
93 | /** | |
94 | * Return the event type. | |
95 | * @return the event type | |
96 | */ | |
97 | 3 | public int getType() { |
98 | 3 | return type; |
99 | } | |
100 | } |
|