Class Templates


public final class Templates extends Object
Locates generated templates by their model via reflection.

This utility class is useful if you plan on implementing your own JStachio and or other integrations.

API Note
In order to use reflection in a modular setup one must open packages to the io.jstach.jstachio module.
  • Method Details

    • findTemplate

      public static TemplateInfo findTemplate(Class<?> modelType, JStachioConfig config) throws Exception
      Finds a Template if possible otherwise falling back to a TemplateInfo based on annotation metadata. This method is effectively calls getTemplate(Class) first and if that fails possibly tries getInfoByReflection(Class) based on config.
      modelType - the models class (the one annotated with JStache and not the Templates class)
      config - config used to determine whether or not to fallback
      the template info which might be a Template if the generated template was found.
      Exception - if any reflection error happes or the template is not found
      API Note
      Callers can do an instanceof Template t to see if a generated template was returned instead of the fallback.
    • getInfoByReflection

      public static TemplateInfo getInfoByReflection(Class<?> modelType) throws Exception
      Finds template info by accessing JStache annotations through reflective lookup.

      This allows you to lookup template meta data regardless of whether or not the annotation processor has generated code. This method is mainly used for fallback mechanisms and extensions.

      Why might you need the reflective data instead of the static generated meta data? Well often times the annotation processor in a hot reload environment such as JRebel, JBoss modules, or Spring Reload has not generated the code from a JStache model and or it is not desired. This allows reflection based engines like JMustache to keep working even if code is not generated.

      modelType - the class that is annotated with JStache
      template info meta data
      Exception - if any reflection error happes or the template is not found
    • getTemplate

      public static <T> Template<T> getTemplate(Class<T> clazz) throws Exception
      Finds a template by reflection or an exception is thrown.
      Type Parameters:
      T - the model type
      clazz - the model type
      the template never null.
      ClassNotFoundException - if the template is not found
      Exception - if the template is not found or any reflective access errors