Author: vgritsenko Date: Thu Apr 14 08:19:44 2005 New Revision: 161303 URL: http://svn.apache.org/viewcvs?view=rev&rev=161303 Log: perform validity check in accordance with contract
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/DefaultCacheManager.java Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/DefaultCacheManager.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/DefaultCacheManager.java?view=diff&r1=161302&r2=161303 ============================================================================== --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/DefaultCacheManager.java (original) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/DefaultCacheManager.java Thu Apr 14 08:19:44 2005 @@ -15,8 +15,6 @@ */ package org.apache.cocoon.forms; -import java.io.IOException; - import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; @@ -26,22 +24,31 @@ import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.thread.ThreadSafe; + import org.apache.commons.collections.FastHashMap; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceValidity; +import java.io.IOException; +import java.util.Map; + /** * Component implementing the [EMAIL PROTECTED] CacheManager} role. * * @version $Id$ */ public class DefaultCacheManager - extends AbstractLogEnabled - implements CacheManager, ThreadSafe, Serviceable, Disposable, Configurable { + extends AbstractLogEnabled + implements CacheManager, ThreadSafe, Serviceable, Disposable, + Configurable { protected ServiceManager manager; protected Configuration configuration; - protected FastHashMap cache = new FastHashMap(); + protected Map cache; + + public DefaultCacheManager() { + this.cache = new FastHashMap(); + } public void service(ServiceManager serviceManager) throws ServiceException { this.manager = serviceManager; @@ -55,34 +62,25 @@ } public Object get(Source source, String prefix) { - String key = prefix + source.getURI(); - SourceValidity newValidity = source.getValidity(); - - // If source is not valid then remove object from cache and return null - if (newValidity == null) { - this.cache.remove(key); - return null; - } + // Create a cache key + final String key = prefix + source.getURI(); - // If object is not in cache then return null + // If object is not in the cache then return null Object[] objectAndValidity = (Object[]) this.cache.get(key); if (objectAndValidity == null) { return null; } - // Check stored validity against current source validity - SourceValidity storedValidity = (SourceValidity) objectAndValidity[1]; - int valid = storedValidity.isValid(); - boolean isValid; + // If object is in the cache, check stored object validity + final SourceValidity validity = (SourceValidity) objectAndValidity[1]; + int valid = validity.isValid(); if (valid == SourceValidity.UNKNOWN) { - valid = storedValidity.isValid(newValidity); - isValid = (valid == SourceValidity.VALID); - } else { - isValid = (valid == SourceValidity.VALID); + // Compare against current source validity + valid = validity.isValid(source.getValidity()); } // If stored object is not valid then remove object from cache and return null - if (!isValid) { + if (valid != SourceValidity.VALID) { this.cache.remove(key); return null; } @@ -92,11 +90,11 @@ } public void set(Object object, Source source, String prefix) throws IOException { - String key = prefix + source.getURI(); - SourceValidity validity = source.getValidity(); + final String key = prefix + source.getURI(); + final SourceValidity validity = source.getValidity(); if (validity != null) { Object[] objectAndValidity = {object, validity}; - cache.put(key, objectAndValidity); + this.cache.put(key, objectAndValidity); } }