Author: gvanmatre Date: Fri Sep 16 23:30:58 2005 New Revision: 289709 URL: http://svn.apache.org/viewcvs?rev=289709&view=rev Log: Fix for Bug#: 36661 - Clay template reloading problem
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBeanFactory.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?rev=289709&r1=289708&r2=289709&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java Fri Sep 16 23:30:58 2005 @@ -165,7 +165,7 @@ watchDogs.put(watchDog.getName(), watchDog); // loads the config files - watchDog.refresh(); + watchDog.refresh(true); param = null; configFiles = null; @@ -230,7 +230,7 @@ /** * <p>Collection holding all the top-level components defined in the XML config files</p> */ - private Map displayElements = null; + protected Map displayElements = null; /** * <p>Constructor initializes the <code>displayElements</code> collection</p> @@ -805,7 +805,7 @@ } - protected void clear() { + protected void clear(String watchDogName) { Iterator di = displayElements.entrySet().iterator(); while (di.hasNext()) { Map.Entry e = (Map.Entry) di.next(); @@ -830,7 +830,7 @@ * </p> */ public void destroy() { - clear(); + clear(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG); context = null; if (parser != null) @@ -1039,19 +1039,24 @@ /** * <p>This method is the watch dog timmer. It's invoked to determine - * if any of the files have changed since the last time they were loaded. - * If a change has occured on any of the <code>configDefs</code>, all the + * if any of the files have changed since the last time they were loaded. + * If a change has occured on any of the <code>configDefs</code> or + * the <code>forceReload</code> param is <code>true</code>, all the * files are reloaded and the last modified date is reset in the - * [EMAIL PROTECTED] ConfigBean.ConfigDefinition}. + * [EMAIL PROTECTED] ConfigBean.ConfigDefinition}. A <code>true</code> value is + * returned if the files were refreshed. * </p> */ - public void refresh() { + public boolean refresh(boolean forceReload) { + + boolean wasDirty = false; int i = 0; try { open(); - if (isDirty()) { - clear(); + if (forceReload || isDirty()) { + wasDirty = true; + clear(getName()); for (i = 0; i < configDefs.length; i++) { if (log.isInfoEnabled()) @@ -1090,30 +1095,36 @@ } finally { close(); } + + return wasDirty; } - + } /** * <p>This method should be called from key points in the application to invoke * automatic reloading of the configuration files if they have been modified since - * last reloaded. The parameter <code>watchDogName</code> corresponds to a - * HTML template name or the default defined by the static String constant - * <code>Global.DEFAULT_COMPONENT_CONFIG_WATCHDOG</code></p> + * last reloaded. If the <code>forceReload</code> flag is <code>true</code> the files are + * reloaded. A <code>true</code> return value indicates the config files + * where reloaded.</p> */ - public void refresh(String watchDogName) { + public boolean refresh(boolean forceReload) { + + boolean wasDirty = false; - WatchDog watchDog = (WatchDog) watchDogs.get(watchDogName); + WatchDog watchDog = (WatchDog) watchDogs.get(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG); // is auto watch turned off if (!ComponentConfigBean.this.isWatchDogOn || watchDog == null) - return; + return wasDirty; synchronized (displayElements) { - watchDog.refresh(); + wasDirty = watchDog.refresh(forceReload); } watchDog = null; + + return wasDirty; } Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java?rev=289709&r1=289708&r2=289709&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java Fri Sep 16 23:30:58 2005 @@ -102,10 +102,10 @@ /** * <p>This method should be called from key points in the application to invoke * automatic reloading of the configuration files if they have been modified since - * last reloaded. The <code>watchDogName</code> parameter corresponds to the - * instance of the [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ComponentConfigBean$WatchDog} - * monitoring a configuration file for change.</p> + * last reloaded. If the parameter <code>forceReload</code> is <code>true</code>, + * all files will be reloaded. The return value is <code>true</code>, if the + * files were reloaded.</p> */ - public void refresh(String watchDogName); + public boolean refresh(boolean forceReload); } Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBeanFactory.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBeanFactory.java?rev=289709&r1=289708&r2=289709&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBeanFactory.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBeanFactory.java Fri Sep 16 23:30:58 2005 @@ -84,20 +84,19 @@ /** * <p>This method should be called from key points in the application to invoke * automatic reloading of the configuration files if they have been modified since - * last reloaded. The <code>watchDogName</code> parameter corresponds to the instance of the - * [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ComponentConfigBean.WatchDog} monitoring - * a configuration file for change. The same [EMAIL PROTECTED] ConfigBean} interfaces is used for - * [EMAIL PROTECTED] ComponentConfigBean} and [EMAIL PROTECTED] TemplateConfigBean} but the - * [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ComponentConfigBean$WatchDog} for the XML - * configuration files is assumed to be known by <code>Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG</code>. + * last reloaded. If the XML files have changed, all files have to be reloaded. + * This includes HTML template files. * </p> */ - public static void refresh(String watchDogName) { + public static void refresh() { Iterator ci = configBeans.iterator(); - ConfigBean config = null; + //the logic assumes the ComponentConfigBean will be first + //in the ordered list. If the XML files are dirty, the + //template cache must be reestablished. + boolean wasDirty = false; while (ci.hasNext()) { - config = (ConfigBean) ci.next(); - config.refresh(watchDogName); + ConfigBean config = (ConfigBean) ci.next(); + wasDirty = config.refresh(wasDirty); } } Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java?rev=289709&r1=289708&r2=289709&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java Fri Sep 16 23:30:58 2005 @@ -65,7 +65,7 @@ */ protected void accept(ShaleWebContext context) throws Exception { - ConfigBeanFactory.refresh(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG); + ConfigBeanFactory.refresh(); } Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java?rev=289709&r1=289708&r2=289709&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java Fri Sep 16 23:30:58 2005 @@ -18,6 +18,8 @@ package org.apache.shale.clay.config.beans; +import java.util.Iterator; +import java.util.Map; import java.util.TreeMap; import javax.servlet.ServletContext; @@ -25,6 +27,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.shale.clay.config.ClayTemplateParser; +import org.apache.shale.clay.config.Globals; +import org.apache.shale.clay.config.beans.ComponentConfigBean.WatchDog; /** * <p>The second type of top-level object pool. This implementation @@ -60,8 +64,7 @@ WatchDog watchDog = (WatchDog) watchDogs.get(jsfid.toString()); if (watchDog == null || super.getElement(jsfid.toString()) == null) { //The first time the page is created, create a watcher - - + watchDog = new WatchDog(getConfigDefinitions(jsfid.toString()), jsfid.toString()); // register by name @@ -70,7 +73,7 @@ //loads the HTML template the first time and when file //has been modified - watchDog.refresh(); + watchDog.refresh(false); // returns the cached element return super.getElement(jsfid.toString()); @@ -123,5 +126,58 @@ isWatchDogOn = true; } + + /** + * <p>If the <code>watchDogName</code> equals + * the [EMAIL PROTECTED] ComponentBean} that defines the selected + * template, remove it.</p> + */ + protected void clear(String watchDogName) { + if (!watchDogName.equals(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG)) { + //unassign a single template component + ComponentBean b = (ComponentBean) displayElements.get(watchDogName); + displayElements.remove(watchDogName); + if (b != null) { + try { + unassignParent(b); + } catch (RuntimeException e1) { + } + } + b = null; + } else { + super.clear(watchDogName); + } + } + + + /** + * <p>If the <code>forceReload</code> is <code>true</code>, + * the <code>displayElements</code> cache is invalidated. + * A <code>true</code> value is returned if cache has + * been cleared.</p> + */ + public boolean refresh(boolean forceReload) { + if (forceReload) { + synchronized (displayElements) { + + //remove all old templates + Iterator wi = watchDogs.entrySet().iterator(); + while (wi.hasNext()) { + Map.Entry e = (Map.Entry) wi.next(); + WatchDog watchDog = (WatchDog) e.getValue(); + clear(watchDog.getName()); + if (watchDog != null) + watchDog.destroy(); + + } + watchDogs.clear(); + } + } + + return forceReload; + } + + + } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]