Clover coverage report - Code Coverage for tapestry release 4.0-beta-6
Coverage timestamp: Wed Sep 7 2005 18:41:34 EDT
file stats: LOC: 93   Methods: 2
NCLOC: 46   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EstablishDefaultParameterValuesVisitor.java 80% 88.2% 100% 86.2%
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.BindingConstants;
 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 4.0 */
 37    private BindingSource _bindingSource;
 38   
 39    /**
 40    * @see org.apache.tapestry.pageload.IComponentVisitor#visitComponent(org.apache.tapestry.IComponent)
 41    */
 42  1078 public void visitComponent(IComponent component)
 43    {
 44  1078 IComponentSpecification spec = component.getSpecification();
 45   
 46  1078 Iterator i = spec.getParameterNames().iterator();
 47   
 48  1078 while (i.hasNext())
 49    {
 50  3450 String name = (String) i.next();
 51  3450 IParameterSpecification parameterSpec = spec.getParameter(name);
 52   
 53    // Skip aliases
 54   
 55  3450 if (!name.equals(parameterSpec.getParameterName()))
 56  0 continue;
 57   
 58  3450 String defaultValue = parameterSpec.getDefaultValue();
 59  3450 if (defaultValue == null)
 60  2920 continue;
 61   
 62    // the parameter has a default value, so it must not be required
 63  530 if (parameterSpec.isRequired())
 64  0 throw new ApplicationRuntimeException(PageloadMessages
 65    .parameterMustHaveNoDefaultValue(component, name), component, parameterSpec
 66    .getLocation(), null);
 67   
 68    // if there is no binding for this parameter, bind it to the default value.
 69    // In 3.0, default-value was always an OGNL expression, but now its a binding reference.
 70   
 71  530 if (component.getBinding(name) == null)
 72    {
 73  509 String description = PageloadMessages.defaultParameterName(name);
 74   
 75  509 IBinding binding = _bindingSource.createBinding(
 76    component,
 77    description,
 78    defaultValue,
 79    BindingConstants.OGNL_PREFIX,
 80    parameterSpec.getLocation());
 81   
 82  509 component.setBinding(name, binding);
 83    }
 84    }
 85    }
 86   
 87    /** @since 4.0 */
 88   
 89  41 public void setBindingSource(BindingSource bindingSource)
 90    {
 91  41 _bindingSource = bindingSource;
 92    }
 93    }