Coverage Report - org.apache.tapestry.bean.Default
 
Classes in this File Line Coverage Branch Coverage Complexity
Default
0%
0/17
0%
0/4
1.571
 
 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 org.apache.tapestry.IBinding;
 18  
 
 19  
 /**
 20  
  *  A helper bean to assist with providing defaults for unspecified
 21  
  *  parameters.    It is initalized
 22  
  *  with an {@link IBinding} and a default value.  It's value property
 23  
  *  is either the value of the binding, but if the binding is null,
 24  
  *  or the binding returns null, the default value is returned.
 25  
  *
 26  
  *  @author Howard Lewis Ship
 27  
  *  @since 1.0.5
 28  
  * 
 29  
  **/
 30  
 
 31  0
 public class Default
 32  
 {
 33  
     private IBinding binding;
 34  
     private Object defaultValue;
 35  
 
 36  
     public void resetForPool()
 37  
     {
 38  0
         binding = null;
 39  0
         defaultValue = null;
 40  0
     }
 41  
 
 42  
     public void setBinding(IBinding value)
 43  
     {
 44  0
         binding = value;
 45  0
     }
 46  
 
 47  
     public IBinding getBinding()
 48  
     {
 49  0
         return binding;
 50  
     }
 51  
 
 52  
     public void setDefaultValue(Object value)
 53  
     {
 54  0
         defaultValue = value;
 55  0
     }
 56  
 
 57  
     public Object getDefaultValue()
 58  
     {
 59  0
         return defaultValue;
 60  
     }
 61  
 
 62  
     /**
 63  
      *  Returns the value of the binding.  However, if the binding is null, or the binding
 64  
      *  returns null, then the defaultValue is returned instead.
 65  
      *
 66  
      **/
 67  
 
 68  
     public Object getValue()
 69  
     {
 70  0
         if (binding == null)
 71  0
             return defaultValue;
 72  
 
 73  0
         Object value = binding.getObject();
 74  
 
 75  0
         if (value == null)
 76  0
             return defaultValue;
 77  
 
 78  0
         return value;
 79  
     }
 80  
     
 81  
     /** @since 3.0 **/
 82  
     
 83  
     public void discardFromPool()
 84  
     {
 85  0
     }
 86  
 
 87  
 }