org.quattor.pan.template
Class Template

java.lang.Object
  extended by org.quattor.pan.template.Template

public class Template
extends java.lang.Object

An immutable Template class that corresponds to a single pan language template. At creation, some additional constraints are enforced which are not caught by the parsing process. The constructor will throw a SyntaxException if any of the additional constraints are not met.

Author:
loomis

Nested Class Summary
static class Template.TemplateType
          An enumeration of the possible template types.
 
Field Summary
 java.lang.String name
          The (valid) name of this template.
 java.io.File source
          The source from which this template was constructed.
 SourceFile sourceFile
          Information about the source file from which this template was constructed.
 Template.TemplateType type
          The type of this template.
static java.util.regex.Pattern validTemplateNameChars
          Pattern with all valid characters for namespaced name.
 
Constructor Summary
Template(java.io.File source, SourceRange sourceRange, Template.TemplateType type, java.lang.String name, java.util.List<Statement> statements)
          Constructs a new template from the given information.
Template(java.lang.String name)
          Constructs a new object template with the given name which contains no statements.
 
Method Summary
static boolean checkValidInclude(Template.TemplateType includeeType, Template.TemplateType includedType)
          Determine whether a particular include combination is legal.
 void execute(boolean runStatic, Context context)
          Execute each of the statements in turn.
static boolean isValidTemplateName(java.lang.String name)
          Check to see if the given name is a valid template name.
 void templateNameVerification(java.lang.String expectedName)
          Check that the internal template name matches the expected template name.
 java.lang.String toString()
          Create a reasonable string representation of this template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

validTemplateNameChars

public static final java.util.regex.Pattern validTemplateNameChars
Pattern with all valid characters for namespaced name. This also requires that the name not be the empty string.


sourceFile

public final SourceFile sourceFile
Information about the source file from which this template was constructed.


source

public final java.io.File source
The source from which this template was constructed. This must be an absolute File or null.


name

public final java.lang.String name
The (valid) name of this template.


type

public final Template.TemplateType type
The type of this template.

Constructor Detail

Template

public Template(java.lang.String name)
         throws SyntaxException
Constructs a new object template with the given name which contains no statements. This is intended as a convenience for testing.

Throws:
SyntaxException

Template

public Template(java.io.File source,
                SourceRange sourceRange,
                Template.TemplateType type,
                java.lang.String name,
                java.util.List<Statement> statements)
         throws SyntaxException
Constructs a new template from the given information. Additional constraints are applied which are not caught by the parser. If any of the additional constraints fail, an SyntaxException is thrown.

Parameters:
source - absolute File indicating the source pan language template; used for error messages and logging; may be null
sourceRange - the source range for the template declaration
type - TemplateType for this template
name - String indicating the name of this template
statements - List of statements in this template (may be null)
Throws:
SyntaxException
Method Detail

isValidTemplateName

public static boolean isValidTemplateName(java.lang.String name)
Check to see if the given name is a valid template name. Valid template names may include only letters, digits, underscores, hyphens, periods, pluses, and slashes. In addition, each term when split by slashes must not be empty and must not start with a period. The second case excludes potential hidden files and special names like "." and "..".

Parameters:
name - template name to check for validity
Returns:
boolean value indicating if the given name is a valid template name

execute

public void execute(boolean runStatic,
                    Context context)
Execute each of the statements in turn.

Parameters:
runStatic - flag which indicates whether to run the static statements or not
context - context for the evaluation of the template

checkValidInclude

public static boolean checkValidInclude(Template.TemplateType includeeType,
                                        Template.TemplateType includedType)
Determine whether a particular include combination is legal.

Parameters:
includeeType - type of the template that is including another one
includedType - type of the included template
Returns:
flag indicating whether this is a legal combination

templateNameVerification

public void templateNameVerification(java.lang.String expectedName)
                              throws SyntaxException
Check that the internal template name matches the expected template name.

Parameters:
expectedName - expected name of the compiled template
Throws:
SyntaxException

toString

public java.lang.String toString()
Create a reasonable string representation of this template.

Overrides:
toString in class java.lang.Object


Copyright © 2011 Quattor. All Rights Reserved.