View Javadoc

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