1 16 package org.apache.cocoon.forms; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.component.Component; 20 import org.apache.avalon.framework.configuration.Configurable; 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.avalon.framework.logger.AbstractLogEnabled; 24 import org.apache.avalon.framework.service.ServiceException; 25 import org.apache.avalon.framework.service.ServiceManager; 26 import org.apache.avalon.framework.service.Serviceable; 27 import org.apache.avalon.framework.thread.ThreadSafe; 28 29 import org.apache.commons.collections.FastHashMap; 30 import org.apache.excalibur.source.Source; 31 import org.apache.excalibur.source.SourceValidity; 32 33 import java.io.IOException ; 34 import java.util.Map ; 35 36 41 public class DefaultCacheManager 42 extends AbstractLogEnabled 43 implements CacheManager, ThreadSafe, Serviceable, Disposable, 44 Configurable, Component { 45 47 protected ServiceManager manager; 48 protected Configuration configuration; 49 protected Map cache; 50 51 public DefaultCacheManager() { 52 this.cache = new FastHashMap(); 53 } 54 55 public void service(ServiceManager serviceManager) throws ServiceException { 56 this.manager = serviceManager; 57 } 58 59 62 public void configure(Configuration configuration) throws ConfigurationException { 63 this.configuration = configuration; 64 } 65 66 public Object get(Source source, String prefix) { 67 final String key = prefix + source.getURI(); 69 70 Object [] objectAndValidity = (Object []) this.cache.get(key); 72 if (objectAndValidity == null) { 73 return null; 74 } 75 76 final SourceValidity validity = (SourceValidity) objectAndValidity[1]; 78 int valid = validity.isValid(); 79 if (valid == SourceValidity.UNKNOWN) { 80 valid = validity.isValid(source.getValidity()); 82 } 83 84 if (valid != SourceValidity.VALID) { 86 this.cache.remove(key); 87 return null; 88 } 89 90 return objectAndValidity[0]; 92 } 93 94 public void set(Object object, Source source, String prefix) throws IOException { 95 final String key = prefix + source.getURI(); 96 final SourceValidity validity = source.getValidity(); 97 if (validity != null) { 98 Object [] objectAndValidity = {object, validity}; 99 this.cache.put(key, objectAndValidity); 100 } 101 } 102 103 106 public void dispose() { 107 this.manager = null; 108 this.cache = null; 109 } 110 } 111 | Popular Tags |