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.components; 016 017 import org.apache.tapestry.AbstractComponent; 018 import org.apache.tapestry.IActionListener; 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.link.DirectLink; 022 import org.apache.tapestry.listener.ListenerInvoker; 023 024 /** 025 * Invokes a listener method, passing listener parameters. This is used when a 026 * page or component needs some setup logic that can be best accomplished in 027 * Java code. 028 * 029 * @author Howard M. Lewis Ship 030 * @since 4.0 031 */ 032 public abstract class InvokeListener extends AbstractComponent 033 { 034 035 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 036 { 037 Object[] parameters = DirectLink 038 .constructServiceParameters(getParameters()); 039 040 try 041 { 042 cycle.setListenerParameters(parameters); 043 044 getListenerInvoker().invokeListener(getListener(), this, cycle); 045 } 046 finally 047 { 048 cycle.setListenerParameters(null); 049 } 050 } 051 052 /** Parameter. */ 053 public abstract IActionListener getListener(); 054 055 /** Parameter. */ 056 public abstract Object getParameters(); 057 058 /** Injected. */ 059 public abstract ListenerInvoker getListenerInvoker(); 060 }