KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > bean > BeanProviderPropertyAccessor


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.bean;
16
17 import java.util.Map JavaDoc;
18
19 import ognl.ObjectPropertyAccessor;
20 import ognl.OgnlException;
21
22 import org.apache.tapestry.IBeanProvider;
23
24 /**
25  * Adapts a {@link org.apache.tapestry.IBeanProvider} to
26  * <a HREF="http://www.ognl.org">OGNL</a> by exposing the named
27  * beans provided by the provider as read-only properties of
28  * the provider.
29  *
30  * <p>This is registered by {@link org.apache.tapestry.AbstractComponent}.
31  *
32  * @author Howard Lewis Ship
33  * @since 2.2
34  *
35  **/

36
37 public class BeanProviderPropertyAccessor extends ObjectPropertyAccessor
38 {
39     /**
40      * Checks to see if the name matches the name of a bean inside
41      * the provider and returns that bean if so.
42      * Otherwise, invokes the super implementation.
43      *
44      **/

45     
46     public Object JavaDoc getProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc name) throws OgnlException
47     {
48         IBeanProvider provider = (IBeanProvider)target;
49         String JavaDoc beanName = (String JavaDoc)name;
50         
51         if (provider.canProvideBean(beanName))
52             return provider.getBean(beanName);
53         
54         return super.getProperty(context, target, name);
55     }
56
57     /**
58      * Returns true if the name matches a bean provided by the provider.
59      * Otherwise invokes the super implementation.
60      *
61      **/

62     
63     public boolean hasGetProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc oname) throws OgnlException
64     {
65         IBeanProvider provider = (IBeanProvider)target;
66         String JavaDoc beanName = (String JavaDoc)oname;
67
68         if (provider.canProvideBean(beanName))
69             return true;
70             
71         return super.hasGetProperty(context, target, oname);
72     }
73
74 }
75
Popular Tags