Coverage Report - net.sourceforge.pebble.event.EventListenerList
 
Classes in this File Line Coverage Branch Coverage Complexity
EventListenerList
100%
29/29
50%
4/8
1.4
 
 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.BlogListener;
 35  
 import net.sourceforge.pebble.api.event.blogentry.BlogEntryListener;
 36  
 import net.sourceforge.pebble.api.event.comment.CommentListener;
 37  
 import net.sourceforge.pebble.api.event.trackback.TrackBackListener;
 38  
 import org.apache.commons.logging.Log;
 39  
 import org.apache.commons.logging.LogFactory;
 40  
 
 41  
 import java.util.ArrayList;
 42  
 import java.util.List;
 43  
 
 44  
 /**
 45  
  * Maintains a list of listeners, allowing them to be added and removed.
 46  
  *
 47  
  * @author Simon Brown
 48  
  */
 49  
 public class EventListenerList {
 50  
 
 51  
   /** the log in use by this class */
 52  4
   private static final Log log = LogFactory.getLog(EventListenerList.class);
 53  
 
 54  
   /** the list of blog listeners */
 55  
   private List blogListeners;
 56  
 
 57  
   /** the list of blog entry listeners */
 58  
   private List blogEntryListeners;
 59  
 
 60  
   /** the list of comment listeners */
 61  
   private List commentListeners;
 62  
 
 63  
   /** the list of TrackBack listeners */
 64  
   private List trackBackListeners;
 65  
 
 66  
   /**
 67  
    * Default, no args constructor.
 68  
    */
 69  2720
   public EventListenerList() {
 70  2720
     this.blogListeners = new ArrayList();
 71  2720
     this.blogEntryListeners = new ArrayList();
 72  2720
     this.commentListeners = new ArrayList();
 73  2720
     this.trackBackListeners = new ArrayList();
 74  2720
   }
 75  
 
 76  
   /**
 77  
    * Gets the list of blog listeners.
 78  
    *
 79  
    * @return  a List of BlogListener instances
 80  
    */
 81  
   public List getBlogListeners() {
 82  5388
     return this.blogListeners;
 83  
   }
 84  
 
 85  
   /**
 86  
    * Registers a blog listener.
 87  
    *
 88  
    * @param listener    a BlogListener instance
 89  
    */
 90  
   public void addBlogListener(BlogListener listener) {
 91  8
     if (!blogListeners.contains(listener)) {
 92  8
       blogListeners.add(listener);
 93  8
       log.debug(listener.getClass().getName() + " registered");
 94  
     }
 95  8
   }
 96  
 
 97  
   /**
 98  
    * Unregisters a blog listener.
 99  
    *
 100  
    * @param listener    a BlogListener instance
 101  
    */
 102  
   public void removeBlogListener(BlogListener listener) {
 103  4
     blogListeners.remove(listener);
 104  4
   }
 105  
 
 106  
   /**
 107  
    * Gets the list of blog entry listeners.
 108  
    *
 109  
    * @return  a List of BlogEntryListener instances
 110  
    */
 111  
   public List getBlogEntryListeners() {
 112  688
     return this.blogEntryListeners;
 113  
   }
 114  
 
 115  
   /**
 116  
    * Registers a blog entry listener.
 117  
    *
 118  
    * @param listener    a BlogEntryListener instance
 119  
    */
 120  
   public void addBlogEntryListener(BlogEntryListener listener) {
 121  21772
     if (!blogEntryListeners.contains(listener)) {
 122  21772
       blogEntryListeners.add(listener);
 123  21772
       log.debug(listener.getClass().getName() + " registered");
 124  
     }
 125  21772
   }
 126  
 
 127  
   /**
 128  
    * Gets the list of comment listeners.
 129  
    *
 130  
    * @return  a List of CommentListener instances
 131  
    */
 132  
   public List getCommentListeners() {
 133  284
     return this.commentListeners;
 134  
   }
 135  
 
 136  
   /**
 137  
    * Registers a comment listener.
 138  
    *
 139  
    * @param listener    a CommentListener instance
 140  
    */
 141  
   public void addCommentListener(CommentListener listener) {
 142  19068
     if (!commentListeners.contains(listener)) {
 143  19068
       commentListeners.add(listener);
 144  19068
       log.debug(listener.getClass().getName() + " registered");
 145  
     }
 146  19068
   }
 147  
 
 148  
   /**
 149  
    * Gets the list of TrackBack listeners.
 150  
    *
 151  
    * @return  a List of TrackBackListener instances
 152  
    */
 153  
   public List getTrackBackListeners() {
 154  52
     return this.trackBackListeners;
 155  
   }
 156  
 
 157  
   /**
 158  
    * Registers a TrackBack listener.
 159  
    *
 160  
    * @param listener    a TrackBackListener instance
 161  
    */
 162  
   public void addTrackBackListener(TrackBackListener listener) {
 163  19068
     if (!trackBackListeners.contains(listener)) {
 164  19068
       trackBackListeners.add(listener);
 165  19068
       log.debug(listener.getClass().getName() + " registered");
 166  
     }
 167  19068
   }
 168  
 
 169  
 
 170  
 }