You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mark McLaren <ma...@gmail.com> on 2009/04/21 10:51:07 UTC

LazyMap that always calls transform, good idea?

I am using LazyMaps as a mechanism to get lookup functionality into
JSTL/JSP pages and also inside servlet filters.  For example, inside a
servlet filter I have a HttpServletRequestWrapper implementation which
includes a method:

public Map getIsUserInRole()

This means I can fool JSTL into doing a dynamic user lookup by using:

${pageContext.request.isUserInRole['admin']}

I ran into an issue that my LazyMap was always caching the result
(this is how it is supposed to work!) but sometimes the back end value
changes.  So I created a modified version of LazyMap, which I called
ClearingLazyMap, that never stores any values into the map and always
does a lookup (using transform).  Therefore the modified "get" method
now looks like:

public Object get(Object key) {
    return factory.transform(key);
}

This seems to work well for me, is it a good idea or am I missing something?

Mark
-- 
"Paradoxically, the more time saving abstractions you are using the
more you actually have to know." - Simon Willison

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org