[stringtemplate-interest] AttributeProvider interface

Sam Harwell sharwell at pixelminegames.com
Thu Sep 1 06:35:28 PDT 2011


This was added in ST4 with the ModelAdaptor interface.

 

Sam

 

From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Collin Fagan
Sent: Thursday, September 01, 2011 7:47 AM
To: stringtemplate-interest List
Subject: [stringtemplate-interest] AttributeProvider interface

 

Hi Everyone,

I'd like to be able to bridge a StringTemplate to a source of data without
explisitly calling add() for every object. As an example I would like to be
able to add every bean from a Spring application context to the scope of a
string template. I've built a model adapter that allows me to do this but I
still must push in the application context into the template. This also
forces me to do <context.beanIneed.property> instead or the much more
natural <beanINeed.property>. Would it be possible to get an something like
an "AttributeProvider" interface for an ST or STGroup that would allow me to
do this?

I'm thinking something like: 

public interface AttributeProvider {

Object getAttribute(String name) throws NoSuchAttribute;

}

I know there have been discussions about formal parameters on templates and
the few use cases where you might not want them. If you didn't have formal
paramaters then injecting you template with it's dependencies with spring
might be a good alternative. 

What do you think?

Collin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110901/a77f3708/attachment-0001.html 


More information about the stringtemplate-interest mailing list