Author: ehillenius
Date: Sun Dec  3 00:55:06 2006
New Revision: 481740

URL: http://svn.apache.org/viewvc?view=rev&rev=481740
Log:
tweaks. though code doesn't works, and we probably have to follow another route.

Modified:
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/application/ReloadingClassLoader.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/ReloadingWicketFilter.java

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/application/ReloadingClassLoader.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/application/ReloadingClassLoader.java?view=diff&rev=481740&r1=481739&r2=481740
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/application/ReloadingClassLoader.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/application/ReloadingClassLoader.java
 Sun Dec  3 00:55:06 2006
@@ -18,9 +18,9 @@
 
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -36,29 +36,40 @@
  */
 public class ReloadingClassLoader extends URLClassLoader
 {
-       private IChangeListener listener;
-       private Duration pollFrequency = Duration.seconds(3);
-       private static final Log log = 
LogFactory.getLog(ReloadingClassLoader.class);
-       private static List urls = new ArrayList();
-       private ModificationWatcher watcher;
        private static boolean enabled = false;
 
+       private static final Log log = 
LogFactory.getLog(ReloadingClassLoader.class);
+
+       private static Set urls = new HashSet();
+
        /**
-        * Add the location of a directory containing class files 
-        * @param url the URL for the directory
+        * Add the location of a directory containing class files
+        * 
+        * @param url
+        *            the URL for the directory
         */
-       public static void addLocation(URL url) {
+       public static void addLocation(URL url)
+       {
                urls.add(url);
        }
 
        /**
-        * Returns the list of all configured locations of directories 
containing class files
+        * Returns the list of all configured locations of directories 
containing
+        * class files
+        * 
         * @return list of locations as URL
         */
-       public static List getLocations() {
+       public static Set getLocations()
+       {
                return urls;
        }
 
+       private IChangeListener listener;
+
+       private Duration pollFrequency = Duration.seconds(3);
+
+       private ModificationWatcher watcher;
+
        /**
         * Create a new reloading ClassLoader from a list of URLs, and 
initialize
         * the ModificationWatcher to detect class file modifications
@@ -95,7 +106,6 @@
 
                if (clazz == null)
                {
-
                        final ClassLoader parent = getParent();
 
                        try
@@ -135,11 +145,24 @@
        }
 
        /**
-        * Watch changes of a class file by locating it in the list of location 
URLs and adding the corresponding file to the ModificationWatcher
-        *
-        * @param clz the class to watch
+        * Sets the listener that will be notified when a class changes
+        * 
+        * @param listener
+        *            the listener to notify upon class change
+        */
+       public void setListener(IChangeListener listener)
+       {
+               this.listener = listener;
+       }
+
+       /**
+        * Watch changes of a class file by locating it in the list of location 
URLs
+        * and adding the corresponding file to the ModificationWatcher
+        * 
+        * @param clz
+        *            the class to watch
         */
-       void watchForModifications(Class clz)
+       private void watchForModifications(Class clz)
        {
                // Watch class in the future
                Iterator locationsIterator = urls.iterator();
@@ -166,8 +189,10 @@
                                                }
                                                finally
                                                {
-                                                       // If an error occurs 
when the listener is notified, remove
-                                                       // the watched object 
to avoid rethrowing the exception at next check
+                                                       // If an error occurs 
when the listener is notified,
+                                                       // remove
+                                                       // the watched object 
to avoid rethrowing the
+                                                       // exception at next 
check
                                                        // FIXME check if class 
file has been deleted
                                                        
watcher.remove(finalClzFile);
                                                }
@@ -184,14 +209,5 @@
                {
                        log.debug("Could not locate class " + clz.getName());
                }
-       }
-
-       /**
-        * Sets the listener that will be notified when a class changes
-        * @param listener the listener to notify upon class change
-        */
-       public void setListener(IChangeListener listener)
-       {
-               this.listener = listener;
        }
 }

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/ReloadingWicketFilter.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/ReloadingWicketFilter.java?view=diff&rev=481740&r1=481739&r2=481740
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/ReloadingWicketFilter.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/ReloadingWicketFilter.java
 Sun Dec  3 00:55:06 2006
@@ -16,7 +16,9 @@
  */
 package wicket.protocol.http;
 
+import java.io.IOException;
 import java.net.URL;
+import java.util.Enumeration;
 
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
@@ -32,10 +34,23 @@
 {
        private ReloadingClassLoader reloadingClassLoader;
 
-       static {
-               // Get the location of the classes directory
-               URL classesDir = ReloadingWicketFilter.class.getResource("/");
-               ReloadingClassLoader.addLocation(classesDir);
+       static
+       {
+               // Get the locations of the classes directories
+               final Enumeration resources;
+               try
+               {
+                       resources = 
ReloadingWicketFilter.class.getClassLoader().getResources("");
+               }
+               catch (IOException e)
+               {
+                       throw new RuntimeException(e);
+               }
+               while (resources.hasMoreElements())
+               {
+                       URL location = (URL)resources.nextElement();
+                       ReloadingClassLoader.addLocation(location);
+               }
        }
 
        /**
@@ -47,13 +62,21 @@
                reloadingClassLoader = new 
ReloadingClassLoader(getClass().getClassLoader());
        }
 
+       /**
+        * @see wicket.protocol.http.WicketFilter#getClassLoader()
+        */
        protected ClassLoader getClassLoader()
        {
                return reloadingClassLoader;
        }
 
+       /**
+        * @see 
wicket.protocol.http.WicketFilter#init(javax.servlet.FilterConfig)
+        */
        public void init(final FilterConfig filterConfig) throws 
ServletException
        {
+               super.init(filterConfig);
+
                reloadingClassLoader.setListener(new IChangeListener()
                {
                        public void onChange()
@@ -70,7 +93,5 @@
                                }
                        }
                });
-
-               super.init(filterConfig);
        }
 }


Reply via email to