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: 920714 $ $Date: 2010-03-09 01:55:49 -0500 (Tue, 09 Mar 2010) $ 026 */ 027 public class FolderEvent extends MailEvent { 028 029 private static final long serialVersionUID = 5278131310563694307L; 030 031 public static final int CREATED = 1; 032 public static final int DELETED = 2; 033 public static final int RENAMED = 3; 034 035 protected transient Folder folder; 036 protected transient Folder newFolder; 037 protected int type; 038 039 /** 040 * Constructor used for RENAMED events. 041 * 042 * @param source the source of the event 043 * @param oldFolder the folder that was renamed 044 * @param newFolder the folder with the new name 045 * @param type the event type 046 */ 047 public FolderEvent(Object source, Folder oldFolder, Folder newFolder, int type) { 048 super(source); 049 folder = oldFolder; 050 this.newFolder = newFolder; 051 this.type = type; 052 } 053 054 /** 055 * Constructor other events. 056 * 057 * @param source the source of the event 058 * @param folder the folder affected 059 * @param type the event type 060 */ 061 public FolderEvent(Object source, Folder folder, int type) { 062 this(source, folder, null, type); 063 } 064 065 public void dispatch(Object listener) { 066 FolderListener l = (FolderListener) listener; 067 switch (type) { 068 case CREATED: 069 l.folderCreated(this); 070 break; 071 case DELETED: 072 l.folderDeleted(this); 073 break; 074 case RENAMED: 075 l.folderRenamed(this); 076 break; 077 default: 078 throw new IllegalArgumentException("Invalid type " + type); 079 } 080 } 081 082 /** 083 * Return the affected folder. 084 * @return the affected folder 085 */ 086 public Folder getFolder() { 087 return folder; 088 } 089 090 /** 091 * Return the new folder; only applicable to RENAMED events. 092 * @return the new folder 093 */ 094 public Folder getNewFolder() { 095 return newFolder; 096 } 097 098 /** 099 * Return the event type. 100 * @return the event type 101 */ 102 public int getType() { 103 return type; 104 } 105 }