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 page or component
026 * needs some setup logic that can be best accomplished in Java code.
027 *
028 * @author Howard M. Lewis Ship
029 * @since 4.0
030 */
031 public abstract class InvokeListener extends AbstractComponent
032 {
033 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
034 {
035 Object[] parameters = DirectLink.constructServiceParameters(getParameters());
036
037 try
038 {
039 cycle.setListenerParameters(parameters);
040
041 getListenerInvoker().invokeListener(getListener(), this, cycle);
042 }
043 finally
044 {
045 cycle.setListenerParameters(null);
046 }
047 }
048
049 /** Parameter */
050 public abstract IActionListener getListener();
051
052 /** Parameter */
053 public abstract Object getParameters();
054
055 /** Injected */
056 public abstract ListenerInvoker getListenerInvoker();
057 }