Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 88   Methods: 4
NCLOC: 44   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
BindingBeanInitializer.java 50% 100% 100% 94.1%
coverage coverage
 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
 28   
  * bean 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   
     private IBinding _binding;
 41   
 
 42   
     /** @since 4.0 */
 43  14
     public BindingBeanInitializer(BindingSource source)
 44   
     {
 45  14
         Defense.notNull(source, "source");
 46   
 
 47  14
         _bindingSource = source;
 48   
     }
 49   
 
 50   
     /**
 51   
      * @since 4.0
 52   
      */
 53  14
     public void setBindingReference(String bindingReference)
 54   
     {
 55  14
         _bindingReference = bindingReference;
 56   
     }
 57   
 
 58   
     /** @since 4.0 */
 59  4
     public String getBindingReference()
 60   
     {
 61  4
         return _bindingReference;
 62   
     }
 63   
 
 64  8
     public void setBeanProperty(IBeanProvider provider, Object bean)
 65   
     {
 66  8
         if (_binding == null)
 67   
         {
 68  8
             IComponent component = provider.getComponent();
 69   
 
 70  8
             String description = BeanMessages.propertyInitializerName(_propertyName);
 71   
 
 72  8
             _binding = _bindingSource.createBinding(
 73   
                     component,
 74   
                     description,
 75   
                     _bindingReference,
 76   
                     BindingConstants.OGNL_PREFIX,
 77   
                     getLocation());
 78   
         }
 79   
 
 80  8
         Class propertyType = PropertyUtils.getPropertyType(bean, _propertyName);
 81   
 
 82  8
         Object bindingValue = _binding.getObject(propertyType);
 83   
 
 84  8
         setBeanProperty(bean, bindingValue);
 85   
     }
 86   
 }
 87   
 
 88