Element childElement = DOMUtils.getFirstChildOrFail(e);
if (filterCache == null)
{
filterCache = new LRUCache(cacheSize);
}
// Test to see if child Element is a query or filter that needs to be
// cached
QueryBuilder qb = queryFactory.getQueryBuilder(childElement
.getNodeName());
Object cacheKey = null;
Query q = null;
Filter f = null;
if (qb != null)
{
q = qb.getQuery(childElement);
cacheKey = q;
} else
{
f = filterFactory.getFilter(childElement);
cacheKey = f;
}
Filter cachedFilter = null;
synchronized (filterCache)
{ // check cache
cachedFilter = (Filter) filterCache.get(cacheKey);
if (cachedFilter != null)
{
return cachedFilter; // cache hit
}
}
//cache miss
if (qb != null)
{
cachedFilter = new QueryFilter(q);
} else
{
cachedFilter = new CachingWrapperFilter(f);
}
synchronized (filterCache)
{ // update cache
filterCache.put(cacheKey, cachedFilter);
}
return cachedFilter;