001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.pageload; 016 017 import java.util.Iterator; 018 019 import org.apache.hivemind.ApplicationRuntimeException; 020 import org.apache.tapestry.IComponent; 021 import org.apache.tapestry.spec.IComponentSpecification; 022 import org.apache.tapestry.spec.IParameterSpecification; 023 024 /** 025 * Verify whether all required parameters in the examined component are bound, and if they are not, 026 * throw an exception. 027 * 028 * @author mindbridge 029 * @since 3.0 030 */ 031 public class VerifyRequiredParametersVisitor implements IComponentVisitor 032 { 033 /** 034 * @see org.apache.tapestry.pageload.IComponentVisitor#visitComponent(org.apache.tapestry.IComponent) 035 */ 036 public void visitComponent(IComponent component) 037 { 038 IComponentSpecification spec = component.getSpecification(); 039 040 Iterator i = spec.getRequiredParameters().iterator(); 041 042 while (i.hasNext()) 043 { 044 IParameterSpecification parameterSpec = (IParameterSpecification) i.next(); 045 046 String name = parameterSpec.getParameterName(); 047 048 if (component.getBinding(name) == null) 049 throw new ApplicationRuntimeException(PageloadMessages.requiredParameterNotBound( 050 name, 051 component), component, component.getLocation(), null); 052 } 053 } 054 055 }