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. If the listener parameter is not bound, attempt to locate an 028 * implicit listener named by the capitalized component id, prefixed by "do". 029 * 030 * @author Howard M. Lewis Ship 031 * @since 4.0 032 */ 033 public abstract class InvokeListener extends AbstractComponent 034 { 035 036 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 037 { 038 Object[] parameters = DirectLink 039 .constructServiceParameters(getParameters()); 040 041 try 042 { 043 cycle.setListenerParameters(parameters); 044 045 IActionListener listener = getListener(); 046 047 if (listener == null) 048 listener = getContainer().getListeners().getImplicitListener(this); 049 050 getListenerInvoker().invokeListener(listener, this, cycle); 051 } 052 finally 053 { 054 cycle.setListenerParameters(null); 055 } 056 } 057 058 /** Parameter. */ 059 public abstract IActionListener getListener(); 060 061 /** Parameter. */ 062 public abstract Object getParameters(); 063 064 /** Injected. */ 065 public abstract ListenerInvoker getListenerInvoker(); 066 }