java.lang.Object
io.jstach.jstachio.spi.Templates
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.
- Author:
- agentgt
- API Note
- In order to use reflection in a modular setup one must
open
packages to theio.jstach.jstachio
module.
-
Method Summary
Modifier and TypeMethodDescriptionstatic TemplateInfo
findTemplate
(Class<?> modelType, JStachioConfig config) Finds aTemplate
if possible otherwise falling back to aTemplateInfo
based on annotation metadata.static TemplateInfo
getInfoByReflection
(Class<?> modelType) Finds template info by accessing JStache annotations through reflective lookup.static <T> Template<T>
getTemplate
(Class<T> clazz) Finds a template by reflection or an exception is thrown.
-
Method Details
-
findTemplate
Finds aTemplate
if possible otherwise falling back to aTemplateInfo
based on annotation metadata. This method is effectively callsgetTemplate(Class)
first and if that fails possibly triesgetInfoByReflection(Class)
based on config.- Parameters:
modelType
- the models class (the one annotated withJStache
and not the Templates class)config
- config used to determine whether or not to fallback- Returns:
- the template info which might be a
Template
if the generated template was found. - Throws:
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
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.
-
getTemplate
Finds a template by reflection or an exception is thrown.- Type Parameters:
T
- the model type- Parameters:
clazz
- the model type- Returns:
- the template never
null
. - Throws:
ClassNotFoundException
- if the template is not foundException
- if the template is not found or any reflective access errors
-