File Source: eventdispatcher.java

     1  /*
     2   * Copyright (c) 2003-2006, Simon Brown
     3   * All rights reserved.
     4   *
     5   * Redistribution and use in source and binary forms, with or without
     6   * modification, are permitted provided that the following conditions are met:
     7   *
     8   *   - Redistributions of source code must retain the above copyright
     9   *     notice, this list of conditions and the following disclaimer.
    10   *
    11   *   - Redistributions in binary form must reproduce the above copyright
    12   *     notice, this list of conditions and the following disclaimer in
    13   *     the documentation and/or other materials provided with the
    14   *     distribution.
    15   *
    16   *   - Neither the name of Pebble nor the names of its contributors may
    17   *     be used to endorse or promote products derived from this software
    18   *     without specific prior written permission.
    19   *
    20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    30   * POSSIBILITY OF SUCH DAMAGE.
    31   */
    32  package net.sourceforge.pebble.api.event;
    33  
    34  import net.sourceforge.pebble.api.event.blog.BlogEvent;
    35  import net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent;
    36  import net.sourceforge.pebble.api.event.comment.CommentEvent;
    37  import net.sourceforge.pebble.api.event.trackback.TrackBackEvent;
    38  import net.sourceforge.pebble.event.EventListenerList;
    39  import net.sourceforge.pebble.domain.BlogEntry;
    40  import org.apache.commons.logging.Log;
    41  import org.apache.commons.logging.LogFactory;
    42  
    43  /**
    44   * Responsible for dispatching events to registered listeners.
    45   *
    46   * @author Simon Brown
    47   */
         /* 
    P/P   *  Method: void net.sourceforge.pebble.api.event.EventDispatcher()
          */
    48  public abstract class EventDispatcher {
    49  
           /* 
    P/P     *  Method: net.sourceforge.pebble.api.event.EventDispatcher__static_init
            * 
            *  Postconditions:
            *    init'ed(log)
            */
    50    private static final Log log = LogFactory.getLog(EventDispatcher.class);
    51  
    52    /** the event listener list */
    53    private EventListenerList eventListenerList;
    54  
    55    /**
    56     * Gets the event listener list.
    57     *
    58     * @return  an EventListenerList object
    59     */
    60    public EventListenerList getEventListenerList() {
             /* 
    P/P       *  Method: EventListenerList getEventListenerList()
              * 
              *  Preconditions:
              *    init'ed(this.eventListenerList)
              * 
              *  Postconditions:
              *    return_value == this.eventListenerList
              *    init'ed(return_value)
              */
    61      return this.eventListenerList;
    62    }
    63  
    64    /**
    65     * Sets the event listener list.
    66     *
    67     * @param eventListenerList   an EventListenerList object
    68     */
    69    public void setEventListenerList(EventListenerList eventListenerList) {
             /* 
    P/P       *  Method: void setEventListenerList(EventListenerList)
              * 
              *  Postconditions:
              *    this.eventListenerList == eventListenerList
              *    init'ed(this.eventListenerList)
              */
    70      this.eventListenerList = eventListenerList;
    71    }
    72  
    73    /**
    74     * Fires all outstanding events on a given blog entry.
    75     *
    76     * @param blogEntry   the blog entry to fire events on
    77     */
    78    public void fireEvents(BlogEntry blogEntry) {
             /* 
    P/P       *  Method: void fireEvents(BlogEntry)
              * 
              *  Preconditions:
              *    blogEntry != null
              *    blogEntry.events != null
              *    (soft) this.eventListenerList != null
              *    (soft) this.eventListenerList.blogEntryListeners != null
              *    (soft) this.eventListenerList.commentListeners != null
              *    (soft) this.eventListenerList.trackBackListeners != null
              */
    79      while (blogEntry.hasEvents()) {
    80        PebbleEvent event = blogEntry.nextEvent();
    81        if (event instanceof BlogEntryEvent) {
    82          fireBlogEntryEvent((BlogEntryEvent)event);
    83        } else if (event instanceof CommentEvent) {
    84          fireCommentEvent((CommentEvent)event);
    85        } else if (event instanceof TrackBackEvent) {
    86          fireTrackBackEvent((TrackBackEvent)event);
    87        }
    88      }
    89    }
    90  
    91    /**
    92     * Fires a blog event to registered listeners.
    93     *
    94     * @param event   the BlogEvent instance
    95     */
    96    public abstract void fireBlogEvent(BlogEvent event);
    97  
    98    /**
    99     * Fires a blog entry event to registered listeners.
   100     *
   101     * @param event   the BlogEntryEvent instance
   102     */
   103    public abstract void fireBlogEntryEvent(BlogEntryEvent event);
   104  
   105    /**
   106     * Fires a comment event to registered listeners.
   107     *
   108     * @param event   the CommentEvent instance
   109     */
   110    public abstract void fireCommentEvent(CommentEvent event);
   111    /**
   112     * Fires a TrackBack event to registered listeners.
   113     *
   114     * @param event   the TrackBackEvent instance
   115     */
   116    public abstract void fireTrackBackEvent(TrackBackEvent event);
   117  
   118  }








SofCheck Inspector Build Version : 2.22510
eventdispatcher.java 2010-Jun-25 19:40:32
eventdispatcher.class 2010-Jul-19 20:23:40