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 015 package org.apache.tapestry.listener; 016 017 import org.apache.hivemind.util.Defense; 018 import org.apache.tapestry.IActionListener; 019 import org.apache.tapestry.IComponent; 020 import 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 025 * bridge from listener method names to listener method invocations. 026 * <p> 027 * TODO: It would really be nice if we could get the location of the listener 028 * binding into thrown exceptions. As implemented, as best, it will be the 029 * location of the <page-specification> (or <component>) of the page 030 * (or component) containing the listener method. 031 * 032 * @author Howard M. Lewis Ship 033 * @since 4.0 034 */ 035 public class SyntheticListener implements IActionListener 036 { 037 private final Object _target; 038 039 private final ListenerMethodInvoker _invoker; 040 041 public SyntheticListener(Object target, ListenerMethodInvoker invoker) 042 { 043 Defense.notNull(target, "target"); 044 Defense.notNull(invoker, "invoker"); 045 046 _target = target; 047 _invoker = invoker; 048 } 049 050 public void actionTriggered(IComponent component, IRequestCycle cycle) 051 { 052 _invoker.invokeListenerMethod(_target, cycle); 053 } 054 055 public String getMethodName() 056 { 057 return _invoker.getMethodName(); 058 } 059 060 public String toString() 061 { 062 return "SyntheticListener[methodName = " + _invoker.getMethodName() + "]"; 063 } 064 }