Update of /cvsroot/webmacro/webmacro/src/org/webmacro/resource In directory sc8-pr-cvs1:/tmp/cvs-serv6675/src/org/webmacro/resource Modified Files: AbstractTemplateLoader.java BrokerTemplateLoader.java BrokerTemplateProvider.java BrokerTemplateProviderHelper.java CacheElement.java CacheManager.java CacheReloadContext.java CachingProvider.java ClassPathTemplateLoader.java ConfigProvider.java DefaultTemplateLoaderFactory.java DelegatingTemplateProvider.java FileTemplateLoader.java GenerationalCacheManager.java HMapCacheManager.java InvalidResourceException.java ReloadDelayDecorator.java ResourceLoader.java SMapCacheManager.java ServletContextTemplateLoader.java StaticIdentityCacheManager.java StaticSMapCacheManager.java TemplateLoader.java TemplateLoaderFactory.java TemplateLoaderHelper.java TemplatePathTemplateLoader.java TemplateProvider.java TimedReloadContext.java TrivialCacheManager.java URLTemplate.java URLTemplateProvider.java UrlProvider.java Log Message: If this doesn't drive our SF "activity" stats through the roof, I don't know what will. Mass re-formatting of all code, following (to the best of my interpertation) the Sun (w/ jakarta tweaks) coding style guidelines defined here: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html and here: http://jakarta.apache.org/turbine/common/code-standards.html I did this reformatting with IDEA 3.0.5, and I am going to commit the style configuration for IDEA (if I can find it). Index: AbstractTemplateLoader.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/AbstractTemplateLoader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractTemplateLoader.java 11 Jun 2002 17:43:22 -0000 1.3 --- AbstractTemplateLoader.java 12 Jun 2003 00:47:47 -0000 1.4 *************** *** 33,57 **** * @author Sebastian Kanthak <ska...@mu...> */ ! public abstract class AbstractTemplateLoader implements TemplateLoader { ! /** Our broker */ ! protected Broker broker; ! /** Log to use */ ! protected Log log; ! /** Helper class for loading templates from files or URLs */ ! protected TemplateLoaderHelper helper; ! /** ! * Sets up broker, reloadDelayDecorator and log. ! * Don't forget to call super.init() if you override this ! * method. ! */ ! public void init(Broker b, Settings config) throws InitException { ! this.broker = b; ! log = b.getLog("resource", "Loading templates"); ! helper = new TemplateLoaderHelper(); ! helper.init(b, config); ! } } --- 33,59 ---- * @author Sebastian Kanthak <ska...@mu...> */ ! public abstract class AbstractTemplateLoader implements TemplateLoader ! { ! /** Our broker */ ! protected Broker broker; ! /** Log to use */ ! protected Log log; ! /** Helper class for loading templates from files or URLs */ ! protected TemplateLoaderHelper helper; ! /** ! * Sets up broker, reloadDelayDecorator and log. ! * Don't forget to call super.init() if you override this ! * method. ! */ ! public void init (Broker b, Settings config) throws InitException ! { ! this.broker = b; ! log = b.getLog("resource", "Loading templates"); ! helper = new TemplateLoaderHelper(); ! helper.init(b, config); ! } } Index: BrokerTemplateLoader.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/BrokerTemplateLoader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BrokerTemplateLoader.java 11 Nov 2002 19:22:37 -0000 1.3 --- BrokerTemplateLoader.java 12 Jun 2003 00:47:47 -0000 1.4 *************** *** 22,47 **** package org.webmacro.resource; - import java.net.URL; - import org.webmacro.ResourceException; import org.webmacro.Template; ! public class BrokerTemplateLoader extends AbstractTemplateLoader { ! public void setConfig(String config) { ! // ignore config ! if (config != null && config.length() > 0) { ! if (log.loggingWarning()) { ! log.warning("BrokerTemplateProvider: Ignoring configuration options " + config); ! } ! } ! } ! public final Template load(String query, CacheElement ce) throws ResourceException { ! URL url = broker.getTemplate(query); ! if (url != null && log.loggingDebug()) { ! log.debug("BrokerTemplateLoader: Found Template " + url.toString()); ! } ! return (url != null) ? helper.load(url, ce) : null; ! } } --- 22,53 ---- package org.webmacro.resource; import org.webmacro.ResourceException; import org.webmacro.Template; ! import java.net.URL; ! public class BrokerTemplateLoader extends AbstractTemplateLoader ! { ! public void setConfig (String config) ! { ! // ignore config ! if (config != null && config.length() > 0) ! { ! if (log.loggingWarning()) ! { ! log.warning("BrokerTemplateProvider: Ignoring configuration options " + config); ! } ! } ! } ! ! public final Template load (String query, CacheElement ce) throws ResourceException ! { ! URL url = broker.getTemplate(query); ! if (url != null && log.loggingDebug()) ! { ! log.debug("BrokerTemplateLoader: Found Template " + url.toString()); ! } ! return (url != null) ? helper.load(url, ce) : null; ! } } Index: BrokerTemplateProvider.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/BrokerTemplateProvider.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BrokerTemplateProvider.java 12 Jun 2002 17:35:34 -0000 1.4 --- BrokerTemplateProvider.java 12 Jun 2003 00:47:47 -0000 1.5 *************** *** 37,63 **** * @see BrokerTemplateProviderHelper */ ! final public class BrokerTemplateProvider extends CachingProvider { ! private BrokerTemplateProviderHelper _helper; ! private Log _log; ! public void init(Broker b, Settings config) throws InitException { ! super.init(b, config); ! _helper = new BrokerTemplateProviderHelper(); ! _helper.init(b, config); ! _helper.setReload(_cacheSupportsReload); ! _log = b.getLog("resource", "Object loading and caching"); ! } ! final public String getType() { ! return "template"; ! } ! final public Object load(String name, CacheElement ce) ! throws ResourceException { ! if (_log.loggingInfo()) ! _log.info("Loading template: " + name); ! return _helper.load(name, ce); ! } } --- 37,67 ---- * @see BrokerTemplateProviderHelper */ ! final public class BrokerTemplateProvider extends CachingProvider ! { ! private BrokerTemplateProviderHelper _helper; ! private Log _log; ! public void init (Broker b, Settings config) throws InitException ! { ! super.init(b, config); ! _helper = new BrokerTemplateProviderHelper(); ! _helper.init(b, config); ! _helper.setReload(_cacheSupportsReload); ! _log = b.getLog("resource", "Object loading and caching"); ! } ! final public String getType () ! { ! return "template"; ! } ! final public Object load (String name, CacheElement ce) ! throws ResourceException ! { ! if (_log.loggingInfo()) ! _log.info("Loading template: " + name); ! return _helper.load(name, ce); ! } } Index: BrokerTemplateProviderHelper.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/BrokerTemplateProviderHelper.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** BrokerTemplateProviderHelper.java 12 Jun 2002 17:35:34 -0000 1.10 --- BrokerTemplateProviderHelper.java 12 Jun 2003 00:47:47 -0000 1.11 *************** *** 24,30 **** package org.webmacro.resource; - import java.io.*; - import java.net.URL; - import org.webmacro.*; import org.webmacro.engine.FileTemplate; --- 24,27 ---- *************** *** 33,36 **** --- 30,37 ---- import org.webmacro.util.Settings; + import java.io.File; + import java.io.IOException; + import java.net.URL; + /** * This class does the actual work of retrieving templates using the *************** *** 44,181 **** */ final public class BrokerTemplateProviderHelper ! implements ResourceLoader { ! // INITIALIZATION ! private Broker _broker; ! private int _cacheDuration; ! private Log _log; ! private boolean _cacheSupportsReload = true; ! private ReloadDelayDecorator reloadDelay; ! private static class UrlReloadContext extends CacheReloadContext { ! private long lastModified; ! private URL url; ! public UrlReloadContext(URL url, long lastModified) { ! this.url = url; ! this.lastModified = lastModified; ! } ! public boolean shouldReload() { ! return (lastModified != UrlProvider.getUrlLastModified(url)); ! } ! } ! /** ! * Create a new TemplateProvider that uses the specified directory ! * as the source for Template objects that it will return ! * @exception InitException provider failed to initialize ! */ ! public void init(Broker b, Settings config) throws InitException { ! _broker = b; ! _log = b.getLog("resource", "Object loading and caching"); ! _cacheDuration = config.getIntegerSetting("TemplateExpireTime", 0); ! reloadDelay = new ReloadDelayDecorator(); ! reloadDelay.init(b, config); ! } ! /** ! * Grab a template based on its name. ! */ ! final public Object load(String name, CacheElement ce) ! throws ResourceException { ! Template t = null; ! URL tUrl; ! Object ret = null; ! tUrl = findTemplate(name); ! try { ! String protocol = tUrl.getProtocol(); ! // Treat files as a special case ! if (protocol.equals("file")) { ! File f = new File(tUrl.getFile()); ! long lastMod = f.lastModified(); ! t = new FileTemplate(_broker, f); ! t.parse(); ! ret = t; ! if (_cacheSupportsReload) { ! CacheReloadContext reloadContext ! = new TemplateProvider.FTReloadContext(f, lastMod); ! ce.setReloadContext(reloadDelay.decorate("file", reloadContext)); } ! } ! else { ! long lastMod = UrlProvider.getUrlLastModified(tUrl); ! String encoding = tUrl.openConnection().getContentEncoding(); ! // encoding may be null. Will be handled by StreamTemplate ! t = new StreamTemplate(_broker, ! UrlProvider.getUrlInputStream(tUrl), ! encoding); ! t.setName(name); ! t.parse(); ! ret = t; ! if (_cacheSupportsReload) { ! CacheReloadContext reloadContext = new UrlReloadContext(tUrl, lastMod); ! ce.setReloadContext(reloadDelay.decorate(tUrl.getProtocol(), ! reloadContext)); } ! } ! } ! catch (NullPointerException npe) { ! _log.warning("BrokerTemplateProvider: Template not found: " + name); ! } ! catch (ParseException e) { ! _log.warning("BrokerTemplateProvider: Error occured while parsing " ! + name, e); ! throw new InvalidResourceException("Error parsing template " + name, ! e); ! } ! catch (IOException e) { ! _log.warning("BrokerTemplateProvider: IOException while parsing " ! + name, e); ! throw new InvalidResourceException("Error parsing template " + name, ! e); ! } ! catch (Exception e) { ! _log.warning("BrokerTemplateProvider: Error occured while fetching " ! + name, e); ! throw new ResourceException("Error parsing template " + name, e); ! } ! if (ret == null) ! throw new NotFoundException(this + " could not locate " + name); ! return ret; ! } ! /** We don't implement this one */ ! public Object load(Object query, CacheElement ce) ! throws ResourceException { ! throw new ResourceException("CachingProvider: load(Object) not supported, use load(String)"); ! } ! public void setReload(boolean reload) { ! _cacheSupportsReload = reload; ! } ! // IMPLEMENTATION ! /** ! * @param fileName the template filename to find ! * @return a File object that represents the specified template file. ! * @return null if template file cannot be found. */ ! final private URL findTemplate(String fileName) { ! if (_log.loggingDebug()) ! _log.debug("Looking for template in class path: " + fileName); ! URL u = _broker.getTemplate(fileName); ! if (u != null) ! if (_log.loggingDebug()) ! _log.debug("BrokerTemplateProvider: Found " + fileName ! + " at " + u.toString()); ! return u; ! } } --- 45,200 ---- */ final public class BrokerTemplateProviderHelper ! implements ResourceLoader ! { ! // INITIALIZATION ! private Broker _broker; ! private int _cacheDuration; ! private Log _log; ! private boolean _cacheSupportsReload = true; ! private ReloadDelayDecorator reloadDelay; ! private static class UrlReloadContext extends CacheReloadContext ! { ! private long lastModified; ! private URL url; ! public UrlReloadContext (URL url, long lastModified) ! { ! this.url = url; ! this.lastModified = lastModified; ! } ! public boolean shouldReload () ! { ! return (lastModified != UrlProvider.getUrlLastModified(url)); ! } ! } ! /** ! * Create a new TemplateProvider that uses the specified directory ! * as the source for Template objects that it will return ! * @exception InitException provider failed to initialize ! */ ! public void init (Broker b, Settings config) throws InitException ! { ! _broker = b; ! _log = b.getLog("resource", "Object loading and caching"); ! _cacheDuration = config.getIntegerSetting("TemplateExpireTime", 0); ! reloadDelay = new ReloadDelayDecorator(); ! reloadDelay.init(b, config); ! } ! /** ! * Grab a template based on its name. ! */ ! final public Object load (String name, CacheElement ce) ! throws ResourceException ! { ! Template t = null; ! URL tUrl; ! Object ret = null; ! tUrl = findTemplate(name); ! try ! { ! String protocol = tUrl.getProtocol(); ! // Treat files as a special case ! if (protocol.equals("file")) ! { ! File f = new File(tUrl.getFile()); ! long lastMod = f.lastModified(); ! t = new FileTemplate(_broker, f); ! t.parse(); ! ret = t; ! if (_cacheSupportsReload) ! { ! CacheReloadContext reloadContext ! = new TemplateProvider.FTReloadContext(f, lastMod); ! ce.setReloadContext(reloadDelay.decorate("file", reloadContext)); ! } } ! else ! { ! long lastMod = UrlProvider.getUrlLastModified(tUrl); ! String encoding = tUrl.openConnection().getContentEncoding(); ! // encoding may be null. Will be handled by StreamTemplate ! t = new StreamTemplate(_broker, ! UrlProvider.getUrlInputStream(tUrl), ! encoding); ! t.setName(name); ! t.parse(); ! ret = t; ! if (_cacheSupportsReload) ! { ! CacheReloadContext reloadContext = new UrlReloadContext(tUrl, lastMod); ! ce.setReloadContext(reloadDelay.decorate(tUrl.getProtocol(), ! reloadContext)); ! } } ! } ! catch (NullPointerException npe) ! { ! _log.warning("BrokerTemplateProvider: Template not found: " + name); ! } ! catch (ParseException e) ! { ! _log.warning("BrokerTemplateProvider: Error occured while parsing " ! + name, e); ! throw new InvalidResourceException("Error parsing template " + name, ! e); ! } ! catch (IOException e) ! { ! _log.warning("BrokerTemplateProvider: IOException while parsing " ! + name, e); ! throw new InvalidResourceException("Error parsing template " + name, ! e); ! } ! catch (Exception e) ! { ! _log.warning("BrokerTemplateProvider: Error occured while fetching " ! + name, e); ! throw new ResourceException("Error parsing template " + name, e); ! } ! if (ret == null) ! throw new NotFoundException(this + " could not locate " + name); ! return ret; ! } ! /** We don't implement this one */ ! public Object load (Object query, CacheElement ce) ! throws ResourceException ! { ! throw new ResourceException("CachingProvider: load(Object) not supported, use load(String)"); ! } ! public void setReload (boolean reload) ! { ! _cacheSupportsReload = reload; ! } ! // IMPLEMENTATION ! /** ! * @param fileName the template filename to find ! * @return a File object that represents the specified template file. ! * @return null if template file cannot be found. */ ! final private URL findTemplate (String fileName) ! { ! if (_log.loggingDebug()) ! _log.debug("Looking for template in class path: " + fileName); ! URL u = _broker.getTemplate(fileName); ! if (u != null) ! if (_log.loggingDebug()) ! _log.debug("BrokerTemplateProvider: Found " + fileName ! + " at " + u.toString()); ! return u; ! } } Index: CacheElement.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/CacheElement.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CacheElement.java 12 Jun 2002 17:35:34 -0000 1.4 --- CacheElement.java 12 Jun 2003 00:47:47 -0000 1.5 *************** *** 32,38 **** */ ! public abstract class CacheElement { ! public void setReloadContext(CacheReloadContext rc) { ! } } --- 32,40 ---- */ ! public abstract class CacheElement ! { ! public void setReloadContext (CacheReloadContext rc) ! { ! } } Index: CacheManager.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/CacheManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CacheManager.java 11 Jun 2002 17:43:22 -0000 1.3 --- CacheManager.java 12 Jun 2003 00:47:47 -0000 1.4 *************** *** 39,90 **** */ ! public interface CacheManager { ! /** ! * Same as defined in Provider, except with an additional type ! * parameter so it knows what type of resource it is caching ! */ ! public void init(Broker b, Settings config, String resourceType) ! throws InitException; ! /** ! * Same as defined in Provider ! */ ! public void flush(); ! /** ! * Same as defined in Provider ! */ ! public void destroy(); ! /** ! * Called to get a resource from the cache. The helper object is used ! * to load the resource if the resource was not in the cache. ! */ ! public Object get(final Object query, ResourceLoader helper) ! throws ResourceException; ! /** ! * Called to get a resource from the cache. Returns null if not present. ! */ ! public Object get(final Object query); ! /** ! * Called to put a resource into the cache. ! */ ! public void put(final Object query, Object resource); ! /** ! * Invalidates an entry in the cache. Depending on the ! * the implementation, the actual removal from the cache ! * may or may not be immediate. ! */ ! public void invalidate(final Object query); ! /** ! * Does this cache manager support reloading of resources if the ! * underlying resource has changed? ! */ ! public boolean supportsReload(); } --- 39,91 ---- */ ! public interface CacheManager ! { ! /** ! * Same as defined in Provider, except with an additional type ! * parameter so it knows what type of resource it is caching ! */ ! public void init (Broker b, Settings config, String resourceType) ! throws InitException; ! /** ! * Same as defined in Provider ! */ ! public void flush (); ! /** ! * Same as defined in Provider ! */ ! public void destroy (); ! /** ! * Called to get a resource from the cache. The helper object is used ! * to load the resource if the resource was not in the cache. ! */ ! public Object get (final Object query, ResourceLoader helper) ! throws ResourceException; ! /** ! * Called to get a resource from the cache. Returns null if not present. ! */ ! public Object get (final Object query); ! /** ! * Called to put a resource into the cache. ! */ ! public void put (final Object query, Object resource); ! /** ! * Invalidates an entry in the cache. Depending on the ! * the implementation, the actual removal from the cache ! * may or may not be immediate. ! */ ! public void invalidate (final Object query); ! /** ! * Does this cache manager support reloading of resources if the ! * underlying resource has changed? ! */ ! public boolean supportsReload (); } Index: CacheReloadContext.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/CacheReloadContext.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CacheReloadContext.java 11 Jun 2002 17:43:22 -0000 1.3 --- CacheReloadContext.java 12 Jun 2003 00:47:47 -0000 1.4 *************** *** 33,47 **** */ ! public abstract class CacheReloadContext { ! /** ! * The CacheManager calls shouldReload to ask the reference whether ! * it has changed since we loaded it. Subclasses should define an ! * implementation if this if it makes sense to. Otherwise, the default ! * returns false, which means the item is replaced when it expires from ! * the cache. ! */ ! public boolean shouldReload() { ! return false; ! } } --- 33,49 ---- */ ! public abstract class CacheReloadContext ! { ! /** ! * The CacheManager calls shouldReload to ask the reference whether ! * it has changed since we loaded it. Subclasses should define an ! * implementation if this if it makes sense to. Otherwise, the default ! * returns false, which means the item is replaced when it expires from ! * the cache. ! */ ! public boolean shouldReload () ! { ! return false; ! } } Index: CachingProvider.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/CachingProvider.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** CachingProvider.java 11 Jun 2002 17:43:22 -0000 1.18 --- CachingProvider.java 12 Jun 2003 00:47:47 -0000 1.19 *************** *** 37,118 **** abstract public class CachingProvider implements Provider, ! ResourceLoader { ! private CacheManager _cache; ! private Log _log; ! protected boolean _cacheSupportsReload; ! public CachingProvider() { ! } ! /** ! * If you override this method be sure and call super.init(...) ! */ ! public void init(Broker b, Settings config) throws InitException { ! String cacheManager; ! _log = b.getLog("resource", "Object loading and caching"); ! cacheManager = b.getSetting("CachingProvider." + getType() ! + ".CacheManager"); ! if (cacheManager == null) ! cacheManager = b.getSetting("CachingProvider.*.CacheManager"); ! if (cacheManager == null || cacheManager.equals("")) { ! _log.info("CachingProvider: No cache manager specified for " ! + getType() + ", using TrivialCacheManager"); ! _cache = new TrivialCacheManager(); ! } ! else { ! try { ! _cache = (CacheManager) b.classForName(cacheManager).newInstance(); ! } ! catch (Exception e) { ! _log.warning("Unable to load cache manager " + cacheManager ! + " for resource type " + getType() ! + ", using TrivialCacheManager. Reason:\n" + e); _cache = new TrivialCacheManager(); ! } ! } ! _cache.init(b, config, getType()); ! _cacheSupportsReload = _cache.supportsReload(); ! } ! /** ! * Clear the cache. If you override this method be sure ! * and call super.flush(). ! */ ! public void flush() { ! _cache.flush(); ! } ! /** ! * Close down the provider. If you override this method be ! * sure and call super.destroy(). ! */ ! public void destroy() { ! _cache.destroy(); ! } ! /** ! * Get the object associated with the specific query, using the ! * specified cache manager. ! */ ! public Object get(String query) throws ResourceException { ! return _cache.get(query, this); ! } ! /* ! * Delegates to ResourceLoader implementers the load operation ! * by casting the query as a string and invoking the ! * implemented method. ! */ ! public Object load(Object query, CacheElement ce) ! throws ResourceException { ! return ((ResourceLoader) this).load((String) query, ce); ! } ! public String toString() { ! return "CachingProvider(type = " + getType() + ")"; ! } --- 37,130 ---- abstract public class CachingProvider implements Provider, ! ResourceLoader ! { ! private CacheManager _cache; ! private Log _log; ! protected boolean _cacheSupportsReload; ! public CachingProvider () ! { ! } ! /** ! * If you override this method be sure and call super.init(...) ! */ ! public void init (Broker b, Settings config) throws InitException ! { ! String cacheManager; ! _log = b.getLog("resource", "Object loading and caching"); ! cacheManager = b.getSetting("CachingProvider." + getType() ! + ".CacheManager"); ! if (cacheManager == null) ! cacheManager = b.getSetting("CachingProvider.*.CacheManager"); ! if (cacheManager == null || cacheManager.equals("")) ! { ! _log.info("CachingProvider: No cache manager specified for " ! + getType() + ", using TrivialCacheManager"); _cache = new TrivialCacheManager(); ! } ! else ! { ! try ! { ! _cache = (CacheManager) b.classForName(cacheManager).newInstance(); ! } ! catch (Exception e) ! { ! _log.warning("Unable to load cache manager " + cacheManager ! + " for resource type " + getType() ! + ", using TrivialCacheManager. Reason:\n" + e); ! _cache = new TrivialCacheManager(); ! } ! } ! _cache.init(b, config, getType()); ! _cacheSupportsReload = _cache.supportsReload(); ! } ! /** ! * Clear the cache. If you override this method be sure ! * and call super.flush(). ! */ ! public void flush () ! { ! _cache.flush(); ! } ! /** ! * Close down the provider. If you override this method be ! * sure and call super.destroy(). ! */ ! public void destroy () ! { ! _cache.destroy(); ! } ! /** ! * Get the object associated with the specific query, using the ! * specified cache manager. ! */ ! public Object get (String query) throws ResourceException ! { ! return _cache.get(query, this); ! } ! /* ! * Delegates to ResourceLoader implementers the load operation ! * by casting the query as a string and invoking the ! * implemented method. ! */ ! public Object load (Object query, CacheElement ce) ! throws ResourceException ! { ! return ((ResourceLoader) this).load((String) query, ce); ! } ! public String toString () ! { ! return "CachingProvider(type = " + getType() + ")"; ! } Index: ClassPathTemplateLoader.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/ClassPathTemplateLoader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ClassPathTemplateLoader.java 27 Dec 2002 23:36:37 -0000 1.6 --- ClassPathTemplateLoader.java 12 Jun 2003 00:47:47 -0000 1.7 *************** *** 22,27 **** package org.webmacro.resource; - import java.net.URL; - import org.webmacro.Broker; import org.webmacro.InitException; --- 22,25 ---- *************** *** 30,33 **** --- 28,33 ---- import org.webmacro.util.Settings; + import java.net.URL; + /** * Implementation of TemplateLoader that loads template from the classpath. *************** *** 40,80 **** * @author Sebastian Kanthak (seb...@mu...) */ ! public class ClassPathTemplateLoader extends AbstractTemplateLoader { ! private ClassLoader loader; ! private String path; ! public void init(Broker broker, Settings config) throws InitException { ! super.init(broker, config); ! loader = broker.getClassLoader(); ! } ! public void setConfig(String config) { ! // as we'll later use this as a prefix, it should end with a slash ! if (config.length() > 0 && !config.endsWith("/")) { ! if (log.loggingInfo()) ! log.info("ClassPathTemplateLoader: appending \"/\" to path " + config); ! config = config.concat("/"); ! } ! // It isn't clear from the javadocs, whether ClassLoader.getResource() ! // needs a starting slash, so won't add one at the moment. Even worse, ! // most class-loaders require you to _not have_ a slash, so we'll ! // remove it, if it exists ! if (config.startsWith("/")) { ! config = config.substring(1); ! } ! this.path = config; ! } ! public Template load(String query, CacheElement ce) throws ResourceException { ! if (query.startsWith("/")) { ! query = query.substring(1); ! } ! URL url = loader.getResource(path.concat(query)); ! if (url != null && log.loggingDebug()) { ! log.debug("ClassPathTemplateProvider: Found Template " + url.toString()); ! } ! return (url != null) ? helper.load(url, ce) : null; ! } } --- 40,88 ---- * @author Sebastian Kanthak (seb...@mu...) */ ! public class ClassPathTemplateLoader extends AbstractTemplateLoader ! { ! private ClassLoader loader; ! private String path; ! public void init (Broker broker, Settings config) throws InitException ! { ! super.init(broker, config); ! loader = broker.getClassLoader(); ! } ! public void setConfig (String config) ! { ! // as we'll later use this as a prefix, it should end with a slash ! if (config.length() > 0 && !config.endsWith("/")) ! { ! if (log.loggingInfo()) ! log.info("ClassPathTemplateLoader: appending \"/\" to path " + config); ! config = config.concat("/"); ! } ! // It isn't clear from the javadocs, whether ClassLoader.getResource() ! // needs a starting slash, so won't add one at the moment. Even worse, ! // most class-loaders require you to _not have_ a slash, so we'll ! // remove it, if it exists ! if (config.startsWith("/")) ! { ! config = config.substring(1); ! } ! this.path = config; ! } ! public Template load (String query, CacheElement ce) throws ResourceException ! { ! if (query.startsWith("/")) ! { ! query = query.substring(1); ! } ! URL url = loader.getResource(path.concat(query)); ! if (url != null && log.loggingDebug()) ! { ! log.debug("ClassPathTemplateProvider: Found Template " + url.toString()); ! } ! return (url != null) ? helper.load(url, ce) : null; ! } } Index: ConfigProvider.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/ConfigProvider.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ConfigProvider.java 11 Jun 2002 17:43:22 -0000 1.5 --- ConfigProvider.java 12 Jun 2003 00:47:47 -0000 1.6 *************** *** 34,65 **** * passed to it by the broker and returns it. */ ! public class ConfigProvider implements Provider { ! private Settings _config; ! public String getType() { ! return "config"; ! } ! public void init(Broker b, Settings config) throws InitException { ! _config = config; ! if (_config == null) { ! throw new InitException("Attempt to init with no configuration"); ! } ! } ! public void flush() { ! } ! public void destroy() { ! _config = null; ! } ! public Object get(String key) throws NotFoundException { ! Object o = _config.getSetting(key); ! if (o == null) { ! throw new NotFoundException("No config information for: " + key); ! } ! return o; ! } } --- 34,73 ---- * passed to it by the broker and returns it. */ ! public class ConfigProvider implements Provider ! { ! private Settings _config; ! public String getType () ! { ! return "config"; ! } ! public void init (Broker b, Settings config) throws InitException ! { ! _config = config; ! if (_config == null) ! { ! throw new InitException("Attempt to init with no configuration"); ! } ! } ! public void flush () ! { ! } ! public void destroy () ! { ! _config = null; ! } ! public Object get (String key) throws NotFoundException ! { ! Object o = _config.getSetting(key); ! if (o == null) ! { ! throw new NotFoundException("No config information for: " + key); ! } ! return o; ! } } Index: DefaultTemplateLoaderFactory.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/DefaultTemplateLoaderFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DefaultTemplateLoaderFactory.java 11 Jun 2002 17:43:22 -0000 1.4 --- DefaultTemplateLoaderFactory.java 12 Jun 2003 00:47:47 -0000 1.5 *************** *** 39,85 **** * @author Sebastian Kanthak (seb...@mu...) */ ! public class DefaultTemplateLoaderFactory implements TemplateLoaderFactory { ! public TemplateLoader getTemplateLoader(Broker b, String config) throws InitException { ! String protocol; ! String options; ! int pos = config.indexOf(":"); ! if (pos == -1) { ! protocol = "default"; ! options = config; ! } ! else { ! protocol = config.substring(0, pos); ! if (pos + 1 < config.length()) { ! options = config.substring(pos + 1); ! } ! else { ! options = ""; ! } ! } ! String classname = b.getSetting("TemplateLoader.".concat(protocol)); ! if (classname == null || classname.length() == 0) ! throw new InitException("No class found for template loader protocol " + protocol); ! try { ! TemplateLoader loader = (TemplateLoader) b.classForName(classname).newInstance(); ! loader.init(b, b.getSettings()); ! loader.setConfig(options); ! return loader; ! } ! catch (ClassNotFoundException e) { ! throw new InitException("Class " + classname + " for template loader " + protocol + " not found", e); ! } ! catch (InstantiationException e) { ! throw new InitException("Could not instantiate class " + classname + " for template loader " + protocol, e); ! } ! catch (IllegalAccessException e) { ! throw new InitException("Could not instantiate class " + classname + " for template loader " + protocol, e); ! } ! catch (ClassCastException e) { ! throw new InitException("Class " + classname + " for template loader" + protocol + " does not implement " + ! "interface org.webmacro.resource.TemplateLoader", e); ! } ! } } --- 39,96 ---- * @author Sebastian Kanthak (seb...@mu...) */ ! public class DefaultTemplateLoaderFactory implements TemplateLoaderFactory ! { ! public TemplateLoader getTemplateLoader (Broker b, String config) throws InitException ! { ! String protocol; ! String options; ! int pos = config.indexOf(":"); ! if (pos == -1) ! { ! protocol = "default"; ! options = config; ! } ! else ! { ! protocol = config.substring(0, pos); ! if (pos + 1 < config.length()) ! { ! options = config.substring(pos + 1); ! } ! else ! { ! options = ""; ! } ! } ! String classname = b.getSetting("TemplateLoader.".concat(protocol)); ! if (classname == null || classname.length() == 0) ! throw new InitException("No class found for template loader protocol " + protocol); ! try ! { ! TemplateLoader loader = (TemplateLoader) b.classForName(classname).newInstance(); ! loader.init(b, b.getSettings()); ! loader.setConfig(options); ! return loader; ! } ! catch (ClassNotFoundException e) ! { ! throw new InitException("Class " + classname + " for template loader " + protocol + " not found", e); ! } ! catch (InstantiationException e) ! { ! throw new InitException("Could not instantiate class " + classname + " for template loader " + protocol, e); ! } ! catch (IllegalAccessException e) ! { ! throw new InitException("Could not instantiate class " + classname + " for template loader " + protocol, e); ! } ! catch (ClassCastException e) ! { ! throw new InitException("Class " + classname + " for template loader" + protocol + " does not implement " + ! "interface org.webmacro.resource.TemplateLoader", e); ! } ! } } Index: DelegatingTemplateProvider.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/DelegatingTemplateProvider.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DelegatingTemplateProvider.java 11 Jun 2002 17:43:22 -0000 1.7 --- DelegatingTemplateProvider.java 12 Jun 2003 00:47:47 -0000 1.8 *************** *** 24,32 **** package org.webmacro.resource; - import java.util.*; - import org.webmacro.*; import org.webmacro.util.Settings; /** * Alternative implementation of a TemplateProvider that uses TemplateLoaders to do the actual work. --- 24,35 ---- package org.webmacro.resource; import org.webmacro.*; import org.webmacro.util.Settings; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.Collections; + import java.util.List; + /** * Alternative implementation of a TemplateProvider that uses TemplateLoaders to do the actual work. *************** *** 62,151 **** * @author Sebastian Kanthak (seb...@mu...) */ ! public class DelegatingTemplateProvider extends CachingProvider { ! private Broker broker; ! private Log log; ! private TemplateLoaderFactory factory; ! private TemplateLoader[] templateLoaders; ! public void init(Broker broker, Settings config) throws InitException { ! super.init(broker, config); ! this.broker = broker; ! log = broker.getLog("resource", "DelegatingTemplateProvider"); ! String factoryClass = config.getSetting("TemplateLoaderFactory", ""); ! log.info("DelegatingTemplateProvider: Using TemplateLoaderFactory " + factoryClass); ! factory = createFactory(factoryClass); ! List loaders = new ArrayList(); ! // for compatability reasons, check old TemplatePath setting ! if (config.getBooleanSetting("DelegatingTemplateProvider.EmulateTemplatePath", false)) { ! if (config.getSetting("TemplatePath", "").length() > 0) { ! TemplateLoader loader = new TemplatePathTemplateLoader(); ! loader.init(broker, config); ! loader.setConfig(""); ! loaders.add(loader); ! } ! } ! int i = 0; ! String loader = config.getSetting("TemplateLoaderPath.".concat(String.valueOf(i + 1))); ! while (loader != null) { ! loaders.add(factory.getTemplateLoader(broker, loader)); ! i++; ! loader = config.getSetting("TemplateLoaderPath.".concat(String.valueOf(i + 1))); ! } ! templateLoaders = new TemplateLoader[loaders.size()]; ! loaders.toArray(templateLoaders); ! } ! public String getType() { ! return "template"; ! } ! /** ! * Ask all template loaders to load a template from query. ! * Returns the template from the first provider, that returns a non-null value ! * or throws a NotFoundException, if all providers return null. ! */ ! public Object load(String query, CacheElement ce) throws ResourceException { ! for (int i = 0; i < templateLoaders.length; i++) { ! Template t = templateLoaders[i].load(query, ce); ! if (t != null) { ! return t; ! } ! } ! throw new NotFoundException("Could not locate template " + query); ! } ! /** ! * Returns an unmodifieable list of this provider's template loaders. ! * The list is has the same order used for searching templates. You may ! * use this method to access template loaders and change their settings ! * at runtime if they have an appropriate method. ! * @return unmodifieable list of TemplateLoader objects ! */ ! public List getTemplateLoaders() { ! return Collections.unmodifiableList(Arrays.asList(templateLoaders)); ! } ! protected TemplateLoaderFactory createFactory(String classname) throws InitException { ! try { ! return (TemplateLoaderFactory) Class.forName(classname).newInstance(); ! } ! catch (ClassNotFoundException e) { ! throw new InitException("Class " + classname + " for template loader factory not found", e); ! } ! catch (InstantiationException e) { ! throw new InitException("Could not instantiate class " + classname + " for template loader factory", e); ! } ! catch (IllegalAccessException e) { ! throw new InitException("Could not instantiate class " + classname + " for template loader facory", e); ! } ! catch (ClassCastException e) { ! throw new InitException("Class " + classname + " for template loader factory does not implement " + ! "interface org.webmacro.resource.TemplateLoaderFactory", e); ! } ! } } --- 65,170 ---- * @author Sebastian Kanthak (seb...@mu...) */ ! public class DelegatingTemplateProvider extends CachingProvider ! { ! private Broker broker; ! private Log log; ! private TemplateLoaderFactory factory; ! private TemplateLoader[] templateLoaders; ! public void init (Broker broker, Settings config) throws InitException ! { ! super.init(broker, config); ! this.broker = broker; ! log = broker.getLog("resource", "DelegatingTemplateProvider"); ! String factoryClass = config.getSetting("TemplateLoaderFactory", ""); ! log.info("DelegatingTemplateProvider: Using TemplateLoaderFactory " + factoryClass); ! factory = createFactory(factoryClass); ! List loaders = new ArrayList(); ! // for compatability reasons, check old TemplatePath setting ! if (config.getBooleanSetting("DelegatingTemplateProvider.EmulateTemplatePath", false)) ! { ! if (config.getSetting("TemplatePath", "").length() > 0) ! { ! TemplateLoader loader = new TemplatePathTemplateLoader(); ! loader.init(broker, config); ! loader.setConfig(""); ! loaders.add(loader); ! } ! } ! int i = 0; ! String loader = config.getSetting("TemplateLoaderPath.".concat(String.valueOf(i + 1))); ! while (loader != null) ! { ! loaders.add(factory.getTemplateLoader(broker, loader)); ! i++; ! loader = config.getSetting("TemplateLoaderPath.".concat(String.valueOf(i + 1))); ! } ! templateLoaders = new TemplateLoader[loaders.size()]; ! loaders.toArray(templateLoaders); ! } ! public String getType () ! { ! return "template"; ! } ! /** ! * Ask all template loaders to load a template from query. ! * Returns the template from the first provider, that returns a non-null value ! * or throws a NotFoundException, if all providers return null. ! */ ! public Object load (String query, CacheElement ce) throws ResourceException ! { ! for (int i = 0; i < templateLoaders.length; i++) ! { ! Template t = templateLoaders[i].load(query, ce); ! if (t != null) ! { ! return t; ! } ! } ! throw new NotFoundException("Could not locate template " + query); ! } ! /** ! * Returns an unmodifieable list of this provider's template loaders. ! * The list is has the same order used for searching templates. You may ! * use this method to access template loaders and change their settings ! * at runtime if they have an appropriate method. ! * @return unmodifieable list of TemplateLoader objects ! */ ! public List getTemplateLoaders () ! { ! return Collections.unmodifiableList(Arrays.asList(templateLoaders)); ! } ! protected TemplateLoaderFactory createFactory (String classname) throws InitException ! { ! try ! { ! return (TemplateLoaderFactory) Class.forName(classname).newInstance(); ! } ! catch (ClassNotFoundException e) ! { ! throw new InitException("Class " + classname + " for template loader factory not found", e); ! } ! catch (InstantiationException e) ! { ! throw new InitException("Could not instantiate class " + classname + " for template loader factory", e); ! } ! catch (IllegalAccessException e) ! { ! throw new InitException("Could not instantiate class " + classname + " for template loader facory", e); ! } ! catch (ClassCastException e) ! { ! throw new InitException("Class " + classname + " for template loader factory does not implement " + ! "interface org.webmacro.resource.TemplateLoaderFactory", e); ! } ! } } Index: FileTemplateLoader.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/FileTemplateLoader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FileTemplateLoader.java 11 Jun 2002 17:43:22 -0000 1.5 --- FileTemplateLoader.java 12 Jun 2003 00:47:47 -0000 1.6 *************** *** 23,31 **** package org.webmacro.resource; - import java.io.*; - import org.webmacro.ResourceException; import org.webmacro.Template; /** * Implementation of TemplateLoader that loads templates from a given directory. --- 23,31 ---- package org.webmacro.resource; import org.webmacro.ResourceException; import org.webmacro.Template; + import java.io.File; + /** * Implementation of TemplateLoader that loads templates from a given directory. *************** *** 35,71 **** * @author Sebastian Kanthak (seb...@mu...) */ ! public class FileTemplateLoader extends AbstractTemplateLoader { ! private String path; ! public void setConfig(String config) { ! // leading slash isn't needed, because ! // we use File constructor. ! this.path = config; ! // However, we can check, if the directory exists. ! File f = new File(path); ! if (!f.exists()) { ! log.warning("FileTemplateLoader: " + f.getAbsolutePath() + " does not exist."); ! } ! else if (!f.isDirectory()) { ! log.warning("FileTemplateLoader: " + f.getAbsolutePath() + " is not a directory."); ! } ! } ! /** ! * Tries to load a template by interpreting query as ! * a path relative to the path set by setPath. ! */ ! public final Template load(String query, CacheElement ce) throws ResourceException { ! File tFile = new File(path, query); ! if (tFile.isFile() && tFile.canRead()) { ! if (log.loggingDebug()) ! log.debug("FileTemplateProvider: Found template " + tFile.getAbsolutePath()); ! return helper.load(tFile, ce); ! } ! else { ! return null; ! } ! } } --- 35,78 ---- * @author Sebastian Kanthak (seb...@mu...) */ ! public class FileTemplateLoader extends AbstractTemplateLoader ! { ! private String path; ! public void setConfig (String config) ! { ! // leading slash isn't needed, because ! // we use File constructor. ! this.path = config; ! // However, we can check, if the directory exists. ! File f = new File(path); ! if (!f.exists()) ! { ! log.warning("FileTemplateLoader: " + f.getAbsolutePath() + " does not exist."); ! } ! else if (!f.isDirectory()) ! { ! log.warning("FileTemplateLoader: " + f.getAbsolutePath() + " is not a directory."); ! } ! } ! /** ! * Tries to load a template by interpreting query as ! * a path relative to the path set by setPath. ! */ ! public final Template load (String query, CacheElement ce) throws ResourceException ! { ! File tFile = new File(path, query); ! if (tFile.isFile() && tFile.canRead()) ! { ! if (log.loggingDebug()) ! log.debug("FileTemplateProvider: Found template " + tFile.getAbsolutePath()); ! return helper.load(tFile, ce); ! } ! else ! { ! return null; ! } ! } } Index: GenerationalCacheManager.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/resource/GenerationalCacheManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenerationalCacheManager.java 11 Nov 2002 19:22:37 -0000 1.6 --- GenerationalCacheManager.java 12 Jun 2003 00:47:47 -0000 1.7 *************** *** 25,29 **** import org.opendoors.cache.immutable.CacheFactory; import org.opendoors.cache.immutable.CacheImpl; - import org.webmacro.Broker; import org.webmacro.InitException; --- 25,28 ---- *************** *** 58,232 **** * @since 0.96 */ ! public class GenerationalCacheManager implements CacheManager { ! private static final String NAME = "GenerationalCacheManager"; ! private UpdateableCache cache; ! private Log log; ! private CacheFactory cacheFactory; ! private String resourceType; ! private boolean reloadOnChange = false; ! public GenerationalCacheManager() { ! } ! public void init(Broker b, Settings config, String resourceType) ! throws InitException { ! Settings s = new SubSettings(config, "GenerationalCacheManager." + resourceType); ! Settings def = new SubSettings(config, "GenerationalCacheManager.*"); ! if (s.containsKey("ReloadOnChange")) { ! reloadOnChange = s.getBooleanSetting("ReloadOnChange"); // for this resource type ! } ! else if (def.containsKey("ReloadOnChange")) { ! reloadOnChange = def.getBooleanSetting("ReloadOnChange"); // all resource types ! } ! cacheFactory = new CacheFactory(def.getAsProperties()); // uses the union ! this.cache = cacheFactory.initialize(null); ! this.log = b.getLog("resource"); ! this.resourceType = resourceType; ! log.info(NAME + "." + resourceType + ": " + "Reload=" + reloadOnChange); ! } ! public void flush() { ! cache.invalidateAll(); ! } ! public void destroy() { ! cacheFactory.destroy(cache); ! } ! /** ! * Get the cached value and load ! * it if it is not present or reloading ! * is required. ! */ ! public Object get(final Object query, ResourceLoader helper) ! throws ResourceException { ! if (reloadOnChange) ! return getReloadable(query, helper); ! else ! return getUnreloadable(query, helper); ! } ! /** ! * Get the object associated with the specific query, ! * trying to look it up in a cache. If it's not there, return null. ! */ ! public Object get(final Object query) { ! Object o = cache.get(query); ! if (o != null && reloadOnChange) ! return ((ScmCacheElement) o).value; ! else ! return o; ! } ! /** ! * Put an object in the cache ! */ ! public void put(final Object query, Object resource) { ! if (reloadOnChange) { ! ScmCacheElement r = new ScmCacheElement(); ! r.value = resource; ! cache.put(query, r); ! } ! else ! cache.put(query, resource); ! } ! private Object getUnreloadable(final Object query, ResourceLoader helper) ! throws ResourceException { ! Object o = cache.get(query); ! if (o == null) { ! o = helper.load(query, null); ! if (o != null) ! cache.put(query, o); ! } ! return o; ! } ! private Object getReloadable(final Object query, ResourceLoader helper) ! throws ResourceException { ! Object o = null; ! ScmCacheElement r = (ScmCacheElement) cache.get(query); ! if (r != null) ! o = r.value; ! boolean reload = false; ! if (o != null && r.reloadContext != null && reloadOnChange) ! reload = r.reloadContext.shouldReload(); ! if (o == null || reload) { ! if (r == null) ! r = new ScmCacheElement(); ! o = helper.load(query, r); ! if (o != null) { ! r.value = o; ! cache.put(query, r); ! } ! } ! return o; ! } ! /** Invalidate an entry in the cache. */ ! public void invalidate(final Object query) { ! cache.invalidate(query); ! } ! /** This manager supports reloading and so this returns true. */ ! public boolean supportsReload() { ! return true; ! } ! /** Returns the wm type of resource it is caching. */ ! public String getResourceType() { ! return resourceType; ! } ! /** ! * A caching element ! * smart enough to reload itself. ! * <p> ! * Note: SoftReference is a huge overhead hit so ! * it has been obsoleted in favor of straight obj refs. ! */ ! private static class ScmCacheElement extends CacheElement { ! private Object value; ! private CacheReloadContext reloadContext = null; ! public void setReloadContext(CacheReloadContext rc) { ! this.reloadContext = rc; ! } ! } ! /** ! * Returns cache instrumentation statistics. ! * <p> ! * These statistics will be zero if the cache ! * implementation is not using the instrumented get() routine. ! * <p> ! * Use of this routine is normally reserved for performance analysis ! * and depends on recompiling org.opendoors.cache.immutable.CacheImpl ! * @return an array of longs with the following def.<br> ! * <pre> ! * [0] The total number of gets, accesses. ! * [1] The number of accesses which resulted in a hit to the immutable cache. ! * [2] The number of accesses which resulted in a hit to the mutable cache. ! * [3] The number of accesses which resulted in a fault and a need to ! * regenerate the cache entry. ! * </pre> ! * @see org.opendoors.cache.impl.CacheImpl ! */ ! public long[] getMetrics() { ! long[] values = {0, 0, 0, 0}; // the default; ! if (cache instanceof CacheImpl) { ! CacheImpl impl = (CacheImpl) cache; ! values = impl.getMetrics(); ! } ! return values; ! } } --- 57,254 ---- * @since 0.96 */ ! public class GenerationalCacheManager implements CacheManager ! { ! private static final String NAME = "GenerationalCacheManager"; ! private UpdateableCache cache; ! private Log log; ! private CacheFactory cacheFactory; ! private String resourceType; ! private boolean reloadOnChange = false; ! public GenerationalCacheManager () ! { ! } ! public void init (Broker b, Settings config, String resourceType) ! throws InitException ! { ! Settings s = new SubSettings(config, "GenerationalCacheManager." + resourceType); ! Settings def = new SubSettings(config, "GenerationalCacheManager.*"); ! if (s.containsKey("ReloadOnChange")) ! { ! reloadOnChange = s.getBooleanSetting("ReloadOnChange"); // for this resource type ! } ! else if (def.containsKey("ReloadOnChange")) ! { ! reloadOnChange = def.getBooleanSetting("ReloadOnChange"); // all resource types ! } ! cacheFactory = new CacheFactory(def.getAsProperties()); // uses the union ! this.cache = cacheFactory.initialize(null); ! this.log = b.getLog("resource"); ! this.resourceType = resourceType; ! log.info(NAME + "." + resourceType + ": " + "Reload=" + reloadOnChan... [truncated message content] |