type safe templating

Generated Template Classes

Jamon templates are translated into Java classes, either by using the Jamon ant task, or by executing the TemplateProcessor class. These generated classes have the following relationships to the template sources: For example, suppose there is a template MyTemplate in the directory tmpls/org/foo, the template source directory is set to tmpls, and MyTemplate contains the declarations
<%args>
  int i;
  String s = "yes";
  java.math.BigDecimal someNumber = null;
  boolean b;
</%args>
Suppose further that in tmpls is a jamon.properties file containing
org.jamon.contextType=org.foo.MyContext
Then a simplified sketch (showing only the pertinent public methods) of the generated class would be:
  package org.foo;

  import org.jamon.TemplateManager;
  import org.jamon.escaping.Escaping;

  public class MyTemplate
    extends org.jamon.AbstractTemplateProxy
  {
    public MyTemplate() { ... }
    public MyTemplate(TemplateManager manager) { ... }

    public void render(int i, boolean b)
      throws java.io.IOException { ... }

    public Renderer makeRenderer(java.io.Writer writer, int i, boolean b)
      throws java.io.IOException { ... }

    public MyTemplate setS(String s) { ... }

    public MyTemplate setSomeNumber(java.math.BigDecimal someNumber) { ... }

    public MyTemplate setJamonContext(org.foo.MyContext jamonContext() { ... }
  }
If one template inherits from another, then: For example, if /org/foo/ParentTemplate contained the declarations
<%args>
  int i;
  String s = "yes";
  Integer count;
</%args>
then the generated class org.foo.ParentTemplate would look something like:
  package org.foo;

  import org.jamon.escaping.Escaping;

  public abstract class ParentTemplate
    extends org.jamon.AbstractTemplateProxy
  {
    public ParentTemplate setS(String s) { ... }

    public abstract class ParentRenderer
    {
      public ParentRenderer setS(String s) { ... }

      public ParentRenderer setJamonContext(org.foo.MyContext jamonContext) { ... }

      public void render(java.io.Writer writer, int i, Integer count)
        throws java.io.IOException { ... }
    }
  }
Moreover, if /org/foo/ChildTemplate contained the declarations
<%extends ParentTemplate>
<%args>
  long t;
  java.math.BigDecimal amount = new BigDecimal(0);
  double x;
</%args>
then the generated class org.foo.ChildTemplate would look something like:
  package org.foo;

  import org.jamon.TemplateManager;
  import org.jamon.escaping.Escaping;

  public abstract class ChildTemplate
    extends org.foo.ParentTemplate
  {
    public ChildTemplate() { ... }
    public ChildTemplate(TemplateManager manager) { ... }

    public void render(java.io.Writer writer, int i, Integer count, long t, double x)
      throws java.io.IOException { ... }

    public Renderer makeRenderer(int i, Integer count, long t, double x)
      throws java.io.IOException { ... }

    public ChildTemplate setAmount(java.math.BigDecimal amount) { ... }

    public ChildTemplate setJamonContext(org.foo.MyContext jamonContext) { ... }

    public ParentTemplate.ParentRenderer makeParentRenderer(long t, double x)
      throws java.io.IOException { ... }
  }
An instantiated template may be used at most once.