freemarker.template.cache
Class TemplateRegistry

java.lang.Object
  extended by freemarker.template.cache.TemplateRegistry
All Implemented Interfaces:
java.lang.Cloneable

public class TemplateRegistry
extends java.lang.Object
implements java.lang.Cloneable

Stores a register of prototype templates, which can be retrieved by the template cache whenever it needs to compile a template. This allows the cache to store and retrieve different template implementations as required.

This is an implementation of the Parameterized Factory Method pattern.

Version:
$Id: TemplateRegistry.java 1153 2013-04-15 10:59:37Z run2000 $
Author:
Nicholas Cull

Field Summary
protected  java.util.Map<java.lang.String,CompileableFactory> m_cTemplates
          A map of template types that can be instantiated by this object.
 
Constructor Summary
TemplateRegistry()
          Creates new TemplateRegistry.
TemplateRegistry(TemplateRegistry cOriginal)
          Creates a new TemplateRegistry as a clone of an existing one.
 
Method Summary
 void addFactory(CompileableFactory cFactory)
          Adds a template factory to the registry.
 java.lang.Object clone()
          Clones the current registry, and returns the clone back to the caller.
 CompileableFactory getFactory(java.lang.String aKey)
          Retrieve a template factory from the registry.
protected  void registerDefaultTemplates()
          Registers the templates that will be held in this template registry.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_cTemplates

protected java.util.Map<java.lang.String,CompileableFactory> m_cTemplates
A map of template types that can be instantiated by this object.

Constructor Detail

TemplateRegistry

public TemplateRegistry()
Creates new TemplateRegistry.


TemplateRegistry

public TemplateRegistry(TemplateRegistry cOriginal)
Creates a new TemplateRegistry as a clone of an existing one.

Parameters:
cOriginal - the original TemplateRegistry to be cloned
Method Detail

registerDefaultTemplates

protected void registerDefaultTemplates()
Registers the templates that will be held in this template registry. This method may be subclassed to provide alternate template sets.


getFactory

public CompileableFactory getFactory(java.lang.String aKey)
Retrieve a template factory from the registry. The returned factory can then be used to create a compiled template from a given source.

Parameters:
aKey - the type of template factory to retrieve

addFactory

public void addFactory(CompileableFactory cFactory)
Adds a template factory to the registry. The factory can then be retrieved from the registry on demand to create new template instances.

Parameters:
cFactory - the template factory

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the current registry, and returns the clone back to the caller. The clone operation performed here is a shallow clone.

Overrides:
clone in class java.lang.Object
Returns:
a clone of the current TemplateRegistry
Throws:
java.lang.CloneNotSupportedException

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the object