Author: gvanmatre
Date: Sat Feb 24 22:21:04 2007
New Revision: 511456

URL: http://svn.apache.org/viewvc?view=rev&rev=511456
Log:
The clay template handlers that parse and cache meta-data, were not correctly 
guarding shared data structures (SHALE-390).  This patch was provided by Martin 
Bergljung.    

Modified:
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?view=diff&rev=511456&r1=511455&r2=511456
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
 Sat Feb 24 22:21:04 2007
@@ -24,6 +24,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -218,7 +219,7 @@
         parser.setConfig(this);
 
         // map holding the resource watchers
-        watchDogs = new TreeMap();
+        watchDogs = Collections.synchronizedMap(new TreeMap());
 
         // create the watch dog with a list of config files to look for changes
         WatchDog watchDog = new 
WatchDog(getConfigDefinitions(configFiles.toString()),
@@ -315,7 +316,7 @@
      */
     public ComponentConfigBean() {
         final int size = 1000;
-        displayElements = new HashMap(size);
+        displayElements = Collections.synchronizedMap(new HashMap(size));
     }
 
     /**
@@ -328,9 +329,7 @@
      */
     public ComponentBean getElement(String jsfid) {
         ComponentBean element = null;
-        synchronized (displayElements) {
             element = (ComponentBean) displayElements.get(jsfid);
-        }
         return element;
     }
 
@@ -468,59 +467,57 @@
      *
      * @param b component bean needing isa parent assigned
      */
-    public void assignParent(ComponentBean b) {
+    public synchronized void assignParent(ComponentBean b) {
 
-        synchronized (displayElements) {
 
-            if (b instanceof InnerComponentBean) {
+        if (b instanceof InnerComponentBean) {
 
-                // these elements are like inner classes
-                // set the extends to the element so the
-                // parent can be generically resolved
-                if (b.getJsfid() != null) {
-                    b.setExtends(b.getJsfid());
-                }
+            // these elements are like inner classes
+            // set the extends to the element so the
+            // parent can be generically resolved
+            if (b.getJsfid() != null) {
+                b.setExtends(b.getJsfid());
             }
+        }
 
-            // look for a meta inheritance property
-            if (b.getExtends() != null) {
-
-                // assign the parent to a top-level display element
-                b.setIsAParent(getTopLevelElement(b.getExtends()));
-            }
+        // look for a meta inheritance property
+        if (b.getExtends() != null) {
 
-            // resolve inheritance of nested components
-            Iterator ci = b.getChildrenIterator();
-            while (ci.hasNext()) {
-                assignParent((ComponentBean) ci.next());
-            }
+            // assign the parent to a top-level display element
+            b.setIsAParent(getTopLevelElement(b.getExtends()));
+        }
 
-            // resolve inheritance of converter
-            if (b.getConverter() != null) {
-                assignParent(b.getConverter());
-            }
+        // resolve inheritance of nested components
+        Iterator ci = b.getChildrenIterator();
+        while (ci.hasNext()) {
+            assignParent((ComponentBean) ci.next());
+        }
 
-            // resolve inheritance of validators
-            Iterator vi = b.getValidatorIterator();
-            while (vi.hasNext()) {
-                assignParent((ComponentBean) vi.next());
-            }
+        // resolve inheritance of converter
+        if (b.getConverter() != null) {
+            assignParent(b.getConverter());
+        }
 
-            // resolve inheritance of value change listeners
-            vi = b.getValueChangeListenerIterator();
-            while (vi.hasNext()) {
-                assignParent((ComponentBean) vi.next());
-            }
-            vi = null;
+        // resolve inheritance of validators
+        Iterator vi = b.getValidatorIterator();
+        while (vi.hasNext()) {
+            assignParent((ComponentBean) vi.next());
+        }
 
-            // resolve inheritance of action listeners
-            vi = b.getActionListenerIterator();
-            while (vi.hasNext()) {
-                assignParent((ComponentBean) vi.next());
-            }
-            vi = null;
+        // resolve inheritance of value change listeners
+        vi = b.getValueChangeListenerIterator();
+        while (vi.hasNext()) {
+            assignParent((ComponentBean) vi.next());
+        }
+        vi = null;
 
+        // resolve inheritance of action listeners
+        vi = b.getActionListenerIterator();
+        while (vi.hasNext()) {
+            assignParent((ComponentBean) vi.next());
         }
+        vi = null;
+
 
     }
 
@@ -1267,7 +1264,7 @@
          * @param forceReload reload the group of config files
          * @return <code>true</code> if the group was reloaded
          */
-        public boolean refresh(boolean forceReload) {
+        public synchronized boolean refresh(boolean forceReload) {
 
             boolean wasDirty = false;
 
@@ -1334,9 +1331,7 @@
            return wasDirty;
         }
 
-        synchronized (displayElements) {
-            wasDirty = watchDog.refresh(forceReload);
-        }
+        wasDirty = watchDog.refresh(forceReload);
 
         watchDog = null;
 

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java?view=diff&rev=511456&r1=511455&r2=511456
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateComponentConfigBean.java
 Sat Feb 24 22:21:04 2007
@@ -20,6 +20,7 @@
  */
 package org.apache.shale.clay.config.beans;
 
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
@@ -65,7 +66,7 @@
         parser.setConfig(this);
 
         // map holding the resource watchers
-        watchDogs = new TreeMap();
+        watchDogs = Collections.synchronizedMap(new TreeMap());
 
 
         if (param != null && param.length() > 0) {
@@ -135,9 +136,7 @@
 
         //check for dirty cache
         if (defaultWatchDog != null) {
-           synchronized (displayElements) {
-               wasDirty = defaultWatchDog.refresh(forceReload);
-           }
+            wasDirty = defaultWatchDog.refresh(forceReload);
         }
 
         return wasDirty;

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java?view=diff&rev=511456&r1=511455&r2=511456
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
 Sat Feb 24 22:21:04 2007
@@ -21,6 +21,7 @@
 package org.apache.shale.clay.config.beans;
 
 import java.util.BitSet;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
@@ -64,20 +65,20 @@
         }
 
         if (watchDog == null || super.getElement(jsfid.toString()) == null) {
-           //The first time the page is created, create a watcher
+            //The first time the page is created, create a watcher
 
-           watchDog = new WatchDog(getConfigDefinitions(jsfid.toString()), 
jsfid.toString());
+            watchDog = new WatchDog(getConfigDefinitions(jsfid.toString()), 
jsfid.toString());
 
-           // register by name
-           watchDogs.put(watchDog.getName(), watchDog);
+            // register by name
+            watchDogs.put(watchDog.getName(), watchDog);
 
-           //loads the HTML template the first time and when file
-           //has been modified
-           watchDog.refresh(false);
-           } else {
-           //check to see if an existing html template
-           //needs reloaded
-           watchDog.refresh(false);
+            //loads the HTML template the first time and when file
+            //has been modified
+            watchDog.refresh(false);
+        } else {
+            //check to see if an existing html template
+            //needs reloaded
+            watchDog.refresh(false);
         }
 
         // returns the cached element
@@ -120,7 +121,7 @@
         parser = new ClayTemplateParser();
         parser.setConfig(this);
 
-        watchDogs = new TreeMap();
+        watchDogs = Collections.synchronizedMap(new TreeMap());
     }
 
 
@@ -175,21 +176,18 @@
      */
     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();
-                    }
-
+            //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();
-            //}
+
+            }
+            watchDogs.clear();
         }
 
         return forceReload;


Reply via email to