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
015package org.apache.tapestry.parse;
016
017/**
018 *  Enapsulates a parsed component template, allowing access to the
019 *  tokens parsed.
020 *
021 *  <p>TBD:  Record the name of the resource (or other location) from which
022 *  the template was parsed (useful during debugging).
023 *
024 *  @author Howard Lewis Ship
025 * 
026 **/
027
028public class ComponentTemplate
029{
030    /**
031     *  The HTML template from which the tokens were generated.  This is a string
032     *  read from a resource.  The tokens represents offsets and lengths into
033     *  this string.
034     *
035     **/
036
037    private char[] _templateData;
038
039    private TemplateToken[] _tokens;
040
041    /**
042     *  Creates a new ComponentTemplate.
043     *
044     *  @param templateData The template data.  This is <em>not</em> copied, so
045     *  the array passed in should not be modified further.
046     *
047     *  @param tokens  The tokens making up the template.  This is also
048     *  retained (<em>not</em> copied), and so should not
049     *  be modified once passed to the constructor.
050     *
051     **/
052
053    public ComponentTemplate(char[] templateData, TemplateToken[] tokens)
054    {
055        _templateData = templateData;
056        _tokens = tokens;
057    }
058
059    public char[] getTemplateData()
060    {
061        return _templateData;
062    }
063
064    public TemplateToken getToken(int index)
065    {
066        return _tokens[index];
067    }
068
069    public int getTokenCount()
070    {
071        return _tokens.length;
072    }
073}