Re: Determining which BeansWrapper was used to wrap an object in the data model

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Monday, February 21, 2011, 11:22:42 PM, Rebecca Younes wrote:

> My Configuration uses a BeansWrapper with exposure level
> EXPOSE_PROPERTIES_ONLY to wrap template model objects by default.
> Sometimes I use a more permissive wrapper to wrap specific objects.
> When retrieving the data model from the template processing
> environment (for example, inside a Java directive called from the
> template), is there any way to determine which type of wrapper was
> used to wrap a particular object, so that I can determine which
> methods of the object are available to the template? I've looked at
> methods of DeepUnwrap and don't see anything that serves this purpose.

I don't think there is a *clean* way... How the wrapper is associated
with the wrapped values depends on the wrapper implementation, and in
the case of BeansWrapper it will be stored in the protected field
"wrapper". Since it's protected, you can't access it from outside.
Except, since it's protected, you can access it from the same package.
So if you define an WrapperExtractor class in the freemarker.ext.beans
package... you can get it after all.

> Thank you.
>
> Rebecca Younes

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Index, Search & Analyze Logs and other IT data in Real-Time with Splunk 
Collect, index and harness all the fast moving IT data generated by your 
applications, servers and devices whether physical, virtual or in the cloud.
Deliver compliance at lower cost and gain new business insights. 
Free Software Download: http://p.sf.net/sfu/splunk-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.