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.services.impl; 016 017 import org.apache.hivemind.Location; 018 import org.apache.tapestry.IComponent; 019 import org.apache.tapestry.INamespace; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.Tapestry; 022 import org.apache.tapestry.parse.ITemplateParserDelegate; 023 import org.apache.tapestry.resolver.ComponentSpecificationResolver; 024 import org.apache.tapestry.spec.IComponentSpecification; 025 026 /** 027 * Default implementation of {@link org.apache.tapestry.parse.ITemplateParserDelegate}. 028 * 029 * @author Howard Lewis Ship 030 * @since 4.0 031 */ 032 public class DefaultParserDelegate implements ITemplateParserDelegate 033 { 034 private IComponent _component; 035 036 private ComponentSpecificationResolver _resolver; 037 038 private IRequestCycle _cycle; 039 040 private String _componentAttributeName; 041 042 public DefaultParserDelegate(IComponent component, String componentAttributeName, 043 IRequestCycle cycle, ComponentSpecificationResolver resolver) 044 { 045 _component = component; 046 _componentAttributeName = componentAttributeName; 047 _resolver = resolver; 048 _cycle = cycle; 049 } 050 051 public boolean getKnownComponent(String componentId) 052 { 053 return _component.getSpecification().getComponent(componentId) != null; 054 } 055 056 public boolean getAllowBody(String componentId, Location location) 057 { 058 IComponent embedded = _component.getComponent(componentId); 059 060 if (embedded == null) 061 throw Tapestry.createNoSuchComponentException(_component, componentId, location); 062 063 return embedded.getSpecification().getAllowBody(); 064 } 065 066 public boolean getAllowBody(String libraryId, String type, Location location) 067 { 068 INamespace namespace = _component.getNamespace(); 069 070 _resolver.resolve(_cycle, namespace, libraryId, type, location); 071 072 IComponentSpecification spec = _resolver.getSpecification(); 073 074 return spec.getAllowBody(); 075 } 076 077 public String getComponentAttributeName() 078 { 079 return _componentAttributeName; 080 } 081 }