Model adaptors

Skip to end of metadata
Go to start of metadata

StringTemplate lets you access the properties of injected attributes, but only if they follow the JavaBeans naming pattern ("getters") or are publicly visible fields. This works well if you control the attribute class definitions, but falls apart for some models. Some models, though, don't follow to get her method naming convention and so template expressions cannot access properties. To get around this, we need a model adaptor that makes external models look like the kind StringTemplate needs. If object o is of type T, we register a model adaptor object, a, for T that converts property references on o. Given <o.foo>, StringTemplate will ask a to get the value of property foo. As with renderers, a is a suitable adaptor if "o is instance of a's associated type". For the statically typed language ports, here are the interfaces:

 

Java
C#
Python

 

 

Property name type

Property names are usually strings but they don't have to be. For example, if o is a dictionary, the property could be of any key type. The string value of the property name is always passed to the renderer by StringTemplate.

Example

 

Java
C#
Python
Labels: