| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| EventDispatcher |
|
| 1.5714285714285714;1.571 |
| 1 | /* | |
| 2 | * Copyright (c) 2003-2011, 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 | */ | |
| 48 | 2720 | public abstract class EventDispatcher { |
| 49 | ||
| 50 | 4 | 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() { | |
| 61 | 6412 | 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) { | |
| 70 | 2720 | this.eventListenerList = eventListenerList; |
| 71 | 2720 | } |
| 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) { | |
| 79 | 1808 | while (blogEntry.hasEvents()) { |
| 80 | 1024 | PebbleEvent event = blogEntry.nextEvent(); |
| 81 | 1024 | if (event instanceof BlogEntryEvent) { |
| 82 | 688 | fireBlogEntryEvent((BlogEntryEvent)event); |
| 83 | 336 | } else if (event instanceof CommentEvent) { |
| 84 | 284 | fireCommentEvent((CommentEvent)event); |
| 85 | 52 | } else if (event instanceof TrackBackEvent) { |
| 86 | 52 | fireTrackBackEvent((TrackBackEvent)event); |
| 87 | } | |
| 88 | 1024 | } |
| 89 | 784 | } |
| 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 | } |