KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > listener > ListenerMapPropertyAccessor


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.listener;
16
17 import java.util.Map JavaDoc;
18
19 import ognl.ObjectPropertyAccessor;
20 import ognl.OgnlException;
21
22 /**
23  * Exposes {@link org.apache.tapestry.IActionListener} listeners provided by the
24  * {@link org.apache.tapestry.listener.ListenerMap} as read-only properties of the map.
25  *
26  * @author Howard Lewis Ship
27  * @since 2.2
28  */

29
30 public class ListenerMapPropertyAccessor extends ObjectPropertyAccessor
31 {
32     /**
33      * Checks to see if the ListenerMapImpl provides the named listener, returning the listener if
34      * it does. Otherwise, invokes the super implementation.
35      */

36
37     public Object JavaDoc getProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc name) throws OgnlException
38     {
39         ListenerMap map = (ListenerMap) target;
40         String JavaDoc listenerName = (String JavaDoc) name;
41
42         if (map.canProvideListener(listenerName))
43             return map.getListener(listenerName);
44
45         return super.getProperty(context, target, name);
46     }
47
48     /**
49      * Returns true if the ListenerMap contains the named listener, otherwise invokes
50      * super-implementation.
51      */

52
53     public boolean hasGetProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc oname) throws OgnlException
54     {
55         ListenerMap map = (ListenerMap) target;
56         String JavaDoc listenerName = (String JavaDoc) oname;
57
58         if (map.canProvideListener(listenerName))
59             return true;
60
61         return super.hasGetProperty(context, target, oname);
62     }
63
64 }
Popular Tags