001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.internal.parser; 014 015import org.apache.tapestry5.commons.Location; 016import org.apache.tapestry5.commons.Resource; 017import org.apache.tapestry5.commons.util.CollectionFactory; 018import org.apache.tapestry5.ioc.internal.util.InternalUtils; 019 020import static org.apache.tapestry5.commons.util.CollectionFactory.newList; 021 022import java.util.List; 023import java.util.Map; 024 025public class ComponentTemplateImpl implements ComponentTemplate 026{ 027 private final Resource resource; 028 029 private final List<TemplateToken> tokens; 030 031 private final Map<String, Location> componentIds; 032 033 private final boolean extension, strictMixinParameters; 034 035 private final Map<String, List<TemplateToken>> overrides; 036 037 /** 038 * @param resource 039 * the resource from which the template was parsed 040 * @param tokens 041 * the tokens of the template, a copy of this list will be made 042 * @param componentIds 043 * ids of components defined in the template 044 * @param extension 045 * if this template is an extension of a parent-class template 046 * @param strictMixinParameters 047 * if the template was parsed with the 5.4 DTD and is strict 048 * about mixin parameters being fully qualified 049 * @param overrides 050 * id to list of tokens for that override 051 */ 052 public ComponentTemplateImpl(Resource resource, List<TemplateToken> tokens, 053 Map<String, Location> componentIds, boolean extension, 054 boolean strictMixinParameters, Map<String, List<TemplateToken>> overrides) 055 { 056 this.resource = resource; 057 this.extension = extension; 058 this.strictMixinParameters = strictMixinParameters; 059 this.overrides = overrides; 060 this.tokens = newList(tokens); 061 this.componentIds = CollectionFactory.newMap(componentIds); 062 } 063 064 public Resource getResource() 065 { 066 return resource; 067 } 068 069 public List<TemplateToken> getTokens() 070 { 071 return tokens; 072 } 073 074 public Map<String, Location> getComponentIds() 075 { 076 return componentIds; 077 } 078 079 public boolean usesStrictMixinParameters() 080 { 081 return strictMixinParameters; 082 } 083 084 /** 085 * Returns false. 086 */ 087 public boolean isMissing() 088 { 089 return false; 090 } 091 092 public List<TemplateToken> getExtensionPointTokens(String extensionPointId) 093 { 094 return InternalUtils.get(overrides, extensionPointId); 095 } 096 097 public boolean isExtension() 098 { 099 return extension; 100 } 101}