1 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 34 public class EstablishDefaultParameterValuesVisitor implements IComponentVisitor 35 { 36 37 private BindingSource _bindingSource; 38 39 42 public void visitComponent(IComponent component) 43 { 44 IComponentSpecification spec = component.getSpecification(); 45 46 Iterator i = spec.getParameterNames().iterator(); 47 48 while (i.hasNext()) 49 { 50 String name = (String ) i.next(); 51 IParameterSpecification parameterSpec = spec.getParameter(name); 52 53 55 if (! name.equals(parameterSpec.getParameterName())) 56 continue; 57 58 String defaultValue = parameterSpec.getDefaultValue(); 59 if (defaultValue == null) 60 continue; 61 62 if (parameterSpec.isRequired()) 64 throw new ApplicationRuntimeException(PageloadMessages 65 .parameterMustHaveNoDefaultValue(component, name), component, parameterSpec 66 .getLocation(), null); 67 68 71 if (component.getBinding(name) == null) 72 { 73 String description = PageloadMessages.defaultParameterName(name); 74 75 String defaultBindingType = parameterSpec.getDefaultBindingType(); 76 if (defaultBindingType == null) 77 defaultBindingType = BindingConstants.OGNL_PREFIX; 78 79 IBinding binding = _bindingSource.createBinding( 80 component, 81 description, 82 defaultValue, 83 defaultBindingType, 84 parameterSpec.getLocation()); 85 86 component.setBinding(name, binding); 87 } 88 } 89 } 90 91 92 93 public void setBindingSource(BindingSource bindingSource) 94 { 95 _bindingSource = bindingSource; 96 } 97 } | Popular Tags |