NotificationEvent.java

  1. /*
  2.  * NotificationEvent
  3.  */
  4. package gov.usgs.earthquake.distribution;

  5. import gov.usgs.earthquake.product.Product;

  6. import java.io.IOException;

  7. import java.util.EventObject;

  8. /**
  9.  * An event sent to a NotificationListener.
  10.  *
  11.  * These events are sent by a NotificationReceiver.
  12.  */
  13. public class NotificationEvent extends EventObject {

  14.     /** For serialization. */
  15.     private static final long serialVersionUID = 1L;

  16.     /** The notification that generated this event. */
  17.     private final Notification notification;

  18.     /**
  19.      * Construct a new NotificationEvent.
  20.      *
  21.      * @param source
  22.      *            the source of this event, usually a NotificationReceiver.
  23.      * @param notification
  24.      *            the notification that generated this event.
  25.      */
  26.     public NotificationEvent(final NotificationReceiver source,
  27.             final Notification notification) {
  28.         super(source);
  29.         this.notification = notification;
  30.     }

  31.     /**
  32.      * Get the notification associated with this NotificationEvent.
  33.      *
  34.      * @return the associated notification.
  35.      */
  36.     public Notification getNotification() {
  37.         return notification;
  38.     }

  39.     /**
  40.      * A convenience method that casts event source into a NotificationReceiver.
  41.      *
  42.      * @return source as a NotificationReceiver.
  43.      */
  44.     public NotificationReceiver getNotificationReceiver() {
  45.         return (NotificationReceiver) getSource();
  46.     }

  47.     /**
  48.      * A convenience method to request a product.
  49.      *
  50.      * @return the requested product.
  51.      * @throws IOException
  52.      *             if any errors occur while retrieving the product.
  53.      */
  54.     public Product getProduct() throws Exception {
  55.         return getNotificationReceiver().retrieveProduct(
  56.                 notification.getProductId());
  57.     }

  58. }