001    /*
002        Copyright (C) 2003 Adam Olsen
003        This program is free software; you can redistribute it and/or modify
004        it under the terms of the GNU General Public License as published by
005        the Free Software Foundation; either version 1, or (at your option)
006        any later version.
007        This program is distributed in the hope that it will be useful,
008        but WITHOUT ANY WARRANTY; without even the implied warranty of
009        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010        GNU General Public License for more details.
011        You should have received a copy of the GNU General Public License
012        along with this program; if not, write to the Free Software
013        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
014      */
015    package com.valhalla.pluginmanager;
016    
017    import java.util.*;
018    
019    /**
020     * The PluginChain keeps track of PluginEventListeners.
021     * Distributes events to the different PluginEventListeners
022     *
023     * @author     Adam Olsen
024     * @created    October 31, 2004
025     */
026    public class PluginChain
027    {
028            private static Vector pluginListeners = new Vector();
029    
030    
031            /**
032             * Adds a PluginEventListener to the chain
033             *
034             * @param  listener  The listener to addd
035             */
036            public static void addListener( PluginEventListener listener )
037            {
038                    pluginListeners.add( listener );
039            }
040    
041    
042            /**
043             * Removes a listener from the chain
044             *
045             * @param  listener  The listener to remove
046             */
047            public static void removeListener( PluginEventListener listener )
048            {
049                    pluginListeners.remove( listener );
050            }
051    
052    
053            /**
054             * Notifies all the EventListeners of an event
055             *
056             * @param  e  the event to fire
057             */
058            public static void fireEvent( PluginEvent e )
059            {
060                    Iterator i = pluginListeners.iterator();
061    
062                    while( i.hasNext() )
063                    {
064                            PluginEventListener listener = (PluginEventListener)i.next();
065                            listener.handleEvent( e );
066                    }
067            }
068    }
069