Coverage Report - org.apache.tapestry.pageload.EstablishDefaultParameterValuesVisitor
 
Classes in this File Line Coverage Branch Coverage Complexity
EstablishDefaultParameterValuesVisitor
0%
0/19
0%
0/10
4
 
 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 org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.tapestry.IBinding;
 19  
 import org.apache.tapestry.IComponent;
 20  
 import org.apache.tapestry.binding.BindingConstants;
 21  
 import org.apache.tapestry.binding.BindingSource;
 22  
 import org.apache.tapestry.spec.IComponentSpecification;
 23  
 import org.apache.tapestry.spec.IParameterSpecification;
 24  
 
 25  
 import java.util.Iterator;
 26  
 
 27  
 /**
 28  
  * For all parameters in the examined component that have default values, but
 29  
  * are not bound, automatically add an ExpressionBinding with the default value.
 30  
  * 
 31  
  * @author mindbridge
 32  
  * @since 3.0
 33  
  */
 34  0
 public class EstablishDefaultParameterValuesVisitor implements IComponentVisitor
 35  
 {
 36  
 
 37  
     /** @since 4.0 */
 38  
     private BindingSource _bindingSource;
 39  
 
 40  
     /**
 41  
      * @see org.apache.tapestry.pageload.IComponentVisitor#visitComponent(org.apache.tapestry.IComponent)
 42  
      */
 43  
     public void visitComponent(IComponent component)
 44  
     {
 45  0
         IComponentSpecification spec = component.getSpecification();
 46  
 
 47  0
         Iterator i = spec.getParameterNames().iterator();
 48  
 
 49  0
         while(i.hasNext())
 50  
         {
 51  0
             String name = (String) i.next();
 52  0
             IParameterSpecification parameterSpec = spec.getParameter(name);
 53  
 
 54  
             // Skip aliases
 55  
 
 56  0
             if (!name.equals(parameterSpec.getParameterName())) continue;
 57  
 
 58  0
             String defaultValue = parameterSpec.getDefaultValue();
 59  0
             if (defaultValue == null) continue;
 60  
 
 61  
             // the parameter has a default value, so it must not be required
 62  0
             if (parameterSpec.isRequired())
 63  0
                 throw new ApplicationRuntimeException(PageloadMessages
 64  
                         .parameterMustHaveNoDefaultValue(component, name),
 65  
                         component, parameterSpec.getLocation(), null);
 66  
 
 67  
             // if there is no binding for this parameter, bind it to the default
 68  
             // value.
 69  
             // In 3.0, default-value was always an OGNL expression, but now its
 70  
             // a binding reference.
 71  
 
 72  0
             if (component.getBinding(name) == null)
 73  
             {
 74  0
                 String description = PageloadMessages
 75  
                         .defaultParameterName(name);
 76  
 
 77  0
                 IBinding binding = _bindingSource.createBinding(component,
 78  
                         description, defaultValue,
 79  
                         BindingConstants.OGNL_PREFIX, parameterSpec
 80  
                                 .getLocation());
 81  
 
 82  0
                 component.setBinding(name, binding);
 83  
             }
 84  0
         }
 85  0
     }
 86  
 
 87  
     /** @since 4.0 */
 88  
 
 89  
     public void setBindingSource(BindingSource bindingSource)
 90  
     {
 91  0
         _bindingSource = bindingSource;
 92  0
     }
 93  
 }