Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 87   Methods: 2
NCLOC: 43   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
EstablishDefaultParameterValuesVisitor.java 87.5% 93.3% 100% 92%
coverage coverage
 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.pageload;
 16   
 
 17   
 import java.util.Iterator;
 18   
 
 19   
 import org.apache.hivemind.ApplicationRuntimeException;
 20   
 import org.apache.tapestry.IBinding;
 21   
 import org.apache.tapestry.IComponent;
 22   
 import org.apache.tapestry.binding.BindingFactory;
 23   
 import org.apache.tapestry.binding.BindingSource;
 24   
 import org.apache.tapestry.spec.IComponentSpecification;
 25   
 import org.apache.tapestry.spec.IParameterSpecification;
 26   
 
 27   
 /**
 28   
  * For all parameters in the examined component that have default values, but are not bound,
 29   
  * automatically add an ExpressionBinding with the default value.
 30   
  * 
 31   
  * @author mindbridge
 32   
  * @since 3.0
 33   
  */
 34   
 public class EstablishDefaultParameterValuesVisitor implements IComponentVisitor
 35   
 {
 36   
     /** @since 3.1 */
 37   
     private BindingSource _bindingSource;
 38   
 
 39   
     /**
 40   
      * @see org.apache.tapestry.pageload.IComponentVisitor#visitComponent(org.apache.tapestry.IComponent)
 41   
      */
 42  1312
     public void visitComponent(IComponent component)
 43   
     {
 44  1312
         IComponentSpecification spec = component.getSpecification();
 45   
 
 46  1312
         Iterator i = spec.getParameterNames().iterator();
 47   
 
 48  1312
         while (i.hasNext())
 49   
         {
 50  4220
             String name = (String) i.next();
 51  4220
             IParameterSpecification parameterSpec = spec.getParameter(name);
 52   
 
 53  4220
             String defaultValue = parameterSpec.getDefaultValue();
 54  4220
             if (defaultValue == null)
 55  3753
                 continue;
 56   
 
 57   
             // the parameter has a default value, so it must not be required
 58  467
             if (parameterSpec.isRequired())
 59  0
                 throw new ApplicationRuntimeException(PageloadMessages
 60   
                         .parameterMustHaveNoDefaultValue(component, name), component, parameterSpec
 61   
                         .getLocation(), null);
 62   
 
 63   
             // if there is no binding for this parameter, bind it to the default value.
 64   
             // In 3.0, default-value as always an OGNL expression, but now its a locator.
 65   
 
 66  467
             if (component.getBinding(name) == null)
 67   
             {
 68  446
                 String description = PageloadMessages.defaultParameterName(name);
 69   
 
 70  446
                 IBinding binding = _bindingSource.createBinding(
 71   
                         component,
 72   
                         description,
 73   
                         defaultValue,
 74   
                         parameterSpec.getLocation());
 75   
 
 76  446
                 component.setBinding(name, binding);
 77   
             }
 78   
         }
 79   
     }
 80   
 
 81   
     /** @since 3.1 */
 82   
 
 83  52
     public void setBindingSource(BindingSource bindingSource)
 84   
     {
 85  52
         _bindingSource = bindingSource;
 86   
     }
 87   
 }