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.Iterator;
018    import java.util.Vector;
019    
020    /**
021     * The PluginChain keeps track of PluginEventListeners. Distributes events to
022     * the different PluginEventListeners
023     * 
024     * @author Adam Olsen
025     * @created October 31, 2004
026     */
027    public class PluginChain {
028        private static Vector pluginListeners = new Vector();
029    
030        /**
031         * Adds a PluginEventListener to the chain
032         * 
033         * @param listener
034         *            The listener to addd
035         */
036        public static void addListener(PluginEventListener listener) {
037            pluginListeners.add(listener);
038        }
039    
040        /**
041         * Removes a listener from the chain
042         * 
043         * @param listener
044         *            The listener to remove
045         */
046        public static void removeListener(PluginEventListener listener) {
047            pluginListeners.remove(listener);
048        }
049    
050        /**
051         * Notifies all the EventListeners of an event
052         * 
053         * @param e
054         *            the event to fire
055         */
056        public static void fireEvent(PluginEvent e) {
057            Iterator i = pluginListeners.iterator();
058    
059            while (i.hasNext()) {
060                PluginEventListener listener = (PluginEventListener) i.next();
061                listener.handleEvent(e);
062            }
063        }
064    }
065