org.teatrove.tea.compiler
Class CompiledTemplate

java.lang.Object
  extended by org.teatrove.tea.compiler.CompilationUnit
      extended by org.teatrove.tea.compiler.CompiledTemplate
All Implemented Interfaces:
EventListener, ErrorListener

public class CompiledTemplate
extends CompilationUnit

Pre-compiled templates implementation. Allows for the invocation of pre-compiled templates from other dynamically compiled or pre-compiled templates. Nested calls to other pre-compiled templates must be from within the same merged context interface.

Author:
Guy A. Molinari

Constructor Summary
CompiledTemplate(String name, Compiler compiler, CompilationUnit caller)
          This constructor is only invoked when the compiler cannot locate a source file for a template and a template class of the desired name and package exists.
 
Method Summary
static boolean exists(Compiler c, String name, CompilationUnit from)
          Test to see of the template can be loaded before CompiledTemplate can be constructed.
static String getFullyQualifiedName(String name)
           
 String getName()
           
 OutputStream getOutputStream()
          Delegate to calling template.
 Template getParseTree()
          This method is called by JavaClassGenerator during the compile phase.
 Reader getReader()
          Delegate to calling template.
 Class<?> getRuntimeContext()
          Get the runtime context of the compiled template.
 String getSourceFileName()
          Source is not accessible for pre-compiled templates
 String getTargetPackage()
          Return the package name that this CompilationUnit should be compiled into.
 boolean isValid()
          Checks if the compiled template class is a precomiled template (i.e.
 void resetOutputStream()
          Delegate to calling template.
 void setParseTree(Template tree)
           
 boolean shouldCompile()
           
 
Methods inherited from class org.teatrove.tea.compiler.CompilationUnit
compileError, getCompiler, getErrorCount, getImportedPackages, getShortName, signatureEquals
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompiledTemplate

public CompiledTemplate(String name,
                        Compiler compiler,
                        CompilationUnit caller)
This constructor is only invoked when the compiler cannot locate a source file for a template and a template class of the desired name and package exists. Further verification of the template signature occurs during the call to getParseTree.

Method Detail

getName

public String getName()
Overrides:
getName in class CompilationUnit

isValid

public boolean isValid()
Checks if the compiled template class is a precomiled template (i.e. it's runtime context is an interface, not a generated MergedContext)

Returns:
true if the template class is found, has the proper template execute method, and the first parameter to the execute method (the runtime context for the template) is an interface

exists

public static boolean exists(Compiler c,
                             String name,
                             CompilationUnit from)
Test to see of the template can be loaded before CompiledTemplate can be constructed.


getFullyQualifiedName

public static String getFullyQualifiedName(String name)

getRuntimeContext

public Class<?> getRuntimeContext()
Get the runtime context of the compiled template. This is an interface for compiled templates.

Overrides:
getRuntimeContext in class CompilationUnit

getParseTree

public Template getParseTree()
This method is called by JavaClassGenerator during the compile phase. It overrides the method in CompilationUnit and returns just the reflected template signature.

Overrides:
getParseTree in class CompilationUnit

setParseTree

public void setParseTree(Template tree)
Overrides:
setParseTree in class CompilationUnit

getTargetPackage

public String getTargetPackage()
Return the package name that this CompilationUnit should be compiled into.

Overrides:
getTargetPackage in class CompilationUnit

shouldCompile

public boolean shouldCompile()
                      throws IOException
Overrides:
shouldCompile in class CompilationUnit
Returns:
true if the CompilationUnit should be compiled. Default is true.
Throws:
IOException

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Delegate to calling template.

Specified by:
getOutputStream in class CompilationUnit
Returns:
An OutputStream to write compiled code to. Returning null is disables code generation for this CompilationUnit.
Throws:
IOException

resetOutputStream

public void resetOutputStream()
Delegate to calling template.

Specified by:
resetOutputStream in class CompilationUnit

getReader

public Reader getReader()
                 throws IOException
Delegate to calling template.

Specified by:
getReader in class CompilationUnit
Returns:
A new source file reader.
Throws:
IOException

getSourceFileName

public String getSourceFileName()
Source is not accessible for pre-compiled templates

Specified by:
getSourceFileName in class CompilationUnit


Copyright © 1997-2012 TeaTrove.org. All Rights Reserved.