defaulteventdispatcher.java

### File Source: defaulteventdispatcher.java

             /*
        P/P   *  Method: net.sourceforge.pebble.event.DefaultEventDispatcher__static_init
              */
         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.event;
        33
        34  import net.sourceforge.pebble.api.event.blog.BlogEvent;
        35  import net.sourceforge.pebble.api.event.blog.BlogListener;
        36  import net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent;
        37  import net.sourceforge.pebble.api.event.blogentry.BlogEntryListener;
        38  import net.sourceforge.pebble.api.event.comment.CommentEvent;
        39  import net.sourceforge.pebble.api.event.comment.CommentListener;
        40  import net.sourceforge.pebble.api.event.EventDispatcher;
        41  import net.sourceforge.pebble.api.event.trackback.TrackBackEvent;
        42  import net.sourceforge.pebble.api.event.trackback.TrackBackListener;
        43
        44  import java.util.Iterator;
        45
        46  /**
        47   * Responsible for dispatching events to registered listeners, which are
        48   * called in the order they were added.
        49   *
        50   * @author Simon Brown
        51   */
             /*
        P/P   *  Method: void net.sourceforge.pebble.event.DefaultEventDispatcher()
              */
        52  public class DefaultEventDispatcher extends EventDispatcher {
        53
        54    /**
        55     * Fires a blog event to registered listeners.
        56     *
        57     * @param event   the BlogEvent instance
        58     */
        59    public void fireBlogEvent(BlogEvent event) {
                 /*
        P/P       *  Method: void fireBlogEvent(BlogEvent)
                  *
                  *  Preconditions:
                  *    (soft) event != null
                  *
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@62 != null
                  *
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@61: {1}, {0}
                  *
                  *  Preconditions:
                  *    this.eventListenerList != null
                  *    this.eventListenerList.blogListeners != null
                  *    (soft) init'ed(event.type)
                  *    (soft) init'ed(event.vetoed)
                  *
                  *  Test Vectors:
                  *    event.type: {-231..-1, 2..232-1}, {0}, {1}
                  *
                  *  Presumptions:
                  *    listener.timer@62 != null
                  */
        60      Iterator it = getEventListenerList().getBlogListeners().iterator();
        61      while (it.hasNext()) {
        62        BlogListener listener = (BlogListener)it.next();
        63        if (event.getType() == BlogEvent.BLOG_STARTED) {
        64          listener.blogStarted(event);
        65        } else if (event.getType() == BlogEvent.BLOG_STOPPED) {
        66          listener.blogStopped(event);
        67        }
        68
        69        // has the event been vetoed?
        70        if (event.isVetoed()) {
        71          break;
        72        }
        73      }
        74    }
        75
        76    /**
        77     * Fires a blog entry event to registered listeners.
        78     *
        79     * @param event   the BlogEntryEvent instance
        80     */
        81    public void fireBlogEntryEvent(BlogEntryEvent event) {
                 /*
        P/P       *  Method: void fireBlogEntryEvent(BlogEntryEvent)
                  *
                  *  Preconditions:
                  *    (soft) event != null
                  *
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@84 != null
                  *
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@83: {1}, {0}
                  *
                  *  Preconditions:
                  *    this.eventListenerList != null
                  *    this.eventListenerList.blogEntryListeners != null
                  *    (soft) init'ed(event.type)
                  *    (soft) init'ed(event.vetoed)
                  */
        82      Iterator it = getEventListenerList().getBlogEntryListeners().iterator();
        83      while (it.hasNext()) {
        84        BlogEntryListener listener = (BlogEntryListener)it.next();
        85        if (event.getType() == BlogEntryEvent.BLOG_ENTRY_ADDED) {
        86          listener.blogEntryAdded(event);
        87        } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_REMOVED) {
        88          listener.blogEntryRemoved(event);
        89        } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_CHANGED) {
        90          listener.blogEntryChanged(event);
        91        } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_PUBLISHED) {
        92          listener.blogEntryPublished(event);
        93        } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_UNPUBLISHED) {
        94          listener.blogEntryUnpublished(event);
        95        }
        96
        97        // has the event been vetoed?
        98        if (event.isVetoed()) {
        99          break;
       100        }
       101      }
       102    }
       103
       104    /**
       105     * Fires a comment event to registered listeners.
       106     *
       107     * @param event   the CommentEvent instance
       108     */
       109    public void fireCommentEvent(CommentEvent event) {
                 /*
        P/P       *  Method: void fireCommentEvent(CommentEvent)
                  *
                  *  Preconditions:
                  *    (soft) event != null
                  *
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@112 != null
                  *
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@111: {1}, {0}
                  *
                  *  Preconditions:
                  *    this.eventListenerList != null
                  *    this.eventListenerList.commentListeners != null
                  *    (soft) init'ed(event.type)
                  *    (soft) init'ed(event.vetoed)
                  */
       110      Iterator it = getEventListenerList().getCommentListeners().iterator();
       111      while (it.hasNext()) {
       112        CommentListener listener = (CommentListener)it.next();
       113        if (event.getType() == CommentEvent.COMMENT_ADDED) {
       114          listener.commentAdded(event);
       115        } else if (event.getType() == CommentEvent.COMMENT_REMOVED) {
       116          listener.commentRemoved(event);
       117        } else if (event.getType() == CommentEvent.COMMENT_APPROVED) {
       118          listener.commentApproved(event);
       119        } else if (event.getType() == CommentEvent.COMMENT_REJECTED) {
       120          listener.commentRejected(event);
       121        }
       122
       123        // has the event been vetoed?
       124        if (event.isVetoed()) {
       125          break;
       126        }
       127      }
       128    }
       129
       130    /**
       131     * Fires a TrackBack event to registered listeners.
       132     *
       133     * @param event   the TrackBackEvent instance
       134     */
       135    public void fireTrackBackEvent(TrackBackEvent event) {
                 /*
        P/P       *  Method: void fireTrackBackEvent(TrackBackEvent)
                  *
                  *  Preconditions:
                  *    (soft) event != null
                  *
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@138 != null
                  *
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@137: {1}, {0}
                  *
                  *  Preconditions:
                  *    this.eventListenerList != null
                  *    this.eventListenerList.trackBackListeners != null
                  *    (soft) init'ed(event.type)
                  *    (soft) init'ed(event.vetoed)
                  */
       136      Iterator it = getEventListenerList().getTrackBackListeners().iterator();
       137      while (it.hasNext()) {
       138        TrackBackListener listener = (TrackBackListener)it.next();
       139        if (event.getType() == TrackBackEvent.TRACKBACK_ADDED) {
       140          listener.trackBackAdded(event);
       141        } else if (event.getType() == TrackBackEvent.TRACKBACK_REMOVED) {
       142          listener.trackBackRemoved(event);
       143        } else if (event.getType() == TrackBackEvent.TRACKBACK_APPROVED) {
       144          listener.trackBackApproved(event);
       145        } else if (event.getType() == TrackBackEvent.TRACKBACK_REJECTED) {
       146          listener.trackBackRejected(event);
       147        }
       148
       149        // has the event been vetoed?
       150        if (event.isVetoed()) {
       151          break;
       152        }
       153      }
       154    }
       155
       156  }

SofCheck Inspector Build Version : 2.22510

defaulteventdispatcher.java | 2010-Jun-25 19:40:32
defaulteventdispatcher.class | 2010-Jul-19 20:23:40