Serge Knystautas <[EMAIL PROTECTED]> wrote: > I was wondering if there is a convenient way to restrict method calls on > objects I put into VelocityContext. I use Velocity templates to do > dynamic renders high-traffic websites, and I instantiate VelocityEngine > objects along with various POJOs that Spring assembles. These POJOs are > sort of like macros and/or scripting support, have been configured with > setter-injection, and are exposed to templates using a VelocityContext > object. > > My problem is that I intend to reuse these VelocityEngine and POJOs > across multiple requests, so I do not want to allow template authors to > call setter methods and effectively reconfigure the POJOs. > > Is there an easy way to either have Velocity prevent certain method > calls on context objects,
Well, the easy answer to this part of the question is to implement a custom Uberspect. http://jakarta.apache.org/velocity/api/org/apache/velocity/util/introspection/Uberspect.html There's examples of this on the wiki: http://wiki.apache.org/jakarta-velocity/MultiUberspect http://wiki.apache.org/jakarta-velocity/LuceneDocumentUberspect > or otherwise a way to make these POJOs immutable? Outside of the scope of velocity, but really the heart of the problem even with a custom Uberspect. At some point you either need to enumerate all objects you want to be immutable (or mutable), or you need to only stick immutable objects into the context. Personally, I think the second method is easier and safer. Why don't you stick your POJOs into the template as a wrapper object (delegate), with only the getter methods exposed? --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]