| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DefaultEventDispatcher |
|
| 6.75;6.75 |
| 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.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 | */ | |
| 52 | 2720 | 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) { | |
| 60 | 5388 | Iterator it = getEventListenerList().getBlogListeners().iterator(); |
| 61 | 5400 | while (it.hasNext()) { |
| 62 | 12 | BlogListener listener = (BlogListener)it.next(); |
| 63 | 12 | if (event.getType() == BlogEvent.BLOG_STARTED) { |
| 64 | 4 | listener.blogStarted(event); |
| 65 | 8 | } else if (event.getType() == BlogEvent.BLOG_STOPPED) { |
| 66 | 8 | listener.blogStopped(event); |
| 67 | } | |
| 68 | ||
| 69 | // has the event been vetoed? | |
| 70 | 12 | if (event.isVetoed()) { |
| 71 | 0 | break; |
| 72 | } | |
| 73 | 12 | } |
| 74 | 5388 | } |
| 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) { | |
| 82 | 688 | Iterator it = getEventListenerList().getBlogEntryListeners().iterator(); |
| 83 | 6204 | while (it.hasNext()) { |
| 84 | 5516 | BlogEntryListener listener = (BlogEntryListener)it.next(); |
| 85 | 5516 | if (event.getType() == BlogEntryEvent.BLOG_ENTRY_ADDED) { |
| 86 | 4736 | listener.blogEntryAdded(event); |
| 87 | 780 | } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_REMOVED) { |
| 88 | 288 | listener.blogEntryRemoved(event); |
| 89 | 492 | } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_CHANGED) { |
| 90 | 196 | listener.blogEntryChanged(event); |
| 91 | 296 | } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_PUBLISHED) { |
| 92 | 228 | listener.blogEntryPublished(event); |
| 93 | 68 | } else if (event.getType() == BlogEntryEvent.BLOG_ENTRY_UNPUBLISHED) { |
| 94 | 68 | listener.blogEntryUnpublished(event); |
| 95 | } | |
| 96 | ||
| 97 | // has the event been vetoed? | |
| 98 | 5516 | if (event.isVetoed()) { |
| 99 | 0 | break; |
| 100 | } | |
| 101 | 5516 | } |
| 102 | 688 | } |
| 103 | ||
| 104 | /** | |
| 105 | * Fires a comment event to registered listeners. | |
| 106 | * | |
| 107 | * @param event the CommentEvent instance | |
| 108 | */ | |
| 109 | public void fireCommentEvent(CommentEvent event) { | |
| 110 | 284 | Iterator it = getEventListenerList().getCommentListeners().iterator(); |
| 111 | 2300 | while (it.hasNext()) { |
| 112 | 2016 | CommentListener listener = (CommentListener)it.next(); |
| 113 | 2016 | if (event.getType() == CommentEvent.COMMENT_ADDED) { |
| 114 | 1096 | listener.commentAdded(event); |
| 115 | 920 | } else if (event.getType() == CommentEvent.COMMENT_REMOVED) { |
| 116 | 240 | listener.commentRemoved(event); |
| 117 | 680 | } else if (event.getType() == CommentEvent.COMMENT_APPROVED) { |
| 118 | 648 | listener.commentApproved(event); |
| 119 | 32 | } else if (event.getType() == CommentEvent.COMMENT_REJECTED) { |
| 120 | 32 | listener.commentRejected(event); |
| 121 | } | |
| 122 | ||
| 123 | // has the event been vetoed? | |
| 124 | 2016 | if (event.isVetoed()) { |
| 125 | 0 | break; |
| 126 | } | |
| 127 | 2016 | } |
| 128 | 284 | } |
| 129 | ||
| 130 | /** | |
| 131 | * Fires a TrackBack event to registered listeners. | |
| 132 | * | |
| 133 | * @param event the TrackBackEvent instance | |
| 134 | */ | |
| 135 | public void fireTrackBackEvent(TrackBackEvent event) { | |
| 136 | 52 | Iterator it = getEventListenerList().getTrackBackListeners().iterator(); |
| 137 | 444 | while (it.hasNext()) { |
| 138 | 392 | TrackBackListener listener = (TrackBackListener)it.next(); |
| 139 | 392 | if (event.getType() == TrackBackEvent.TRACKBACK_ADDED) { |
| 140 | 200 | listener.trackBackAdded(event); |
| 141 | 192 | } else if (event.getType() == TrackBackEvent.TRACKBACK_REMOVED) { |
| 142 | 128 | listener.trackBackRemoved(event); |
| 143 | 64 | } else if (event.getType() == TrackBackEvent.TRACKBACK_APPROVED) { |
| 144 | 32 | listener.trackBackApproved(event); |
| 145 | 32 | } else if (event.getType() == TrackBackEvent.TRACKBACK_REJECTED) { |
| 146 | 32 | listener.trackBackRejected(event); |
| 147 | } | |
| 148 | ||
| 149 | // has the event been vetoed? | |
| 150 | 392 | if (event.isVetoed()) { |
| 151 | 0 | break; |
| 152 | } | |
| 153 | 392 | } |
| 154 | 52 | } |
| 155 | ||
| 156 | } |