001    // Copyright 2004, 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.contrib.ajax;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    import org.apache.tapestry.BaseComponent;
021    import org.apache.tapestry.IActionListener;
022    import org.apache.tapestry.IRequestCycle;
023    import org.apache.tapestry.engine.IEngineService;
024    import org.apache.tapestry.engine.ILink;
025    
026    /**
027     * @author mindbridge
028     * @author Paul Green
029     * @since 4.0
030     */
031    public abstract class XTile extends BaseComponent implements IXTile
032    {
033        public abstract IActionListener getListener();
034    
035        public abstract String getSendName();
036    
037        public abstract String getReceiveName();
038    
039        public abstract String getErrorName();
040    
041        public abstract boolean getDisableCaching();
042    
043        // Injected
044    
045        public abstract IEngineService getService();
046    
047        public void trigger(IRequestCycle cycle)
048        {
049            IActionListener listener = getListener();
050    
051            if (listener == null)
052                listener = getContainer().getListeners().getImplicitListener(this);
053    
054            listener.actionTriggered(this, cycle);
055        }
056    
057        public Map getScriptSymbols()
058        {
059            ILink link = getService().getLink(false, this);
060    
061            Map result = new HashMap();
062    
063            result.put("sendFunctionName", getSendName());
064            result.put("receiveFunctionName", getReceiveName());
065            result.put("errorFunctionName", getErrorName());
066            result.put("disableCaching", getDisableCaching() ? "true" : null);
067            result.put("url", link.getURL());
068    
069            return result;
070        }
071    
072    }