Interface JStachioTemplateFinder

All Superinterfaces:

public non-sealed interface JStachioTemplateFinder extends JStachioExtension
Finds templates based on the model type (class).

The default JStachio uses a combination of relection and the ServiceLoader to find templates.

Other implementations may want to use their DI framework like Spring or CDI to find templates.

  • Method Details

    • findTemplate

      TemplateInfo findTemplate(Class<?> modelType) throws Exception
      Finds a Template if possible otherwise possibly falling back to a TemplateInfo based on annotation metadata or some other mechanism.
      modelType - the models class (the one annotated with JStache and not the Templates class)
      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 TemplateInfo metadata.
    • supportsType

      default boolean supportsType(Class<?> modelType)
      Determines if this template finder has a template for the model type (the class annotated by JStache).
      modelType - the models class (the one annotated with JStache and not the Templates class)
      true if this finder has template for modelType
    • order

      default int order()
      Hint on order of template finders. The found JStachioTemplateFinders are sorted naturally (lower number comes first) based on the returned number. Thus a template finder with a lower order number that supportsType(Class) the model class will be used.
      default returns zero
    • defaultTemplateFinder

      The default template finder that uses reflection and or the ServiceLoader.

      This implementation performs no caching. If you would like caching call cachedTemplateFinder(JStachioTemplateFinder) on the returned finder.

      config - used to help find templates as well as logging.
      default template finder.
    • cachedTemplateFinder

      Decorates a template finder with a cache using ClassValue with the modelType as the key.

      While the finder does not provide any eviction the cache will not prevent garbage collection of the model classes.

      finder - to be decorated unless the finder is already decorated thus it is a noop to repeateadly call this method on already cached template finder.
      caching template finder