Coverage Report - org.apache.tapestry.bean.BindingBeanInitializer
 
Classes in this File Line Coverage Branch Coverage Complexity
BindingBeanInitializer
0%
0/14
N/A
1
 
 1  
 // Copyright 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 org.apache.hivemind.util.Defense;
 18  
 import org.apache.hivemind.util.PropertyUtils;
 19  
 import org.apache.tapestry.IBeanProvider;
 20  
 import org.apache.tapestry.IBinding;
 21  
 import org.apache.tapestry.IComponent;
 22  
 import org.apache.tapestry.binding.BindingConstants;
 23  
 import org.apache.tapestry.binding.BindingSource;
 24  
 
 25  
 /**
 26  
  * An {@link org.apache.tapestry.bean.IBeanInitializer} implementation that uses an
 27  
  * {@link org.apache.tapestry.IBinding} to obtain the value which will be assigned to the bean
 28  
  * property.
 29  
  * 
 30  
  * @author Howard M. Lewis Ship
 31  
  * @since 4.0
 32  
  */
 33  
 public class BindingBeanInitializer extends AbstractBeanInitializer
 34  
 {
 35  
     private BindingSource _bindingSource;
 36  
 
 37  
     private String _bindingReference;
 38  
 
 39  
     /** @since 4.0 */
 40  
     public BindingBeanInitializer(BindingSource source)
 41  0
     {
 42  0
         Defense.notNull(source, "source");
 43  
 
 44  0
         _bindingSource = source;
 45  0
     }
 46  
 
 47  
     /**
 48  
      * @since 4.0
 49  
      */
 50  
     public void setBindingReference(String bindingReference)
 51  
     {
 52  0
         _bindingReference = bindingReference;
 53  0
     }
 54  
 
 55  
     /** @since 4.0 */
 56  
     public String getBindingReference()
 57  
     {
 58  0
         return _bindingReference;
 59  
     }
 60  
 
 61  
     public void setBeanProperty(IBeanProvider provider, Object bean)
 62  
     {
 63  0
         IComponent component = provider.getComponent();
 64  
 
 65  0
         String description = BeanMessages.propertyInitializerName(_propertyName);
 66  
 
 67  0
         IBinding binding = _bindingSource.createBinding(
 68  
                 component,
 69  
                 description,
 70  
                 _bindingReference,
 71  
                 BindingConstants.OGNL_PREFIX,
 72  
                 getLocation());
 73  
 
 74  0
         Class propertyType = PropertyUtils.getPropertyType(bean, _propertyName);
 75  
 
 76  0
         Object bindingValue = binding.getObject(propertyType);
 77  
 
 78  0
         setBeanProperty(bean, bindingValue);
 79  0
     }
 80  
 }