001    package echopoint.externalevent;
002    /*
003     * This file is part of the Echo Point Project.  This project is a collection
004     * of Components that have extended the Echo Web Application Framework.
005     *
006     * Version: MPL 1.1/GPL 2.0/LGPL 2.1
007     *
008     * The contents of this file are subject to the Mozilla Public License Version
009     * 1.1 (the "License"); you may not use this file except in compliance with
010     * the License. You may obtain a copy of the License at
011     * http://www.mozilla.org/MPL/
012     *
013     * Software distributed under the License is distributed on an "AS IS" basis,
014     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015     * for the specific language governing rights and limitations under the
016     * License.
017     *
018     * Alternatively, the contents of this file may be used under the terms of
019     * either the GNU General Public License Version 2 or later (the "GPL"), or
020     * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
021     * in which case the provisions of the GPL or the LGPL are applicable instead
022     * of those above. If you wish to allow use of your version of this file only
023     * under the terms of either the GPL or the LGPL, and not to allow others to
024     * use your version of this file under the terms of the MPL, indicate your
025     * decision by deleting the provisions above and replace them with the notice
026     * and other provisions required by the GPL or the LGPL. If you do not delete
027     * the provisions above, a recipient may use your version of this file under
028     * the terms of any one of the MPL, the GPL or the LGPL.
029     */
030    import nextapp.echo.app.Component;
031    import nextapp.echo.app.event.EventListenerList;
032    
033    import java.util.EventListener;
034    
035    
036    /**
037     * A <code>ExternalEventMonitor</code> can be used to monitor
038     * external events that come in via web request URIs.
039     * <p>
040     * <code>ExternalEventMonitor</code> will inform
041     * all attached <code>ExternalEventListener</code>s about
042     * those web request events.
043     * <p>
044     * <code>ExternalEventMonitor</code> looks for web application
045     * requests with the special marker "E_id=ExternalEvent".  This
046     * allows other web pages (especially non Echo2 based ones) to link
047     * to the Echo web application via an URI, say something like :
048     * <p>
049     * <blockquote><pre>
050     * /servletcontext/servlet?sid=ExternalEvent&amp;p1=v1&amp;p2=v2..
051     * </pre></blockquote>
052     * <p>
053     * The parameters of the web request are packaged into a Map and
054     * placed within the <code>ExternalEvent</code> object.
055     * <p>
056     * <code>ExternalEventMonitor</code> is a non visual component.
057     *
058     * @see echopoint.externalevent.ExternalEvent
059     * @see echopoint.externalevent.ExternalEventListener
060     * @author Brad Baker <p>Modified by Mikael Soderman 2009-04-28</p>
061     * @version $Id$
062     */
063    public class ExternalEventMonitor extends Component {
064    
065            private EventListenerList listenerList = new EventListenerList();
066    
067            /**
068             * Constructs an <code>ExternalEventMonitor</code>
069             */
070            public ExternalEventMonitor() {
071                    setVisible(false);
072            }
073    
074            /**
075             * When the <code>ExternalEventMonitor</code> is placed in the
076             * component hierarchy it is also made known to the
077             * <code>ExternalEventMonitorService</code>
078             *
079             * @see nextapp.echo.app.Component#init()
080             */
081            public void init() {
082                    super.init();
083                    ExternalEventMonitorService.INSTANCE.register(this);
084            }
085             /**
086             * When the <code>ExternalEventMonitor</code> is removed from the
087             * component hierarchy it is also made removed from the
088             * <code>ExternalEventMonitorService</code>
089             *
090             * @see nextapp.echo.app.Component#dispose()
091             */
092            public void dispose() {
093                    super.dispose();
094                    ExternalEventMonitorService.INSTANCE.deregister(this);
095            }
096            /**
097             * Adds an <code>ExternalEventListener</code> to the <code>ExternalEventMonitor</code>.
098             * @param l the ExternalEventListener to add
099             */
100            /**
101             * Adds an <code>ExternalEventListener</code> to the <code>ExternalEventMonitor</code>
102             * @param l the ExternalEventListener to add
103             */
104            public void addExternalEventListener(ExternalEventListener l) {
105                    listenerList.addListener(ExternalEventListener.class,l);
106            }
107            /**
108             * Removes an <code>ExternalEventListener</code> from the <code>ExternalEventMonitor</code>
109             * @param l the ExternalEventListener to remove
110             */
111            public void removeExternalEventListener(ExternalEventListener l) {
112                    listenerList.removeListener(ExternalEventListener.class,l);
113            }
114    
115            /**
116             * This is called by the support code to inform all
117             * ExternalEventListeners that an external event has
118             * ocurred.  This is method not designed to be called
119             * by Echo2 applications directly.
120             *
121             * @param externalEvent - the new ExternalEvent
122             */
123            public void fireExternalEvent(ExternalEvent externalEvent) {
124                    EventListener[] listeners = listenerList.getListeners(ExternalEventListener.class);
125                    for (int index = 0; index < listeners.length; ++index) {
126                            ((ExternalEventListener) listeners[index]).externalEvent(externalEvent);
127                    }
128            }
129    
130            /**
131             * This component can never be made visible.
132             *
133             * @see nextapp.echo.app.Component#setVisible(boolean)
134             */
135            public void setVisible(boolean newValue) {
136                    super.setVisible(false);
137            }
138    
139    }
140