1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.mail.event;
  6. import java.util.*;
  7. import javax.mail.*;
  8. /**
  9. * This class models Folder <em>existence</em> events. FolderEvents are
  10. * delivered to FolderListeners registered on the affected Folder as
  11. * well as the containing Store. <p>
  12. *
  13. * Service providers vary widely in their ability to notify clients of
  14. * these events. At a minimum, service providers must notify listeners
  15. * registered on the same Store or Folder object on which the operation
  16. * occurs. Service providers may also notify listeners when changes
  17. * are made through operations on other objects in the same virtual
  18. * machine, or by other clients in the same or other hosts. Such
  19. * notifications are not required and are typically not supported
  20. * by mail protocols (including IMAP).
  21. *
  22. * @author John Mani
  23. * @author Bill Shannon
  24. */
  25. public class FolderEvent extends MailEvent {
  26. /** The folder was created. */
  27. public static final int CREATED = 1;
  28. /** The folder was deleted. */
  29. public static final int DELETED = 2;
  30. /** The folder was renamed. */
  31. public static final int RENAMED = 3;
  32. /**
  33. * The event type.
  34. *
  35. * @serial
  36. */
  37. protected int type;
  38. /**
  39. * The folder the event occurred on.
  40. */
  41. transient protected Folder folder;
  42. /**
  43. * The folder that represents the new name, in case of a RENAMED event.
  44. *
  45. * @since JavaMail 1.1
  46. */
  47. transient protected Folder newFolder;
  48. /**
  49. * Constructor. <p>
  50. *
  51. * @param source The source of the event
  52. * @param folder The affected folder
  53. * @param type The event type
  54. */
  55. public FolderEvent(Object source, Folder folder, int type) {
  56. this(source, folder, folder, type);
  57. }
  58. /**
  59. * Constructor. Use for RENAMED events.
  60. *
  61. * @param source The source of the event
  62. * @param oldFolder The folder that is renamed
  63. * @param newFolder The folder that represents the new name
  64. * @param type The event type
  65. * @since JavaMail 1.1
  66. */
  67. public FolderEvent(Object source, Folder oldFolder,
  68. Folder newFolder, int type) {
  69. super(source);
  70. this.folder = oldFolder;
  71. this.newFolder = newFolder;
  72. this.type = type;
  73. }
  74. /**
  75. * Return the type of this event.
  76. *
  77. * @return type
  78. */
  79. public int getType() {
  80. return type;
  81. }
  82. /**
  83. * Return the affected folder.
  84. *
  85. * @return the affected folder
  86. * @see #getNewFolder
  87. */
  88. public Folder getFolder() {
  89. return folder;
  90. }
  91. /**
  92. * If this event indicates that a folder is renamed, (i.e, the event type
  93. * is RENAMED), then this method returns the Folder object representing the
  94. * new name. <p>
  95. *
  96. * The <code>getFolder()</code> method returns the folder that is renamed.
  97. *
  98. * @return Folder representing the new name.
  99. * @see #getFolder
  100. * @since JavaMail 1.1
  101. */
  102. public Folder getNewFolder() {
  103. return newFolder;
  104. }
  105. /**
  106. * Invokes the appropriate FolderListener method
  107. */
  108. public void dispatch(Object listener) {
  109. if (type == CREATED)
  110. ((FolderListener)listener).folderCreated(this);
  111. else if (type == DELETED)
  112. ((FolderListener)listener).folderDeleted(this);
  113. else if (type == RENAMED)
  114. ((FolderListener)listener).folderRenamed(this);
  115. }
  116. }