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
015package org.apache.tapestry.listener;
016
017import java.util.Map;
018
019import ognl.ObjectPropertyAccessor;
020import ognl.OgnlException;
021
022/**
023 * Exposes {@link org.apache.tapestry.IActionListener} listeners provided by the
024 * {@link org.apache.tapestry.listener.ListenerMap} as read-only properties of the map.
025 * 
026 * @author Howard Lewis Ship
027 * @since 2.2
028 */
029
030public class ListenerMapPropertyAccessor extends ObjectPropertyAccessor
031{
032    /**
033     * Checks to see if the ListenerMapImpl provides the named listener, returning the listener if
034     * it does. Otherwise, invokes the super implementation.
035     */
036
037    public Object getProperty(Map context, Object target, Object name) throws OgnlException
038    {
039        ListenerMap map = (ListenerMap) target;
040        String listenerName = (String) name;
041
042        if (map.canProvideListener(listenerName))
043            return map.getListener(listenerName);
044
045        return super.getProperty(context, target, name);
046    }
047
048    /**
049     * Returns true if the ListenerMap contains the named listener, otherwise invokes
050     * super-implementation.
051     */
052
053    public boolean hasGetProperty(Map context, Object target, Object oname) throws OgnlException
054    {
055        ListenerMap map = (ListenerMap) target;
056        String listenerName = (String) oname;
057
058        if (map.canProvideListener(listenerName))
059            return true;
060
061        return super.hasGetProperty(context, target, oname);
062    }
063
064}