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 Connection events.
  10. *
  11. * @author John Mani
  12. */
  13. public class ConnectionEvent extends MailEvent {
  14. /** A connection was opened. */
  15. public static final int OPENED = 1;
  16. /** A connection was disconnected (not currently used). */
  17. public static final int DISCONNECTED = 2;
  18. /** A connection was closed. */
  19. public static final int CLOSED = 3;
  20. /**
  21. * The event type.
  22. *
  23. * @serial
  24. */
  25. protected int type;
  26. /**
  27. * Constructor
  28. * @param source The source object
  29. */
  30. public ConnectionEvent(Object source, int type) {
  31. super(source);
  32. this.type = type;
  33. }
  34. /**
  35. * Return the type of this event
  36. * @return type
  37. */
  38. public int getType() {
  39. return type;
  40. }
  41. /**
  42. * Invokes the appropriate ConnectionListener method
  43. */
  44. public void dispatch(Object listener) {
  45. if (type == OPENED)
  46. ((ConnectionListener)listener).opened(this);
  47. else if (type == DISCONNECTED)
  48. ((ConnectionListener)listener).disconnected(this);
  49. else if (type == CLOSED)
  50. ((ConnectionListener)listener).closed(this);
  51. }
  52. }