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 1052 2004-10-28 00:40:54Z run2000 $
Author:
Nicholas Cull

Field Summary
protected  java.util.Map<java.lang.String,Cacheable> 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 addTemplate(java.lang.String aName, Cacheable cTemplate)
          Adds a prototype template to the registry.
 java.lang.Object clone()
          Clones the current registry, and returns the clone back to the caller.
 Cacheable getTemplate(java.lang.String aKey)
          Retrieve a cloned template 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,Cacheable> 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.


getTemplate

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

Parameters:
aKey - the type of template to retrieve

addTemplate

public void addTemplate(java.lang.String aName,
                        Cacheable cTemplate)
Adds a prototype template to the registry. The template can then be cloned and retrieved from the registry on demand.

Parameters:
aName - the name of the prototype template
cTemplate - the prototype template itself

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