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