|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| BeanProviderPropertyAccessor.java | 25% | 40% | 50% | 37.5% |
|
||||||||||||||
| 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; | |
| 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 | 90 | public Object getProperty(Map context, Object target, Object name) throws OgnlException |
| 47 | { | |
| 48 | 90 | IBeanProvider provider = (IBeanProvider)target; |
| 49 | 90 | String beanName = (String)name; |
| 50 | ||
| 51 | 90 | if (provider.canProvideBean(beanName)) |
| 52 | 90 | return provider.getBean(beanName); |
| 53 | ||
| 54 | 0 | 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 | 0 | public boolean hasGetProperty(Map context, Object target, Object oname) throws OgnlException |
| 64 | { | |
| 65 | 0 | IBeanProvider provider = (IBeanProvider)target; |
| 66 | 0 | String beanName = (String)oname; |
| 67 | ||
| 68 | 0 | if (provider.canProvideBean(beanName)) |
| 69 | 0 | return true; |
| 70 | ||
| 71 | 0 | return super.hasGetProperty(context, target, oname); |
| 72 | } | |
| 73 | ||
| 74 | } |
|
||||||||||