commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark McLaren <mark.mcla...@gmail.com>
Subject LazyMap that always calls transform, good idea?
Date Tue, 21 Apr 2009 08:51:07 GMT
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


Mime
View raw message