Interface AdapterTemplateModel

All Superinterfaces:
TemplateModel
All Known Implementing Classes:
ArrayModel, BeanModel, BooleanModel, CollectionModel, DateModel, DefaultArrayAdapter, DefaultEnumerationAdapter, DefaultIterableAdapter, DefaultIteratorAdapter, DefaultListAdapter, DefaultMapAdapter, DefaultNonListCollectionAdapter, EnumerationModel, GenericObjectModel, IteratorModel, JythonHashModel, JythonModel, JythonNumberModel, JythonSequenceModel, MapModel, NodeModel, NumberModel, ResourceBundleModel, RhinoFunctionModel, RhinoScriptableModel, SimpleMapModel, StringModel

public interface AdapterTemplateModel extends TemplateModel
A TemplateModel that can be unwrapped and then it considers a provided desired (hint) class. This is useful when multiple languages has to communicate with each other through FreeMarker. For example, if we have a model that wraps a Jython object, then we have to unwrap that differently when we pass it to plain Java method and when we pass it to a Jython method.

This is rarely implemented by applications. It is typically implemented by the model classes belonging to ObjectWrapper-s.

  • Field Summary

    Fields inherited from interface freemarker.template.TemplateModel

    NOTHING
  • Method Summary

    Modifier and Type
    Method
    Description
    getAdaptedObject​(Class<?> hint)
    Retrieves the underlying object, or some other object semantically equivalent to its value narrowed by the class hint.
  • Method Details

    • getAdaptedObject

      Object getAdaptedObject(Class<?> hint)
      Retrieves the underlying object, or some other object semantically equivalent to its value narrowed by the class hint.
      Parameters:
      hint - the desired class of the returned value. An implementation should make reasonable effort to retrieve an object of the requested class, but if that is impossible, it must at least return the underlying object as-is. As a minimal requirement, an implementation must always return the exact underlying object when hint.isInstance(underlyingObject) holds. When called with java.lang.Object.class, it should return a generic Java object (i.e. if the model is wrapping a scripting language object that is further wrapping a Java object, the deepest underlying Java object should be returned).
      Returns:
      the underlying object, or its value accommodated for the hint class.