001// Copyright 2005 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry.listener;
016
017import org.apache.hivemind.util.Defense;
018import org.apache.tapestry.IActionListener;
019import org.apache.tapestry.IComponent;
020import org.apache.tapestry.IRequestCycle;
021
022/**
023 * Adapter class that combines a target object (typically, a component) with a
024 * {@link org.apache.tapestry.listener.ListenerMethodInvoker}. This is the bridge from listener
025 * method names to listener method invocations.
026 * <p>
027 * TODO: It would really be nice if we could get the location of the listener binding into thrown
028 * exceptions. As implemented, as best, it will be the location of the &lt;page-specification&gt;
029 * (or &lt;component&gt;) of the page (or component) containing the listener method.
030 * 
031 * @author Howard M. Lewis Ship
032 * @since 4.0
033 */
034public class SyntheticListener implements IActionListener
035{
036    private final Object _target;
037
038    private final ListenerMethodInvoker _invoker;
039
040    public SyntheticListener(Object target, ListenerMethodInvoker invoker)
041    {
042        Defense.notNull(target, "target");
043        Defense.notNull(invoker, "invoker");
044
045        _target = target;
046        _invoker = invoker;
047    }
048
049    public void actionTriggered(IComponent component, IRequestCycle cycle)
050    {
051        _invoker.invokeListenerMethod(_target, cycle);
052    }
053}