001 // Copyright 2006, 2008, 2009 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.tapestry5.internal.parser; 016 017 import org.apache.tapestry5.ioc.Location; 018 import org.apache.tapestry5.ioc.Resource; 019 import org.apache.tapestry5.ioc.internal.util.CollectionFactory; 020 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList; 021 import org.apache.tapestry5.ioc.internal.util.InternalUtils; 022 023 import java.util.List; 024 import java.util.Map; 025 026 public class ComponentTemplateImpl implements ComponentTemplate 027 { 028 private final Resource resource; 029 030 private final List<TemplateToken> tokens; 031 032 private final Map<String, Location> componentIds; 033 034 private final boolean extension; 035 036 private final Map<String, List<TemplateToken>> overrides; 037 038 /** 039 * @param resource the resource from which the template was parsed 040 * @param tokens the tokens of the template, a copy of this list will be made 041 * @param componentIds ids of components defined in the template 042 * @param extension 043 * @param overrides id to list of tokens for that override 044 */ 045 public ComponentTemplateImpl(Resource resource, List<TemplateToken> tokens, 046 Map<String, Location> componentIds, boolean extension, 047 Map<String, List<TemplateToken>> overrides) 048 { 049 this.resource = resource; 050 this.extension = extension; 051 this.overrides = overrides; 052 this.tokens = newList(tokens); 053 this.componentIds = CollectionFactory.newMap(componentIds); 054 } 055 056 public Resource getResource() 057 { 058 return resource; 059 } 060 061 public List<TemplateToken> getTokens() 062 { 063 return tokens; 064 } 065 066 public Map<String, Location> getComponentIds() 067 { 068 return componentIds; 069 } 070 071 /** 072 * Returns false. 073 */ 074 public boolean isMissing() 075 { 076 return false; 077 } 078 079 public List<TemplateToken> getExtensionPointTokens(String extensionPointId) 080 { 081 return InternalUtils.get(overrides, extensionPointId); 082 } 083 084 public boolean isExtension() 085 { 086 return extension; 087 } 088 }