001 /** 002 * 003 * Copyright 2003-2006 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package javax.mail.event; 019 020 import javax.mail.Folder; 021 022 /** 023 * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $ 024 */ 025 public class FolderEvent extends MailEvent { 026 public static final int CREATED = 1; 027 public static final int DELETED = 2; 028 public static final int RENAMED = 3; 029 030 protected transient Folder folder; 031 protected transient Folder newFolder; 032 protected int type; 033 034 /** 035 * Constructor used for RENAMED events. 036 * 037 * @param source the source of the event 038 * @param oldFolder the folder that was renamed 039 * @param newFolder the folder with the new name 040 * @param type the event type 041 */ 042 public FolderEvent(Object source, Folder oldFolder, Folder newFolder, int type) { 043 super(source); 044 folder = oldFolder; 045 this.newFolder = newFolder; 046 this.type = type; 047 } 048 049 /** 050 * Constructor other events. 051 * 052 * @param source the source of the event 053 * @param folder the folder affected 054 * @param type the event type 055 */ 056 public FolderEvent(Object source, Folder folder, int type) { 057 this(source, folder, null, type); 058 } 059 060 public void dispatch(Object listener) { 061 FolderListener l = (FolderListener) listener; 062 switch (type) { 063 case CREATED: 064 l.folderCreated(this); 065 break; 066 case DELETED: 067 l.folderDeleted(this); 068 break; 069 case RENAMED: 070 l.folderRenamed(this); 071 break; 072 default: 073 throw new IllegalArgumentException("Invalid type " + type); 074 } 075 } 076 077 /** 078 * Return the affected folder. 079 * @return the affected folder 080 */ 081 public Folder getFolder() { 082 return folder; 083 } 084 085 /** 086 * Return the new folder; only applicable to RENAMED events. 087 * @return the new folder 088 */ 089 public Folder getNewFolder() { 090 return newFolder; 091 } 092 093 /** 094 * Return the event type. 095 * @return the event type 096 */ 097 public int getType() { 098 return type; 099 } 100 }